Why is my graph of my falling object going random?

1 次查看(过去 30 天)
Dear,
i made this for loop for an object going down a hill. I specified all the variables above this part:
for t = t:t_stap:endtime
speed = v0+a*t; %Speed at time t, m/s
D = Cd*p*0.5*speed^2*A; %Drag force, N
a = (Fg-D-Fsnow)/m; %Acceleration, m/s^2
height = x0-((speed^2)/g)*log(cosh((g*t)/speed)); %Distance fallen, speed/time graph integrated over time, m
lastspeed = speed;
hold('all')
plot(t,height,'r')
plot(t,speed,'g')
plot(t,a,'b')
axis([0 20 0 100])
drawnow
if height <= 0
break
end
end
Now when i run this it shows me a perfect graph of all the results, just as intended. But after about t = 3 it starts going random. All 3 graphs go up and down in random sense. It does not make any sense. It should just keep going on like normal.
What am I doing wrong/why is matlab suddenly interpreting my code wrongly? My best guess is that
speed = v0+a*t
is wrong. I know the formula does not hold, because this assummes constant acceleration, but i do not know anything better. Is the problem here?
Thanking you in advance
  6 个评论
Jelle
Jelle 2013-10-16
Well, my graph makes sense now and it does exactly as expected, so you solved it! Thank you!
dpb
dpb 2013-10-16
Now, as "exercise for the student", write the underlying differential equations and integrate them and compare your solution... :P

请先登录,再进行评论。

采纳的回答

dpb
dpb 2013-10-16
Instead of using a*t for the instantaneous speed, you need to compute the speed at the time step and increment the current speed by the differential timestep at the acceleration computed for the time step. Your solution presumes the same acceleration has held from t=0.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by