Keep a for loop running when ODE gives an error

1 view (last 30 days)
Hi,
I am trying to run a code for sensitivity analysis on initial conditions and parameters of a process. To evaluate the different inputs I use a for loop and I solve an ODE in each iteration. The problem is that some of the combination of parameters and initial conditions cannot be solved and, when this happens, ode45 (and ode15s) stops the script. I really would wish that the for loop could keep on running after storing a warning output from the odesolver. Do you know if this is possible? I include a pseudocode of the script:
% mxn A matrix contaning m sampling combinations of n input parameters
for i=1:m
input=A(i,:)
solution(i)=odesolver(@function,t,input)
end
So the question is if I could do something so that the for loop keeps running even if the odesolver gives an error message. Thank you,
Miguel

Accepted Answer

Grzegorz Knor
Grzegorz Knor on 30 Sep 2011
% mxn A matrix contaning m sampling combinations of n input parameters
for i=1:m
input=A(i,:)
try
solution(i)=odesolver(@function,t,input)
catch ME
warning(...)
end
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!