MATLAB Answers

Alex
0

Problem with nonlinear curve fitting - lsqcurvefit

Asked by Alex
on 4 Mar 2013
Hello!
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

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.

Tags

3 Answers

Answer by Shashank Prasanna on 4 Mar 2013
 Accepted Answer

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)

  0 Comments

Sign in to comment.


Answer by Alan Weiss
on 4 Mar 2013
Edited by 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

  0 Comments

Sign in to comment.


Answer by 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!

  0 Comments

Sign in to comment.