フィルターのクリア

Help with my 2nd Order ODE Solver.

1 回表示 (過去 30 日間)
Drake
Drake 2020 年 5 月 15 日
コメント済み: Star Strider 2020 年 5 月 15 日
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

採用された回答

Star Strider
Star Strider 2020 年 5 月 15 日
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 件のコメント
Drake
Drake 2020 年 5 月 15 日
Thank you very much. :)
Star Strider
Star Strider 2020 年 5 月 15 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by