matlab 拟合函数求系数
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/05 22:33:23
matlab 拟合函数求系数
x=1:5
y=[-264662 -119192 -42940 -26347 -26335]
现在有两个模型是 y=A(1)+A(2)exp(A(3)/x)
y=A(1)/(A(2)x+A(3))
该如何拟合,哪个模型好一点?
求下5:10的值?
x=1:5
y=[-264662 -119192 -42940 -26347 -26335]
现在有两个模型是 y=A(1)+A(2)exp(A(3)/x)
y=A(1)/(A(2)x+A(3))
该如何拟合,哪个模型好一点?
求下5:10的值?
clc;clear
x=1:5;
y=[-264662 -119192 -42940 -26347 -26335];
fun1=inline('A(1)+A(2)*exp(1./x)','A','x');
fun2=inline('A(1)./(x+A(2))','A','x') ;
fun3=inline('A(1)*exp(A(2)*x)','A','x');
format short g
[A1,R1,J1,SIGMA1,MSE1] =nlinfit(x,y,fun1,[10000 -10000])
[A2,R2,J2,SIGMA2,MSE2]=nlinfit(x,y,fun2,[-10000 1 ])
[A3,R3,J3,SIGMA3,MSE3]=nlinfit(x,y,fun3,[-50000 1 ])
xx=1:0.1:10;
y1=A1(1)+A1(2)*exp(1./xx);
y2=A2(1)./(xx+A2(2));
y3=A3(1)*exp(A3(2)*xx);
plot(x,y,'o',xx,y1,xx,y2,xx,y3)
结果:
A1 =
1.7437e+005 -1.6344e+005
R1 =
5240.4 -24096 10789 9144.5 -1078.4
J1 =
1 2.7183
1 1.6487
1 1.3956
1 1.284
1 1.2214
SIGMA1 =
5.381e+008 -2.9278e+008
-2.9278e+008 1.7706e+008
MSE1 =
2.6975e+008
A2 =
-1.4941e+005 -0.43927
R2 =
1804.7 -23458 15409 15615 6426.2
J2 =
1.7834 4.7522e+005
0.64073 61340
0.39051 22786
0.28084 11785
0.21926 7183.4
SIGMA2 =
1.0283e+009 -4021.2
-4021.2 0.017282
MSE2 =
3.5869e+008
A3 =
-5.9199e+005 -0.80682
R3 =
-468.67 -1288.7 9677.4 -2865.1 -15856
J3 =
0.44628 -2.6419e+005
0.19916 -2.3581e+005
0.088881 -1.5785e+005
0.039666 -93927
0.017702 -52396
SIGMA3 =
2.9228e+009 3313.9
3313.9 0.0044886
MSE3 =
1.1838e+008
提供的模型不唯一,稍作改动.例如y=A(1)/(A(2)x+A(3)) 有无限种可能,只要分子分母存在约数.改成A(1)./(x+A(2))就唯一了.
选取mse最小的那个.
x=1:5;
y=[-264662 -119192 -42940 -26347 -26335];
fun1=inline('A(1)+A(2)*exp(1./x)','A','x');
fun2=inline('A(1)./(x+A(2))','A','x') ;
fun3=inline('A(1)*exp(A(2)*x)','A','x');
format short g
[A1,R1,J1,SIGMA1,MSE1] =nlinfit(x,y,fun1,[10000 -10000])
[A2,R2,J2,SIGMA2,MSE2]=nlinfit(x,y,fun2,[-10000 1 ])
[A3,R3,J3,SIGMA3,MSE3]=nlinfit(x,y,fun3,[-50000 1 ])
xx=1:0.1:10;
y1=A1(1)+A1(2)*exp(1./xx);
y2=A2(1)./(xx+A2(2));
y3=A3(1)*exp(A3(2)*xx);
plot(x,y,'o',xx,y1,xx,y2,xx,y3)
结果:
A1 =
1.7437e+005 -1.6344e+005
R1 =
5240.4 -24096 10789 9144.5 -1078.4
J1 =
1 2.7183
1 1.6487
1 1.3956
1 1.284
1 1.2214
SIGMA1 =
5.381e+008 -2.9278e+008
-2.9278e+008 1.7706e+008
MSE1 =
2.6975e+008
A2 =
-1.4941e+005 -0.43927
R2 =
1804.7 -23458 15409 15615 6426.2
J2 =
1.7834 4.7522e+005
0.64073 61340
0.39051 22786
0.28084 11785
0.21926 7183.4
SIGMA2 =
1.0283e+009 -4021.2
-4021.2 0.017282
MSE2 =
3.5869e+008
A3 =
-5.9199e+005 -0.80682
R3 =
-468.67 -1288.7 9677.4 -2865.1 -15856
J3 =
0.44628 -2.6419e+005
0.19916 -2.3581e+005
0.088881 -1.5785e+005
0.039666 -93927
0.017702 -52396
SIGMA3 =
2.9228e+009 3313.9
3313.9 0.0044886
MSE3 =
1.1838e+008
提供的模型不唯一,稍作改动.例如y=A(1)/(A(2)x+A(3)) 有无限种可能,只要分子分母存在约数.改成A(1)./(x+A(2))就唯一了.
选取mse最小的那个.