Plotting Issues with function provided

1 回表示 (過去 30 日間)
N/A
N/A 2020 年 3 月 5 日
回答済み: Walter Roberson 2020 年 3 月 6 日
Attemtping to plot a graph of the equation displayed below. All I see is a line, where it should be more of a parabola.
g=9.81;
z0=100;
v0=55;
m=80;
c=15;
for t=0:.1:20
z=z0+(m/c)*(v0+(m*g/c))*1-exp(-c*t/m)-m*g*t/c;
end
plot(t,z)

採用された回答

Walter Roberson
Walter Roberson 2020 年 3 月 6 日
Every iteration, you are overwriting all of z.
Also, with a for loop, each iteration, the loop control variable t will be assigned exactly one column (so, in context, a scalar). At the end of the loop, the loop control variable will be left as the last value it was assigned -- so in context, the scalar 20.
You are therefor asking asking to plot with a scalar t value and a scalar z value, which would only produce a dot at most (and usually not even that if you have not defined a marker type)
You should vectorize your computation.
The result will still look like a line. If you want something more like a parabola, you should plot between roughly t = -50 to +50 . The peak is at roughly -30

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by