multi-vari​able-param​etric data fitting

Hello,
I try to fit the following polynomial to a set of data:
myfun =fittype(@(a,b,c,d,e,f,x,y) y.^3-a*x*y.^2-b*y.^2+c*y*x.^2+d*x*y+e*y-f*x, 'ind', {'x' 'y'},'dep','z')
After I ask matlab to fit the function to my data:
myfit = fit([data(:,1),data(:,2)],z,myfun)
I get the following error.
Warning: Start point not provided, choosing random start point.
> In Warning>Warning.throw at 31
In fit>iFit at 320
In fit at 109
Error using fit>iFit (line 415)
Error while trying to evaluate FITTYPE function :
Inner matrix dimensions must agree.
Error in fit (line 109)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Caused by:
Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.
What I am doing wrong? data is a matrix of 25x2. which my x is the first column and y is the second. z is defined as
z=zeros(25,1);
Which simply means the coefficients should be obtained in a way to get a flat surface... Any idea why I get such error?

1 件のコメント

Matt J
Matt J 2014 年 9 月 10 日
Why not simply,
myfit = fit(data,z,myfun)

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

回答 (1 件)

Matt J
Matt J 2014 年 9 月 10 日

0 投票

Make sure all operations are elementwise,
>> fun=@(a,b,c,d,e,f,x,y) y.^3-a*x*y.^2-b*y.^2+c*y*x.^2+d*x*y+e*y-f*x;
>> vectorize(fun)
ans =
@(a,b,c,d,e,f,x,y)y.^3-a.*x.*y.^2-b.*y.^2+c.*y.*x.^2+d.*x.*y+e.*y-f.*x

1 件のコメント

Shazux Gharasoo
Shazux Gharasoo 2014 年 9 月 11 日
Hi, thank you for your comment and answer. It still makes the same error!
my dependent variable is actually 'y'! Since my function is not y=f(x) but it is f(x,y)=0, I did it this way assuming z=f(x,y)=0. is this way of doing it correct at all? any hint on how to do it? Or shall I do it in a completely different way?
I tried:
myfun =fittype(@(a,b,c,d,e,f,x,y) y.^3-a*x*y.^2-b*y.^2+c*y*x.^2+d*x*y+e*y-f*x, 'ind', {'x'},'dep','y')
but it didnt work in Matlab

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

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

質問済み:

2014 年 9 月 10 日

コメント済み:

2014 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by