How to plot a linear equation with a final condition
9 views (last 30 days)
Show older comments
I want to plot the following:
V(t) = V0 * (1-t/ts);
Where V0 is my initial velocity, my time range is t = [t0 ts] and
V(ts)= 0;
I know I have to use a for loop, but don't know how to call the initial function into the loop or how to include the final condition.
V0 = [10 20 30 40 50];
Vel = @(t,V,ts) V0*(1-t/ts)
for j = 1:length(V0)
figure (2)
line(V0,Vel)
end
Any suggestions?
2 Comments
Walter Roberson
on 4 May 2020
V(ts) = 0 does not add any new information V0 * (1-t/ts) -> V0 * (1 - ts/ts) -> V0 * (1 - 1) -> 0 . Therefore you did not need to be told V(ts) = 0 as it happens anyhow.
Walter Roberson
on 4 May 2020
Hints:
1) If you have a row vector A which is 1 x M, and a column vector B which is N x 1, then
B * A
will be N x M in size.
2) plot() of something that is N x M in size will give you M lines on the screen, each containing N points.
Answers (1)
David Hill
on 4 May 2020
ts=10;%not sure what ts should be
t=0:.1:ts;
V0 = [10 20 30 40 50];
hold on;
for k=1:length(V0)
v=V0(k)*(1-t/ts);
plot(t,v);
end
1 Comment
Walter Roberson
on 4 May 2020
We do not encourage giving complete answers to homework problems. (When someone "has to" use a for loop, then you can tell that it is homework.)
See Also
Categories
Find more on Loops and Conditional Statements 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!