How to plot a linear equation with a final condition

9 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2020-5-4
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
Walter Roberson 2020-5-4
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.

请先登录,再进行评论。

回答(1 个)

David Hill
David Hill 2020-5-4
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 个评论
Walter Roberson
Walter Roberson 2020-5-4
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.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by