Why is my graph of my falling object going random?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 16 Okt. 2013
Now, as "exercise for the student", write the underlying differential equations and integrate them and compare your solution... :P
Akzeptierte Antwort
dpb
am 16 Okt. 2013
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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!