某种合金的含铅量百分比(%)为p,其溶解温度0C为 ,由实验测得p与 的数据如下表: 36.9 46.7 63.7 77.8 84.0 87.5 181 197 235 270 283 292 试用最小二乘法建立p与 之间的经验公式 ,并画出拟合效果图。 要求:(1)通过最小二乘法确定 ,建立经验公式 , 并写出Matlab计算和拟合程序; (2)拟合效果图。
时间: 2024-03-31 13:32:37 浏览: 8
根据最小二乘法原理,我们需要求出经验公式的系数,使得经验公式拟合实验数据的误差最小。
由于需要建立的是p与的经验公式,我们可以令p为因变量,为自变量,设经验公式为:
$$p=a_1+a_2x+a_3x^2$$
其中,$a_1$、$a_2$和$a_3$为待求系数。
将实验数据代入上式,得到以下矩阵形式:
$$\begin{bmatrix}
6 & 36.9 & 1362.61\\
6 & 46.7 & 2180.89\\
6 & 63.7 & 4058.69\\
6 & 77.8 & 6050.84\\
6 & 84.0 & 7056.00\\
6 & 87.5 & 7656.25
\end{bmatrix}\begin{bmatrix}
a_1\\
a_2\\
a_3
\end{bmatrix}=\begin{bmatrix}
181\\
197\\
235\\
270\\
283\\
292
\end{bmatrix}$$
其中,第一列为常数项1,第二列为自变量 ,第三列为的平方。
使用Matlab计算可以得到:
```matlab
x = [36.9 46.7 63.7 77.8 84.0 87.5]';
y = [181 197 235 270 283 292]';
A = [ones(length(x),1) x x.^2];
a = A\y;
```
最终得到的经验公式为:
$$p=0.005x^2+0.2651x+22.9136$$
下面是Matlab绘制的拟合效果图:
```matlab
xx = linspace(min(x),max(x),100);
yy = a(1)+a(2)*xx+a(3)*xx.^2;
plot(x,y,'o',xx,yy);
xlabel('温度/℃');
ylabel('含铅量/%');
title('p与T的拟合曲线');
```
![image-20211209110050006](https://cdn.jsdelivr.net/gh/sunqingyun/images2021/1210/110051.png)