2012-07-04 24 views
1

我想在lsqcurvefit命令中使用Levenberg Marquardt算法。我已經做了以下內容:使用lsqcurvefit中的選項

options = optimset('LevenbergMarquardt','on'); 
x = lsqcurvefit(@myfun,x0,xdata,ydata,options); 

我得到以下錯誤:

??? 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] = ...

如何克服這個問題?

回答

2

您應該查看功能lsqcurvefitdocumentation。您使用的功能錯誤。要通過options你應該使用7參數版本並通過結構作爲最後7論點的結構:

x = lsqcurvefit(@myfun,x0,xdata,ydata,lb,ub,options); 

這意味着你還需要定義lbub爲第五和第六的說法。這些是x中設計變量的下限和上限。

但你也可以通過空矩陣如果不存在界限:

x = lsqcurvefit(@myfun,x0,xdata,ydata,[],[],options);