数据如下t=[1 2 3 4 5 6 7 8] y=[4.00 6.40 8.00 8.80 9.22 9.50 9.70 9.68]
1.使用非线性最小二乘拟合函数lsqcurvefit拟合
t=[1 2 3 4 5 6 7 8];
y=[4.00 6.40 8.00 8.80 9.22 9.50 9.70 9.68];
fun=@(b,x)x./(b(1)*x+b(2));
x0=[0.1 0.1];
b=lsqcurvefit(fun,x0,t,y)
结果为:
b =
0.0811 0.1468
即a=0.0811 b=0.1468
2.绘图
plot(t,y,'ko');
hold on
plot(t,fun(b,t),'r-');
legend('Original data','fitted curve ')