Reputation: 1548
I want to use Levenberg Marquardt Algorithm in the lsqcurvefit
command. I've done the following :
options = optimset('LevenbergMarquardt','on');
x = lsqcurvefit(@myfun,x0,xdata,ydata,options);
I get the following error:
??? Error using ==> optim\private\lsqncommon
LSQCURVEFIT only accepts inputs of data type double.Error in ==> lsqcurvefit at 149
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
How do I overcome this error?
Upvotes: 1
Views: 7950
Reputation: 1353
You should take a look at the documentation for the function lsqcurvefit
. You are using the function wrong. To pass the struct options
you should use the 7-argument version and pass the struct as the last 7th argument:
x = lsqcurvefit(@myfun,x0,xdata,ydata,lb,ub,options);
This means that you also need to define lb
and ub
as the 5th and 6th argument. These are the lower and upper bounds for the design variable in x
.
But you can also pass empty matrices if no bounds exist:
x = lsqcurvefit(@myfun,x0,xdata,ydata,[],[],options);
Upvotes: 3