Fitting unknowns to a curve with minimized error

5 ビュー (過去 30 日間)
Tiffany
Tiffany 2013 年 8 月 30 日
I have a series of equations I am trying to fit to a data set (x) separately:
for example:
(a+b*c)*d = x
a*(1+b*c)*d = x
x = 1.9248 3.0137 4.0855 5.0097 5.7226 6.2064 6.4655 6.5108 6.3543 6.0065
c= 0.0200 0.2200 0.4200 0.6200 0.8200 1.0200 1.2200 1.4200 1.6200 1.8200
d = 1.2849 2.2245 3.6431 5.6553 8.3327 11.6542 15.4421 19.2852 22.4525 23.8003
I know c, d and x - they are observations. My unknowns are a and b, and should be constant.
I have tried fsolve and polyfit at the recommendation of others - the polyfit gives a very poor fit. What should I do?
Note: I have asked on SO and this code section was written by Prashant. Another author Emmet suggested a similar strategy using polyfit.
(a+b*c)*d = x
p = polyfit(c, x./d, 1);
a = p(2);
b = p(1);
a*(1+b*c)*d = x
p = polyfit(c, x./d, 1);
a = p(2);
b = p(1) / a;
I'm trying to learn how to fit curves with data instead of curve fitting using the Matlab tool. If someone could show me a general example or use my numbers as an example that I could follow and learn, that would be a brilliant thing :) Thank you for your time.

採用された回答

the cyclist
the cyclist 2013 年 8 月 30 日
編集済み: the cyclist 2013 年 8 月 30 日
This doesn't seem like a bad fit to me.
x = [1.9248 3.0137 4.0855 5.0097 5.7226 6.2064 6.4655 6.5108 6.3543 6.0065];
c = [0.0200 0.2200 0.4200 0.6200 0.8200 1.0200 1.2200 1.4200 1.6200 1.8200];
d = [1.2849 2.2245 3.6431 5.6553 8.3327 11.6542 15.4421 19.2852 22.4525 23.8003];
p = polyfit(c,x./d,1);
a = p(2);
b = p(1);
figure
plot(c,x./d,'.',c,a+b*c)
Were you expecting something better than linear?
p_2nd = polyfit(c,x./d,2);
figure
plot(c,x./d,'.',c,p_2nd(1)*c.^2+p_2nd(2)*c+p_2nd(3))
  4 件のコメント
the cyclist
the cyclist 2013 年 8 月 30 日
polyfit() uses a polynomial to fit. Your code fit a 1st-order polynomial (i.e. straight line). Notice that all I did was fit a 2nd-order polynomial (a parabola).
In other words, you fit
x/d = P0 + P1*c
where I fit
x/d = P0 + P1*c + P2*c^2
So, yes, an extra term, and therefore an extra parameter.
Tiffany
Tiffany 2013 年 9 月 2 日
Thank you for your explanation :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by