Fitting data using lsqcurvefit
3 views (last 30 days)
Show older comments
Dear Community,
I have been trying to fit my data using lsqcurvefit but I have had trouble with the internal limits. Currently I am getting this prompt when I run the system
Can anyone help me with this prompt? And how I can go about fixing it. If you need my code please let me know and I will provide it ASAP
Any help would be greatly appreciated! Thank you!
0 Comments
Answers (1)
Walter Roberson
on 10 Apr 2023
There is nothing to fix.
Ideally the sum of squares would be exactly 0, which would require a perfect fit of parameters to the model and would require there be no round-off error.
lsqcurvefit knows that is not likely to happen, so it has several different stopping criteria. Some of the criteria cause a stop if the fit is taking longer than the maximum it has been configured for. Some of the criteria cause a stop if nan or infinities are encountered, making a solution impossible. Some of the criteria cause a stop if it can tell that the current location is unlikely to be an actual solution but it cannot figure out how to improve the solution.
And then there are criteria that lead to stopping when the result looks to be as good as you are likely to be able to get, that it does not seem worth looking for a better result anymore.
The particular criteria you are encountering is one that is in effect when the fit looks quite good and it doesn't seem worth chasing a better fit.
In some cases you need even more precise values; if so then there are options you can adjust to wait longer before deciding that further improvements are pointless.
In some cases, if your model deals with fairly small numbers, your fit might not really be any good and you need to adjust the options or scale the values. You need to have some understanding of the model to know whether a fit to within 10^-6 is good enough.
There is only one case in which lsqcurvefit could say definitively that it has found the model coefficients: that would be the case where the fit was exact right down to the last possible decimal place. That rarely happens. Instead the normal way for lsqcurvefit to end is to figure out that it has done as good of a fit as you are likely to get -- and then to say "but of course it is always possible that this is not really the best set of model parameters, that just maybe there is a better set of parameters somewhere".
Unless you get a fit right down to the last possible decimal place, then you will never know for sure that you really found the global minima -- not when you are doing numeric calculations. (In some cases it is possible to use symbolic calculations to prove that you have reached a global minima, but that gets difficult except for polynomials.)
5 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!