mathematica怎么拟合多项式方程

1个回答

  • 拟合x1和y之间的曲线,用12次多项式拟合

    x1 = {1.5,1.5,2,2,2.5,2.5,2.5,2.5,3,3,3,3};

    y = {1,0.99,0.98,0.97,0.98,0.975,0.97,0.965,0.975,0.97,

    0.965,0.96};

    data = Table[{x1[[i]],y[[i]]},{i,1,Length[x1]}]

    p1 = Fit[data,{1,x,x^2,x^3,x^4,x^5,x^6,x^7,x^8,x^9,x^10,

    x^11,x^12},x]

    Show[ListPlot[data,PlotStyle -> Red],Plot[p1,{x,1,3}]]

    输出

    0.968628 + 0.062384 x - 0.0192278 x^2 - 0.00727978 x^3 -

    0.000960493 x^4 + 0.000212047 x^5 + 0.000183664 x^6 +

    0.0000720644 x^7 + 0.0000200974 x^8 + 3.65551*10^-6 x^9 -

    1.29406*10^-7 x^10 - 5.40089*10^-7 x^11 - 3.46969*10^-7 x^12

    所以可以用2次曲线拟合就可以得到比较好的结果

    p2 = Fit[data,{1,x,x^2},x]

    输出

    1.07467 - 0.0725 x + 0.0123333 x^2