필터 지우기
필터 지우기

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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by