- #1
sirclash
- 7
- 0
MatLab "for" loops
Write an m-file to evaluate y(x)= x^2 - 3x +2 for all values of x between -1 and 3, in steps of .1 . Do this twice, once with a for loop and once with vectors. Plot the resulting functions.
count=0;
for x= -1:.1:3
count = count+1;
y(count)= x.^2 -3*x +2;
end
plot(x,y)
z=-1:.1:3;
u= z.^2 -3*z + 2;
plot(z,u)
My vector is correct, however i have no clue why my "for" loop won't show the correct graph.
Homework Statement
Write an m-file to evaluate y(x)= x^2 - 3x +2 for all values of x between -1 and 3, in steps of .1 . Do this twice, once with a for loop and once with vectors. Plot the resulting functions.
Homework Equations
The Attempt at a Solution
count=0;
for x= -1:.1:3
count = count+1;
y(count)= x.^2 -3*x +2;
end
plot(x,y)
z=-1:.1:3;
u= z.^2 -3*z + 2;
plot(z,u)
My vector is correct, however i have no clue why my "for" loop won't show the correct graph.