MATLAB Answers

Problem with nonlinear curve fitting - lsqcurvefit

56 views (last 30 days)
Alex on 4 Mar 2013
Commented: Deniz Toprak on 26 Jul 2020
I'm trying to fit a nonlinear curve with constrains, so I use lsqcurvefit to get the parameters of my function. After applying lsqcurvefit I obtain this output:
Local minimum possible.
So I use MultiStart in order to get the global minimum, but it is not able to obtain the parameters of the function. In this case the output is:
MultiStart encountered failures in the user provided functions. All 100 local solver runs failed in a user supplied function
Searching on Matlab answers I came across this post
They suggest patternsearch in situations where an objective function has many local minima. However, it is not clear how to use pattern search to fit a nonlinear curve.
How can I obtain an optimal fitting? How can I use pattern search when fitting a nonlinear curve?
Any help will be appreciated. Thanks!
  1 Comment
Matt J
Matt J on 4 Mar 2013
It could be worthwhile seeing your code, your curve model, and how you are initializing the iterations. Sometimes, it takes some problem-specific artistry, to avoid naive initial guesses.

Sign in to comment.

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 4 Mar 2013
Hi Alex, this link may help you get started:
Using optimization routines in MATLAB are very similar across functions. The idea in fitting a curve is to set up an error function usually sum of squared errors, and ask the optimization tool (your choice) to minimize it.
x = patternsearch(@err,x0)

More Answers (2)

Alan Weiss
Alan Weiss on 4 Mar 2013
Edited: Alan Weiss on 4 Mar 2013
If your first run with lsqcurvefit produced a local solution, as it seems, then there is no reason I know that MultiStart would fail every time. I would look into the syntax you used to call MultiStart. This example show how to use lsqcurvefit with MultiStart. In particular, you might need to set bounds for the MultiStart object.
Also, the exit message you quoted (Local minimum possible) means that lsqcurvefit did not obtain a sufficiently low value of its first-order optimality measure, but it might have succeeded in minimizing the model discrepancy anyway. It is not clear from that message whether you need MultiStart, but if you want a global optimum then it is a good idea to use it.
I would avoid using patternsearch or any other solver just yet, lsqcurvefit should provide more accurate answers if you can get it to work with MultiStart.
Alan Weiss
MATLAB mathematical toolbox documentation
Deniz Toprak
Deniz Toprak on 26 Jul 2020
Hi Alan and Shashank,
I have problem with lsqcurvefit function. I couldn't get good results from parameters. I used multistart with lsqcurvefit. The results are worse than before. I mean without multistart results are more approximate to the real parameter. What the problem should be?
How can I get good parameter results ?
Please help me with this?

Sign in to comment.

Alex on 5 Mar 2013
Hi Alan and Shashank,
I solved the problem following the example that Alan posted. Thanks to your comments it is more clear for me not only MultiStart function but also pattersearch.
Many thanks for your help!


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!