フィルターのクリア

nonlinear curve fitting: how to add an extra data vector?

2 ビュー (過去 30 日間)
Ramirez
Ramirez 2014 年 9 月 24 日
コメント済み: Matt J 2014 年 9 月 25 日
Hi, I know how to fit a curve to the ' ydata ' vector, e.g.:
opt = fitoptions('Method','NonlinearLeastSquares',...
'Startpoint',[1,0.2]);
fun = fittype('p1*cos(x)+p2*sin(x)','options',opt);
[fitobject,gof,output] = fit(time',ydata,fun)
However, I would like to include an additional data vector [same size as time and ydata(time) ] as a non-free time varying parameter [ pdata(time) ] to the function, so that we have something along this form:
fun = fittype('pdata*(p1*cos(x)+p2*sin(x))','options',opt);
Does anyone know how to implement this?

回答 (1 件)

Matt J
Matt J 2014 年 9 月 24 日
編集済み: Matt J 2014 年 9 月 24 日
You can specify the model as an anonymous function and pass parameters to that in the usual way and/or you could use the 'problem' input option to fittype/fit, see
  2 件のコメント
Ramirez
Ramirez 2014 年 9 月 24 日
I tried your suggestion using:
fun = fittype( @(p1,p2,pdata,x) pdata*(p1*cos(x)+p2*sin(x)))
[fitobject,gof,output] = fit(time',y,fun,'problem','pdata')
where pdata is a vector with the same length as y and time. However I get the following error message:
Error using fit>iAssertNumProblemParameters (line 1115) Wrong number of values for problem parameters. Specify the values as a cell array with one element for each problem parameter in the fittype.
Matt J
Matt J 2014 年 9 月 25 日
fun = fittype( @(p1,p2,x) pdata.*(p1.*cos(x)+p2.*sin(x)),'problem','pdata');
[fitobject,gof,output] = fit(time',y,fun,'problem',pdata)

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

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by