How to stop an ode-solver if integration takes too long?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (2)
Jared Barber
el 15 de Jul. de 2019
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 comentario
Karim Shawki
el 17 de Jul. de 2019
Works perfectly, thanks Jared!
Franziska
el 3 de Abr. de 2013
2 comentarios
Mahdi
el 3 de Abr. de 2013
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
el 4 de Abr. de 2013
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!