필터 지우기
필터 지우기

How to stop ode after 50th event has occurred

조회 수: 19 (최근 30일)
cgz6887
cgz6887 2015년 7월 15일
답변: Torsten 2015년 7월 16일
I am trying to run ode45 once using an event function, but have it stop after the 50th event has occurred. I am currently using a persistent counter to keep track of events, but am missing the logic to update the counter. Below is the code for my event function. I do not want to call ode45 50 times by updating the initial conditions with the terminal conditions from the previous call.
function [value,isterminal,direction] = y0eventPoincare(t,y)
persistent icount
if (isempty(icount))
icount=0;
end
if icount<50
value=y(2);
isterminal=0;
direction=1;
if (**Missing Logic**) %Event has occured
icount=icount+1;
end
end
if icount==50
value=y(2);
if true
% code
end
isterminal=1;
direction=1;
end
end

채택된 답변

Torsten
Torsten 2015년 7월 16일
Not each call to y0eventPoincare means that a new event has occured. Thus it is not possible to keep track of the number of events within the event function.
I don't see another way to count the number of events in the routine calling the ODE solver (thus to go the way you wanted to avoid).
Best wishes
Torsten.

추가 답변 (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