Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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