Difference fit result form nlinfit and lsqcurvefit
17 views (last 30 days)
Show older comments
Wout Laeremans
on 4 Feb 2023
Commented: Wout Laeremans
on 4 Feb 2023
Hi all
I have found online that nlinfit and lsqcurvefit are based on the same principles, but could it be that I got a different fit from one than from the other? I used both, but got better results using lsqcurvefit.
Thank you!
0 Comments
Accepted Answer
John D'Errico
on 4 Feb 2023
And, so?
Many problems will have multiple locally optimal solutions. Neither of those tools even hopes to be a globally optimal solver. So at best, they find a solution based on where you start them out. The solution is one where no search direction will yield an improvement over the current point, but it may easily be a local minimum.
However, they are different solvers. Given the same problem, two different solvers need not converge to the same solution. This is a term called a basin of attraction.
On this specific example, you got a better result from lsqcurvefit. That is irrelevant, as on the next problem, nlinfit might do better.
If you want better results, then use better starting values. That is always true. If you want better help than this, then show your data and tell us what starting values you used, and of course the model being fit.
5 Comments
John D'Errico
on 4 Feb 2023
@Wout Laeremans And you clearly did not read my answer.
Yes. It is entirely possible they will generate a different solution, given the same model, AND the same starting values. This is entirely possible. I said EXACTLY that. Different optimizers do not need to converge to the same solution.
Do the two codes use (by default) the same algoritm? NO. They do not.
Nlinfit uses Levenberg-Marquardt, whereas lsqcurvefit uses a trust-region-reflective code. Levenberg-Marquardt is an OPTION for lsqcurvefit, but not the default. Even if you tell lsqcurvefit to use LM, I still would not gaurantee the two implementations are identical, so they may still have different basins of attraction.
Have you made some mistake in your code? It appears the two calls you made are similar. But since they were made to two different algorithms, go back and read my answer. They do not need to converge to the same result.
More Answers (0)
See Also
Categories
Find more on Least Squares 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!