Error in using fitlnm: Why do I get "The model function must accept two arguments"?

4 ビュー (過去 30 日間)
pietro
pietro 2018 年 5 月 16 日
コメント済み: Star Strider 2018 年 5 月 16 日
Hi all,
I am having troubles in using fillnm. Below an example:
clear all
x=[0:0.01:10];
y=x.^2;
modelfun=@(x)(x.^2);
beta0=1;
mdl=fitnlm(x,y,modelfun,beta0);
Unfortunately, I get the following error:
Error using classreg.regr.NonLinearFormula (line 225)
The model function must accept two arguments.
Error in NonLinearModel/createFormula (line 1643)
formula =
classreg.regr.NonLinearFormula(modelDef,coefNames,predictorVars,responseVar,varNames,ncoefs);
Error in NonLinearModel.fit (line 1397)
model.Formula =
NonLinearModel.createFormula(supplied,modelDef,X,ncoefs,coefNames,
...
Error in fitnlm (line 94)
model = NonLinearModel.fit(X,varargin{:});
Why do I get this error?
Thanks.
Best regards,
Pietro

採用された回答

Star Strider
Star Strider 2018 年 5 月 16 日
The function must express the model you are fitting in terms of a vector of parameters and the independent variable, with the parameter vector being the first argument, and the independent variable the second argument.
Ideally, your model would be something like:
modelfun = @(b,x) b(1) + b(2).*x.^2;
If you are estimating no parameters, it makes no sense to use any parameter estimation function.
  2 件のコメント
pietro
pietro 2018 年 5 月 16 日
That's unbelievable I have lost two hours for a such stupid issue! Thanks a lot
Star Strider
Star Strider 2018 年 5 月 16 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEvent Functions についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by