How to stop an ode-solver if integration takes too long?
이전 댓글 표시
Hi all,
I am working with implicit ode15i solver.
I receive results within seconds for more than 80 parameters to solve. However, sometimes it seems it gets stuck - no progress after hours. I can reproduce that, so I am sure I have chosen bad initial conditions. Is there a way to interrupt the integration after certain time to start new with different initial conditions? Something like a timing option?
I know about the event-function but this is for events given by the system only as far as I understood.
Thanks a lot in advance. Best, Franziska
채택된 답변
추가 답변 (2개)
Jared Barber
2019년 7월 15일
I know it's been a while since this was posted but since I have implemented something that does something similar to what the poster asks about, I thought I'd report it.
This may not give the level of control that you are seeking, but you can, in fact, feed the start time of your integration to your events function and use that to monitor how long the ode solver has been integrating for. The following code integrates y' = sin(t^2)*y and stops prematurely because the integration has been running for 1.2 seconds:
myevent function
function [values,isterminal,direction] = myevent(t,y,yp,tstart)
% Don't let t cross zero...a dummy "event" to illustrate how
% one might handle other events in conjunction with the time
% constraint. Not necessary, but I put it in just in case.
values(1) = t;
% Don't let integration go for more than 1.2 seconds.
values(2) = toc(tstart) < 1.2;
isterminal = true(size(values));
direction = zeros(size(values));
end
corresponding function definition and function call:
myf = @(t,y,yp) yp-sin(t^2)*y;
tstart = tic;
[t,y,te,ye,ie] = ode15i(myf,[0,1e15],1,0,odeset('Events',@(t,y,yp) myevent(t,y,yp,tstart)));
plot(t,y);
This was also in Matlab 2019a. It may not have been possible in Matlab 2013 or earlier, I'm not sure.
댓글 수: 1
Karim Shawki
2019년 7월 17일
Works perfectly, thanks Jared!
Franziska
2013년 4월 3일
댓글 수: 2
Mahdi
2013년 4월 3일
Please reply as a comment to keep it all within the same thread for future reference.
Unless you go into the loops for ode15i, this is almost impossible to do. The feature hasn't been implemented to my knowledge. You can try to do it with while statements (and the way I suggested) into the ode15i function.
This link discusses why MATLAB can't have this feature, and I don't think they've implemented it since then.
Franziska
2013년 4월 4일
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!