How can one monitor the progress of a Diff Equ Solver?

21 views (last 30 days)
I'm using the ode15s function to help me solve a relatively large system of stiff, first order ODE's. Depending on my settings, sometimes it solves fast and easy, sometimes slowly, and sometimes it takes forever, floods my computer's RAM, and I don't get any solution. I'd like to be able to watch it so I can see if it's worth waiting for it to solve or if I need to stop change something.
I read the instructions in the Matlab help for how to do this, but I'm still a novice user, and I don't understand the instructions. I know that I'm interested though in figuring out how to use functions like OutputFcn, odeplot, odephas2, odeprint, and OutputSel, although I can't tell the differences between them, or which one I want. If I could get Matlab to show me each new point of the solution result of the solver in the Command Window as it goes, that would be great. If this is too computationally demanding, if I could just have a way to pause, check, and continue the solver would also be helpful. I've been plotting the results upon conclusion of the solving process. If I could plot whatever partial solution that the solver achieved over the tspan before it is fully done, that would also be helpful.
The bottom line is that I don't want to wait 5 hours for the solver to tell me that it failed when I could have been working fixing whatever caused it to struggle in solving.
Karl Broer
Karl Broer on 19 Aug 2012
I see that I can just simply remove the ; at the end of the line of differential equation solver, and then the solution prints out in the home screen. This might help me some. Are there any other ways to do it, like maybe a way that you could run one iteration of the solver at a time, or have a plot on the screen that graphs the solver's progress during the solving?

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 19 Aug 2012
You seem to have discovered the many wonders of odeset so I'll not mention it further. The only other possibility I can suggest is to break tspan up into several much smaller subsections (particularly by defining tspan as a vector of distinct times rather than only a start and end time), and have the solver stop and report its results at the end of the tspan vector. Then save the integrated results, define your next tspan vector of distinct times, use the last of the previous outputs as the new initial conditions, and proceed from there.
The advantage of defining tspan as a vector of specific times rather than simply a start and stop time isn't so much efficiency (because the solvers evaluate the ODE at times other than those specified in the tspan vector), but because (ideally at least) you can use the vector to avoid singularities and other discontinuities, at least once you discover any that the solver might get hung up on. It also gives you some control over the solver's performance.
There are likely other possibilities, however this approach has worked well enough for me in the past that I've not needed to explore them.

Azzi Abdelmalek
Azzi Abdelmalek on 19 Aug 2012
Edited: Azzi Abdelmalek on 19 Aug 2012
try this
y0=[0 1 1],s=[];t0=0;tf=0.1;
figure;set(gca,'xlim',[0 20]); ax1=gca;
for k=1:100
[t,y] = ode15s(@ode_exemple,[t0 tf],y0,option);
hold on;pause(1)
hold on
function s = ode_exemple(t,y)
s = zeros(3,1); % a column vector
s(1) = y(2) * y(3);
s(2) = -y(1) * y(3);
s(3) = -0.51 * y(1) * y(2);

Community Treasure Hunt

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

Start Hunting!