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)
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!