用MatLab进行多项式3次方拟合 30
4 4.60206 4.954243 5.20412 5.39794 5.556303 5.690196 5.80618 5.908485 6
y1=1.744.028.0613.419.525.731.837.242.847.952.957.8
y2=1.83.66.510.214.418.72327.131.735.940.245.6
y3=1.743.977.7512.51823.228.533.539.244.349.456.2
y4=1.11.311.682.283.093.974.885.827.18.229.3310.9
用MatLab进行多项式3次方拟合,分别拟合{x,y1},{x,y2},{x,y3},{x,y4}对应的多项式3次方拟合方程
y=ax^3+bx^2+cx+d中的a,b,c,d各自的系数。
y1=1.74,4.02,8.06,13.4,19.5,25.7,31.8,37.2,42.8,47.9,52.9,57.8
y2=1.8,3.6,6.5,10.2,14.4,18.7,23,27.1,31.7,35.9,40.2,45.6
y3=1.74,3.97,7.75,12.5,18,23.2,28.5,33.5,39.2,44.3,49.4,56.2
y4=1.1,1.31,1.68,2.28,3.09,3.97,4.88,5.82,7.1,8.22,9.33,10.9 展开
2015-09-27
x=
4 4.60206 4.954243 5.20412 5.39794 5.556303 5.690196 5.80618 5.908485 6 6.08278537 6.158362492
我知道容易做,但我没有安装MatLab呀,谁安装了帮拟合一下呢。
参考代码:
x=[ 4 4.60206 4.954243 5.20412 5.39794 5.556303 5.690196 5.80618 5.908485 6 6.08278537 6.158362492];
y1=[1.74, 4.02, 8.06, 13.4, 19.5, 25.7, 31.8, 37.2, 42.8, 47.9, 52.9, 57.8];
y2=[1.8, 3.6, 6.5, 10.2, 14.4, 18.7, 23, 27.1, 31.7, 35.9, 40.2, 45.6];
y3=[1.74, 3.97, 7.75, 12.5, 18, 23.2, 28.5, 33.5, 39.2, 44.3, 49.4, 56.2];
y4=[1.1, 1.31, 1.68, 2.28, 3.09, 3.97, 4.88, 5.82, 7.1, 8.22, 9.33, 10.9];
p1=polyfit(x,y1,3)
p2=polyfit(x,y2,3)
p3=polyfit(x,y3,3)
p4=polyfit(x,y4,3)
cla
plot(x,[y1;y2;y3;y4])
hold on
plot(x,[polyval(p1,x);polyval(p2,x);polyval(p3,x);polyval(p4,x)],'--')
拟合结果:
系数:
p1 =
2.9813 -28.9976 86.3931 -70.5498
p2 =
4.8961 -61.5470 260.6037 -369.2625
p3 =
5.5190 -68.1560 283.6332 -395.5758
p4 =
2.0074 -27.1706 122.7532 -183.6924