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 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