用MATLAB计算—最小二乘法及均方误差这两个题用MATLAB怎么做,并作图?1.实验数据xi 19 25 31 38 44yi 19.0 32.3 49.0 73.3 97.8用最小二乘法求型如y=a+bx^2的经验公式及均方误差.2.化学反应中由实验得分解

来源:学生作业学帮网 编辑:学帮网 时间:2024/05/09 03:56:43

用MATLAB计算—最小二乘法及均方误差
这两个题用MATLAB怎么做,并作图?
1.
实验数据
xi 19 25 31 38 44
yi 19.0 32.3 49.0 73.3 97.8
用最小二乘法求型如y=a+bx^2的经验公式及均方误差.
2.
化学反应中由实验得分解物浓度与实践关系
时间t /s 0 5 10 15 20 25 30 35 40 45 50 55
浓度y /(×10^-4) 0 1.27 2.16 2.86 3.44 3.87 4.15 4.37 4.51 4.58 4.62 4.64
用最小二乘法求y=f(t)
运行什么语句啊
第2题 函数模型是 y=a*e^(-b/t)

用fit函数或者nlinfit,nlinfit是最小平方估计
比如第一个
>> y= [19.0 32.3 49.0 73.3 97.8]
y =
19.0000 32.3000 49.0000 73.3000 97.8000
>> x=[19 25 31 38 44]
x =
19 25 31 38 44
>> fit(x',y','a+b*x^2')
Warning:Start point not provided,choosing random start point.
> In fit>handlewarn at 715
In fit at 315
ans =
General model:
ans(x) = a+b*x^2
Coefficients (with 95% confidence bounds):
a = 0.9726 (0.7579,1.187)
b = 0.05004 (0.04986,0.05021)
用nlinfit
建立m文件mymodel.m
function y=mymodel(beta,x)
y=beta(1)+beta(2)*x.^2;
console下输入:
nlinfit(x,y,@mymodel,[0 0])
ans =
0.9726 0.0500
第二个我不知道函数模型,没法拟合
x=[0 5 10 15 20 25 30 35 40 45 50 55];
y=[0 1.27 2.16 2.86 3.44 3.87 4.15 4.37 4.51 4.58 4.62 4.64];
建立m文件mymodel.m
function y=mymodel(beta,x)
y=beta(1)*exp(-beta(2)./x);
console下输入:
nlinfit(x,y,@mymodel,[1 1])
ans =
5.5031 8.7873