ODE: Using try/catch to catch "Unable to meet integration tolerances (...)" not working

2 views (last 30 days)
opt = odeset('AbsTol',1e-4,'RelTol',1e-4,'Stats','off');
ME = [];
for i = 1:N
func = @(t,x) mbl(x,p{i}); % p{} contains a param. comb. for the diff.eq
try
[simResult{i,1}.t simResult{i,1}.y] = ode23(func, tspan, p{i}.x0, opt);
catch
disp(lasterr)
end
%close the open resources
if ~isempty(ME)
rethrow(ME);
end
end
Above is a snippet of my code. I am simulating a stiff system with different parameter combinations passed to the function through p{}. Many parameter combinations will trigger the warning "Unable to meet integration tolerances without reducing the step size below the smallest value allowed".
I am trying to weed out these simulations, as I am only interested in the parameter combinations that are less stiff. I was thinking I could use try/catch for this as I have read people doing for similar problems, but for some reason, the catch-condition never seems to trigger. I get the warning mentioned above, but my code never enters the catch.
Any suggestions?

Answers (1)

Vishwas Bharadwaj
Vishwas Bharadwaj on 1 Nov 2016
From your description, I understand that you are trying to catch the warning 'Unable to meet integration tolerances without reducing the step size below the smallest value allowed' and whenever it occurs, you do not want to perform simulation.
Try/catch statements are used to execute a statement and catch any errors. Hence, there is no direct way of using Try/Catch statements to catch the warnings. However, as described here, you could consider converting the 'warning' to an 'error'.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!