matlab 线性拟合polyfit_matlab如何做线性拟合

时间:2024-11-08 07:35:55

展开全部

matlab中线性拟合可以使来用多项自式拟合函数polyfit()实现bai,du其调用格式为P = polyfit(X,Y,N)

其中zhi,X,Y是需要拟合的数据,N是拟dao合的多项式的最高次数,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