x=[100 105 96 102] ;
y=[105 96 102 101];
fun=inline('a(1)*x^2+a(2)*x+a(3)','a','x');
a=lsqcurvefit(fun,[1, 1, 1],x,y);
c=a(3),b=a(2),a=a(1)
c =
-2.2001e+003
>> b=a(2)
b =
46.5663
>> a=a(1)
a =
-0.2353
多项式拟合
x=[100 105 96 102];
y=[105 96 102 101];
t=polyfit(x,y,2);
a=t(1)
b=t(2)
c=(3)
>> x=[100 105 96 102]';
y=[105 96 102 101]';
X=[ones(size(x)) x x.^2];
t=regress(y,X);
a=t(3)
b=t(2)
c=t(1)
a*x.^2+b*x+c
----------------------------------
结果如下:
a =
-0.2353
b =
46.5665
c =
-2.2001e+003
ans =
104.0099
95.7066
102.1834
102.1001
>>