Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch errors (not exceptions) in Mathematica

I have a Table that does fitting operations for 10000 datasets that looks as follows:

ParallelTable[
NonlinearModelFit[data[[i]], func[t,a,b,c,d], {a,b,c,d}, t],
{i,1,10000}];

Which I can change to a for loop if necessary for my problem. That's no problem.

I would like to be able to catch errors in this statement. So if NonlinearModelFit returns any kind of errors (saddle point, maximum iterations reached, non-convergence), I would like to have "i" printed or appended to some other array, in order to know which dataset is not compatible with the fit and debug it. How can I do that?

like image 200
The Quantum Physicist Avatar asked Dec 13 '25 19:12

The Quantum Physicist


1 Answers

Just to paraphrase belisarius and make it an answer:

Use

Check[ mymaincommand, resultexpressioniferror, optionallistofspecificmessages]

like image 79
ogerard Avatar answered Dec 16 '25 08:12

ogerard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!