Non-linear curvefitting in MATLAB
古いコメントを表示
Hey guys! I'm some given some huge set of data. I am trying to fit a set of data into a model of functional form as described below:
z(x, y) = c0. * x^0 * y^2 + c1. * x^1 * y^1 + c2. * x^2 *y^1
where c0, c1, c2 are the coefficients to be found.
My attempt is to use the nlinfit function to solve it.
So far I have tried:
% i have just added a small portion of my data
a= [ 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001,0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011];
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
y = x.* a;
z = [ -.304860225, .170315374, .343019354, .370114906, .373180536, .36719579, .363397853, .363417755, .366962504, .379710865, -.304860225, .170315374, .343019354, .370114906, .373180536, .36719579, .363397853, .363417755, .366962504, .379710865];
model= c0.* (x(:).^0).* (y(:).^2) + c1.* (x(:).^1).* (y(:).^1) + c2.* (x(:).^2).* (y(:).^0)
[c0 c1 c2] = [0.001 0.007 0.788]
C= nlinfit( [x,y], z, 'model', [0.001 0.007 0.788])
% Here x,y are independent variables and z is dependent variable.
How can one set these initial values for the coefficients? I'm not getting how to pass the arguments. I'm getting this error "??? Undefined function or variable 'c0' ". Please help!!!
Thanks in advance, Syeda
採用された回答
その他の回答 (1 件)
Matt J
2013 年 10 月 8 日
1 投票
Using a nonlinear solver for a linear fitting problem seems like the wrong way to go. A better option might be
10 件のコメント
Syeda
2013 年 10 月 8 日
Matt J
2013 年 10 月 8 日
I've never used the tool myself. Perhaps you need to columnize z,
p = polyfitn([x,y], z(:), 'model');
Syeda
2013 年 10 月 8 日
Matt J
2013 年 10 月 8 日
Maybe this
p = polyfitn([x(:),y(:)], z(:), {'y', 'x*y', 'x^2*y'});
Matt J
2013 年 10 月 8 日
I can't see why the syntax
p = polyfitn([x(:),y(:)], z(:), 'model')
would work. And it is obviously not working, since it gives you the wrong number of coefficients.
Syeda
2013 年 10 月 8 日
Matt J
2013 年 10 月 8 日
Dunno. Instead of 'x^2*y' maybe you should try either 'x*x*y' or 'y*x^2'.
Syeda
2013 年 10 月 9 日
カテゴリ
ヘルプ センター および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!