Why isn't my code graph anything.
Show older comments
Why don't matlab show me a graph. I ran it last time and it ran perfectly. Why nothing happend this time?
%create a cater plot
clear all;
%x = [20,30,40,50]
x = [-3,-1,1,2]
y = [8,23,28,34]
figure;
plot(x,y,"O",'MarkerSize', 4);
hold on
y=[8,23,28,34].'
colum = [1,1,1,1]
matrixA1 =[]
matrixA2 = []
matrixA3 = []
equation = (x -35)/ 5
%create a matrix
% first matrix
matrixA1 = [colum(:),x(:)]
% secon matrix
new_vector = x.^2
matrixA2 = [colum(:), x(:), new_vector(:)]
% third matrix
new_vector3 = x.^3
matrixA3 = [colum(:), x(:), new_vector(:), new_vector3(:)]
%create the tranpose matrix
tranposeA = matrixA1.';
tranposeB = matrixA2.';
tranposeC = matrixA3.';
% power 1
final_matrixA = [tranposeA*matrixA1 tranposeA*y];
%power 2
final_matrixB = [tranposeB*matrixA2 tranposeB*y];
%power e
final_matrixC = [tranposeC*matrixA3 tranposeC*y];
A1 = rref(final_matrixA);
A2 = rref(final_matrixB);
A3 = rref(final_matrixC);
% for matrix A
a = A1(1,3);
b = A1(2,3);
%q = a+bx
i = -10:10
q = a +b*i
plot(i,q)
hold on
% for matrix b
a1 = A2(1,4);
b1 = A2(2,4);
c1 = A2(3,4);
q1 = a1 +b1*i+c1*i.^2
plot(i,q1)
hold on
% matrix c
a2 = A3(1,5);
b2 = A3(2,5);
c2 = A3(3,5);
d2 = A3(4,5)
q2 = a2 +b2*i+c2*i.^2+d2*i.^3
plot(i,q2)
Answers (1)
Try:
%create a cater plot
clear all;
%x = [20,30,40,50]
x = [-3,-1,1,2]
y = [8,23,28,34]
y=[8,23,28,34].'
colum = [1,1,1,1]
matrixA1 =[]
matrixA2 = []
matrixA3 = []
equation = (x -35)/ 5
%create a matrix
% first matrix
matrixA1 = [colum(:),x(:)]
% secon matrix
new_vector = x.^2
matrixA2 = [colum(:), x(:), new_vector(:)]
% third matrix
new_vector3 = x.^3
matrixA3 = [colum(:), x(:), new_vector(:), new_vector3(:)]
%create the tranpose matrix
tranposeA = matrixA1.';
tranposeB = matrixA2.';
tranposeC = matrixA3.';
% power 1
final_matrixA = [tranposeA*matrixA1 tranposeA*y];
%power 2
final_matrixB = [tranposeB*matrixA2 tranposeB*y];
%power e
final_matrixC = [tranposeC*matrixA3 tranposeC*y];
A1 = rref(final_matrixA);
A2 = rref(final_matrixB);
A3 = rref(final_matrixC);
% for matrix A
a = A1(1,3);
b = A1(2,3);
%q = a+bx
i = -10:10
q = a +b*i
% for matrix b
a1 = A2(1,4);
b1 = A2(2,4);
c1 = A2(3,4);
q1 = a1 +b1*i+c1*i.^2
% matrix c
a2 = A3(1,5);
b2 = A3(2,5);
c2 = A3(3,5);
d2 = A3(4,5)
q2 = a2 +b2*i+c2*i.^2+d2*i.^3
% Plot
figure
hold on
plot(x,y,"O",'MarkerSize', 4);
plot(i,q,i,q1,i,q2)
hold off
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!