Why is my graph of my falling object going random?

조회 수: 1 (최근 30일)
Jelle
Jelle 2013년 10월 16일
댓글: dpb 2013년 10월 16일
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