Plotting Issues with function provided

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by