Help with my 2nd Order ODE Solver.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Drake
am 15 Mai 2020
Kommentiert: Star Strider
am 15 Mai 2020
A penny dropped from the top of a building (138meters). Using ode45 compute the motion of the penny’s fall. Which I have done below. I just need the function to stop when the penny hits the ground. I can guess the penny hits roughly at 13.25 seconds from the graph and math. In my second funtion I am trying to make it where my function stops when the pennny hits the goround(y=0). Plz help any suggestions will be helpful.
yo = 138;
yf = 0;
a = 9.8;
to = 0;
tf = 20; making the final time longer than need be becuse I want to make my event fcn to work.
time = [to tf];
iv = [138 0];
Options = odeset('RelTol',100*eps,'Events',@ground);
[t,y,te,ue,ie] = ode45(@f,time,iv,Options);
%%%FUNTIONS%%%
function rk=f(t,y)
ag = 9.8;
vt = 11;
rk = [y(2); (-ag)*(1-(y(2)/vt)^2)] % this is my system of equations
return
end
function [value, isterminal, direction] = ground(t,y)
gd = 138;
value = y(2)-gd;
isterminal = 1;
direction = -1;
end
0 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Mai 2020
Trigger the event on ‘y(1)’, and set ‘gd’ to zero:
function [value, isterminal, direction] = ground(t,y)
gd = 0;
value = y(1)-gd;
isterminal = 1;
direction = -1;
end
That worked as I suspect it should, stopping the integration at about 13.3 seconds simulation time.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!