How to get parameter values from lsqcurvefit?

I have been using lsqcurve fit to calculate two parameters so that my model fits my experimental data more accurately. I have written code and keep getting the exit message:
"Local minimum found.
Optimization completed because the size of the gradient is less than the default value of the function tolerance."
Does this mean the programme has succeeded? How do I get the values for my two parameters?
Thanks

Answers (1)

Your estimated parameters are ‘x’ in this example from the documentation:
x = lsqcurvefit(fun,x0,xdata,ydata)
The warning (not error) indicates that lsqcurvefit has found a local minimum, not the global minimum that would produce the best parameter estimates. Use different initial parameter estimates (in this example, ‘x0’) and see if that produces a better fit. Another option is to use fminsearch, since it uses a derivative-free method, and sometimes succeeds when the gradient-descent solvers do not. If you have the Global Optimization Toolbox, the patternsearch function may find the global minimum most efficiently.
Example code using fminsearch:
x = ...; % Independent Variable
y = ...; % Dependent Variable
fun = @(b,x) ...; % Objective Function
SSECF = @(b) sum((y - fun(b,x)).^2); % Sum-Squared-Error Cost Function
B0 = [...]; % Initial Parameter Estimates
B = fminsearch(SSECF, B0); % Estimate Parameters
Here, ‘B’ would be the estimated parameters.

Asked:

on 17 Mar 2016

Edited:

on 17 Mar 2016

Community Treasure Hunt

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

Start Hunting!