matlab中线性拟合可以使用多项式拟合函数polyfit()实现,其调用格式为
P = polyfit(X,Y,N)
其中,X,Y是需要拟合的数据,N是拟合的多项式的最高次数,P是拟合的多项式的系数。
实例演示如下:
1、示例数据
x=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2]
y=[-8,-236,-415,-562,-701,-860,-961,-1082,-1188,-1304,-1405,-1534]
拟合方程:y=a+bx
2、matlab代码
>> x=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2]; >> y=[-8,-236,-415,-562,-701,-860,-961,-1082,-1188,-1304,-1405,-1534]; >> p = polyfit(x,y,1) >> plot(x,y,‘o‘,x,polyval(p,x))
3、结果及说明
p = 1.0e+003 * -1.3253 0.0068
表示拟合的线性公式为 : y = -1325.3x+6.8
原文:https://www.cnblogs.com/flyingfishing/p/13555958.html