What function should I choose while sometimes ode45 will fall into endless loop?

Actually,the problem to solve sometimes don't have a solution. In this case, the ode45 will fall into endless loop, and could not stop itself. As a build-in function, tic-toc control can not apply to it, so I try to use other ode-functions, they all will automatically stop and throw a warning. That's good for me. But I'm not sure if they can always do this everytime. In all, my question is: is there a function of ode that will never fall into endless loop? If there is or there are, please name it or them, and I would really appreciate if the reason can be explain.

 Accepted Answer

As far as I know, ODE45 does never fall into an infinite loop. But the stepsize can be very small, such that the calculation take a lot of time. Then limiting the smallest step size is helpful usually.
Another idea is using an Event function, which drops a terminal event after a specified amount of time. A persistent variable in side this Event function might be usful for this job.

5 Comments

Actually,it will.I could email you the program to test this. And I have found that only two ode-funtions may never fall into endless loop. They are ode23t and ode23tb. But I'm still not sure about that. The time control is kind of complicated to apply, because ode-functions are build-in functions. If they fall into endless loop, it happens inside and we could do nothing other than Ctrl+Pause. If you can detail your method or if you would like to see my test-program, please email me, and my address is rabota@163.com.
@Jianwei Guo: I'm not happy about that I found your question in my personal mailbox. If I find the time to answer, I will answer. If I don't find the time to answer, I do not want to be pushed by emails. It is a much better idea to post your code here, because a lot of other readers can have a lot of more ideas. Therefore this is a public forum and not a private mail-chat. Please do *not* send me mails again.
The method to set the minimal allowed step size is explained in the documentation of ODE45 and ODESET. The usage of Event functions is described there also.
Sorry about that if it made you uncomfortable. And surely I want you to know that I didn't mean it anyway.
I'll read the documentation of ODE45 and ODESET one more time and try to find what you say.
Thanks a lot and all the best.
options=odeset('Events',@eventRR)
tic
[T,Y] = ode45(@RR,[0:0.1:8],[0.1 -0.2],options);
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function [value,isterminal,direction] = eventRR( t,y )
%EVENTRR Summary of this function goes here
% Detailed explanation goes here
value=double(toc<0.5);
isterminal=1;
direction=0;
end
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I use this to apply time control. In the case of long-time no ending, the program will jump out. This is great, thank you.
But if the problem can be solved all among tspan, time control didn't work. I've switch the value of 'direction' between 0,-1and 1 when I set 'value=double(toc<0.00001)'. I expect the ode to end the first time it check the event, while when problem can be solved, it won't jump out but to finish the solving. Do you know why, Jan?
The event function is triggered, if the value changes its sign, but "double(toc<0.00001)" is 1 always. In addition the solver tries to locate the exact time of the event by further evaluations of the ODE. Perhaps it is a more stable idea to modify a copy(!) of the ODE45 function, e.g. with a limit the number of calculated steps.
Concerning the email: *One* email would not be a problem, but I get too many of them comming from this forum. And most of them are less polite than you are. Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!