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
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
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
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
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 Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!