3
$\begingroup$

I want to see how well some curves fit a data set. If a curve doesn't fit after 100 iterations, I get the error cvmit. How do I test for and handle this error within my code?

$\endgroup$

1 Answer 1

6
$\begingroup$

I think Check will do it, e.g.:

 cvmitErrorFlag=False;
 Check[
    (* function that may throw error *) 
    Fit[ data, funs, vars ],
    (* what to do if error is thrown *)
    Print["No convergence within 100 iterations!"]; 
    cvmitErrorFlag=True,
    (* limit to only this error *)
    Fit::cvmit
 ]

Of course, you could be using other functions to do the fitting (instead of Fit). You could also do things like Quiet the error message, in case you want to handle the convergence problem gracefully.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.