How to plot a linear equation with a final condition
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 4 Mag 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
il 4 Mag 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.
Risposte (1)
David Hill
il 4 Mag 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 Commento
Walter Roberson
il 4 Mag 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.)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!