使用matlab的曲线拟合结果错误

curve fitting result error using matlab

我在 Matlab 中使用曲线拟合插件来获得校准温度和校准温度之间的适当关系,它给了我与该曲线的关系:

Linear model Poly6:
     f(x) = p1*x^6 + p2*x^5 + p3*x^4 + p4*x^3 + p5*x^2 + p6*x + p7
       where x is normalized by mean 100.7 and std 0.9139
Coefficients (with 95% confidence bounds):
       p1 =    -0.08382  (-0.4273, 0.2597)
       p2 =    -0.06449  (-0.4851, 0.3562)
       p3 =      0.3342  (-0.8434, 1.512)
       p4 =     0.09103  (-0.9764, 1.158)
       p5 =     -0.3258  (-1.459, 0.8071)
       p6 =       1.629  (0.9808, 2.278)
       p7 =       38.76  (38.49, 39.03)

Goodness of fit:
  SSE: 9.913
  R-square: 0.9322
  Adjusted R-square: 0.9239
  RMSE: 0.4498

这是每个使用的矩阵:

temp=[36 36.1 36.2 36.3 36.4 36.5 36.6 36.7 36.8 36.9 37 37.1 37.2 37.3 37.4 37.5 37.6 37.7 37.8 37.9 38 38.1 38.2 38.3 38.4 38.5 38.6 38.7 38.8 38.9 39 39.1 39.2 39.3 39.4 39.5 39.6 39.7 39.8 39.9 40 40.1 40.2 40.3 40.4 40.5 40.6 40.7 40.8 40.9 41 41.1 41.2 41.3 41.4 41.5] ;
uncalibrated_temp=[99.132 99.185 99.052 99.162 99.203 99.142 99.650 99.720 99.610 99.561 99.764 99.961 99.942 99.863 99.825 99.941 100.127 100.156 100.462 100.323 100.381 100.392 100.527 100.582 100.549 100.362 100.488 100.656 100.792 100.953 100.891 101.095 101.161 101.182 101.161 101.224 101.537 101.491 101.392 101.539 101.565 101.749 101.704 101.764 101.707 101.910 101.968 101.805 101.807 101.791 101.771 102  101.892 101.731 101  101.581 ];
[][1]

它给了我那个图表:

但是当我使用那个一般方程时,它给了我这条与插值曲线有很大不同的曲线。 这是我写的代码:

f_temp=uncalibrated_temp;
temp1 = -0.08382  *f_temp.^6  - 0.06449  *f_temp.^5 + 0.3342  *f_temp.^4 + 0.09103  *f_temp.^3 - 0.3258  *f_temp.^2 + 1.629  *f_temp + 38.76  
figure,plot (uncalibrated_temp,temp1)

它给出了右边的曲线,其中左边的曲线是由两个矩阵的真实点生成的曲线

你在拟合结果中遗漏了一条重要的线

where x is normalized by mean 100.7 and std 0.9139

试试这个

f_temp=(uncalibrated_temp-100.7)./0.9139;

在此上下文中归一化意味着使值达到 0 均值和 1 标准差。模型给出的值是数据的平均值和标准差。例如。尝试

mean(uncalibrated_temp)

std(uncalibrated_temp)

您将看到模型为您提供的值(100.7.. 和 0.91..)。要使您的数据达到 0 均值和 1 标准差,您可以从数据中减去均值并将其除以标准差。例如

f_temp=(uncalibrated_temp-mean(uncalibrated_temp))./std(uncalibrated_temp);

我没有工具箱...但是从纯数值的角度来看,将 100 的值放入 6 次多项式将是毁灭性的:)

Matlab 通过在进行拟合过程之前移动和重新缩放值来避免这个问题。留言

where x is normalized by mean 100.7 and std 0.9139

看起来 x 值已经移动了 100.7 并缩放了 0.9139。所以,如果你写类似

f_temp=(uncalibrated_temp-100.7)/0.9139;
temp1 = -0.08382  *f_temp.^6  - 0.06449  *f_temp.^5 + 0.3342  *f_temp.^4 + 0.09103  *f_temp.^3 - 0.3258  *f_temp.^2 + 1.629  *f_temp + 38.76  

为了转换您的 x 值,它应该这样做。再次注意,我没有工具箱,也不知道转换步骤的顺序。也可能是

f_temp=(uncalibrated_temp-100.7)*0.9139;

但我确信其中之一是正确的。如果您找到解决方案,请告诉我。

祝你好运;)