Keep a for loop running when ODE gives an error

2 次查看(过去 30 天)
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

采纳的回答

Grzegorz Knor
Grzegorz Knor 2011-9-30
% 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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by