How to stop an ode-solver if integration takes too long?
조회 수: 17 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Mahdi
2013년 4월 3일
At the start of your code:
StartTime=clock;
At the end of each loop/the point you might want to exit
TimeElapsed=clock-StartTime;
if TimeElapsed(end)>10 %Set it to a value that you want (I chose 10 seconds)
return
end
Look at the clock function to understand this more.
댓글 수: 0
추가 답변 (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.
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!