How to plot a linear equation with a final condition

9 ビュー (過去 30 日間)
Carlos Ojeda
Carlos Ojeda 2020 年 5 月 4 日
コメント済み: Walter Roberson 2020 年 5 月 4 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by