Why is my graph of my falling object going random?
Show older comments
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 Comments
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.
Jelle
on 16 Oct 2013
Image Analyst
on 16 Oct 2013
Edited: Image Analyst
on 16 Oct 2013
dpb - you can move that response from a comment to an Answer so you get credit for it and the poster can mark it as Accepted.
dpb
on 16 Oct 2013
OK, IA, done! Guess it really does answer the problem; knew it was one problem, whether it was the only I didn't try to check...
Jelle
on 16 Oct 2013
dpb
on 16 Oct 2013
Now, as "exercise for the student", write the underlying differential equations and integrate them and compare your solution... :P
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!