数学实验作业第五组.docx
- 文档编号:25452864
- 上传时间:2023-06-08
- 格式:DOCX
- 页数:32
- 大小:133.89KB
数学实验作业第五组.docx
《数学实验作业第五组.docx》由会员分享,可在线阅读,更多相关《数学实验作业第五组.docx(32页珍藏版)》请在冰豆网上搜索。
数学实验作业第五组
实验七T7:
取不同的初值计算下列平方和形式的非线性规划,尽可能求出所有局部极小点,进而找出全局极小点,并对不同算法(搜索方向、搜索步长、数值梯度与分析梯度等)的结果进行分析、比较。
2)min
4)min
其中
解:
2)在matlab中输入程序(exam0705grad.m,exam0705grad_run.m):
function[f,g]=exam0705grad(x)
f=(x
(1)^2+12*x
(2)-11)^2+(49*x
(1)^2+49*x
(2)^2+81*x
(1)+2324*x
(2)-681)^2;%computethefunctionvalueatx
ifnargout>1%funcalledwith2outputarguments
g
(1)=2*(98*x
(1)+81)*(49*x
(1)^2+81*x
(1)+49*x
(2)^2+2324*x
(2)-681)+4*x
(1)*(x
(1)^2+12*x
(2)-11);%computethegradientevaluatedatx
g
(2)=288*x
(2)+2*(98*x
(2)+2324)*(49*x
(1)^2+81*x
(1)+49*x
(2)^2+2324*x
(2)-681)+24*x
(1)^2-264;
end
clearall;
clc;
%comparingdifferentalgorithms:
usinggradientvector
formatshorte
x0=[-1.9,2];
'---case1:
bfgs,hybrid2,3poly-------'
opt1=optimset('LargeScale','off','MaxFunEvals',1000,'GradObj','on');
[x1,v1,exit1,out1]=fminunc(@exam0705grad,x0,opt1)
pause
'---case2:
dfp,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','dfp');
[x2,v2,exit2,out2]=fminunc(@exam0705grad,x0,fopt)
pause
'---case3:
bfgs,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','bfgs');
[x3,v3,exit3,out3]=fminunc(@exam0705grad,x0,fopt)
pause
'---case4:
steep,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','steepdesc');
[x4,v4,exit4,out4]=fminunc(@exam0705grad,x0,fopt)
pause
'---case5:
bfgs,3rdpoly-------'
opt2=optimset(opt1,'LineSearchType','cubicpoly');
[x5,v5,exit5,out5]=fminunc(@exam0705grad,x0,opt2)
pause
'---case6:
dfp,3rdpoly-------'
fopt=optimset(opt2,'HessUpdate','dfp');
[x6,v6,exit6,out6]=fminunc(@exam0705grad,x0,fopt)
pause
'---case7:
bfgs,3rdpoly-------'
fopt=optimset(opt2,'HessUpdate','bfgs');
[x7,v7,exit7,out7]=fminunc(@exam0705grad,x0,fopt)
pause
'---case8:
steep,3rdpoly-------'
fopt=optimset(opt2,'HessUpdate','steepdesc');
[x8,v8,exit8,out8]=fminunc(@exam0705grad,x0,fopt)
pause
'++++resultsofsolutions++++++'
solutions=[x1;x2;x3;x4;x5;x6;x7;x8];
funvalues=[v1;v2;v3;v4;v5;v6;v7;v8];
iterations=[out1.funcCount;out2.funcCount;out3.funcCount;out4.funcCount;out5.funcCount;out6.funcCount;out7.funcCount;out8.funcCount];
[solutions,funvalues,iterations]
则输出:
x1=
-2.8997e+0002.1583e-001
v1=
3.2329e-006
exit1=
1
out1=
iterations:
32
funcCount:
41
stepsize:
1
firstorderopt:
2.3873e+000
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x438char]
x2=
-2.3709e+0002.5629e-001
v2=
6.8300e+000
exit2=
0
out2=
iterations:
401
funcCount:
422
stepsize:
1
firstorderopt:
5.7455e+003
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x128char]
x3=
-2.8997e+0002.1583e-001
v3=
3.2329e-006
exit3=
1
out3=
iterations:
32
funcCount:
41
stepsize:
1
firstorderopt:
2.3873e+000
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x438char]
x4=
-2.0594e+0002.7379e-001
v4=
1.2063e+001
exit4=
0
out4=
iterations:
118
funcCount:
1000
stepsize:
4.7397e-006
firstorderopt:
1.7291e+002
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x144char]
x5=
-2.8997e+0002.1583e-001
v5=
3.2329e-006
exit5=
1
out5=
iterations:
32
funcCount:
41
stepsize:
1
firstorderopt:
2.3873e+000
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x438char]
x6=
-2.3709e+0002.5629e-001
v6=
6.8300e+000
exit6=
0
out6=
iterations:
401
funcCount:
422
stepsize:
1
firstorderopt:
5.7455e+003
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x128char]
x7=
-2.8997e+0002.1583e-001
v7=
3.2329e-006
exit7=
1
out7=
iterations:
32
funcCount:
41
stepsize:
1
firstorderopt:
2.3873e+000
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x438char]
x8=
-2.0594e+0002.7379e-001
v8=
1.2063e+001
exit8=
0
out8=
iterations:
118
funcCount:
1000
stepsize:
4.7397e-006
firstorderopt:
1.7291e+002
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x144char]
ans=
++++resultsofsolutions++++++
ans=
-2.8997e+0002.1583e-0013.2329e-0064.1000e+001
-2.3709e+0002.5629e-0016.8300e+0004.2200e+002
-2.8997e+0002.1583e-0013.2329e-0064.1000e+001
-2.0594e+0002.7379e-0011.2063e+0011.0000e+003
-2.8997e+0002.1583e-0013.2329e-0064.1000e+001
-2.3709e+0002.5629e-0016.8300e+0004.2200e+002
-2.8997e+0002.1583e-0013.2329e-0064.1000e+001
-2.0594e+0002.7379e-0011.2063e+0011.0000e+003
改变x0,程序见附序(di1tix0.m),因太过繁琐,只输出最后x的值,输出:
ans=
-2.8956e+0002.1618e-0014.6001e-0044.9000e+001
-2.9377e+0002.1295e-0011.0877e+0004.6600e+002
-2.8956e+0002.1618e-0014.6001e-0044.9000e+001
-1.4106e+0002.9837e-0012.9482e+0011.0000e+003
-2.8956e+0002.1618e-0014.6001e-0044.9000e+001
-2.9377e+0002.1295e-0011.0877e+0004.6600e+002
-2.8956e+0002.1618e-0014.6001e-0044.9000e+001
-1.4106e+0002.9837e-0012.9482e+0011.0000e+003
4)程序见(exam07052grad.m,Untitled.m),输出结果:
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
-1.9000e+0001.0000e+0002.0000e+0005.0213e+0021.6000e+001
改变初值x0后程序见Untitled1.m,输出结果:
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
-1.9000e+0002.0000e+0002.0000e+0002.9923e+0021.7000e+001
结论:
从2)4)输出观察和比较数据可以看出改变x0,最优解随之改变,而bfgs公式,混合2,3次插值,求得的局部最优解最接近全局最优解。
实验七T8:
取不同的初值计算下列非线性规划,尽可能求出所有局部极小点,进而找出全局极小点,并对不同算法(搜索方向、搜索步长、数值梯度与分析梯度等)的结果进行分析、
比较。
3)min
解:
3)在matlab中输入程序(exam07051grad.m,exam07051grad_run.m):
function[f,g]=exam07051grad(x)
f=(x
(1)-2)^2+(x
(2)-1)^2+0.04/(-0.25*x
(1)^2-x
(2)^2+1)+5*(x
(1)-2*x
(2)+1)^2;%computethefunctionvalueatx
ifnargout>1%funcalledwith2outputarguments
g
(1)=12*x
(1)-20*x
(2)+x
(1)/(50*(x
(1)^2/4+x
(2)^2-1)^2)+6
;%computethegradientevaluatedatx
g
(2)=42*x
(2)-20*x
(1)+(2*x
(2))./(25*(x
(1)^2/4+x
(2)^2-1)^2)-22;
end
clearall;
clc;
%comparingdifferentalgorithms:
usinggradientvector
formatshorte
x0=[-1.9,2];
'---case1:
bfgs,hybrid2,3poly-------'
opt1=optimset('LargeScale','off','MaxFunEvals',1000,'GradObj','on');
[x1,v1,exit1,out1]=fminunc(@exam07051grad,x0,opt1)
pause
'---case2:
dfp,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','dfp');
[x2,v2,exit2,out2]=fminunc(@exam07051grad,x0,fopt)
pause
'---case3:
bfgs,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','bfgs');
[x3,v3,exit3,out3]=fminunc(@exam07051grad,x0,fopt)
pause
'---case4:
steep,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','steepdesc');
[x4,v4,exit4,out4]=fminunc(@exam07051grad,x0,fopt)
pause
'---case5:
bfgs,3rdpoly-------'
opt2=optimset(opt1,'LineSearchType','cubicpoly');
[x5,v5,exit5,out5]=fminunc(@exam07051grad,x0,opt2)
pause
'---case6:
dfp,3rdpoly-------'
fopt=optimset(opt2,'HessUpdate','dfp');
[x6,v6,exit6,out6]=fminunc(@exam07051grad,x0,fopt)
pause
'---case7:
bfgs,3rdpoly-------'
fopt=optimset(opt2,'HessUpdate','bfgs');
[x7,v7,exit7,out7]=fminunc(@exam07051grad,x0,fopt)
pause
'---case8:
steep,3rdpoly-------'
fopt=optimset(opt2,'HessUpdate','steepdesc');
[x8,v8,exit8,out8]=fminunc(@exam07051grad,x0,fopt)
pause
'++++resultsofsolutions++++++'
solutions=[x1;x2;x3;x4;x5;x6;x7;x8];
funvalues=[v1;v2;v3;v4;v5;v6;v7;v8];
iterations=[out1.funcCount;out2.funcCount;out3.funcCount;out4.funcCount;out5.funcCount;out6.funcCount;out7.funcCount;out8.funcCount];
[solutions,funvalues,iterations]
输出(太多,省略一部分):
x8=
1.7954e+0001.3778e+000
v8=
1.6904e-001
exit8=
1
out8=
iterations:
42
funcCount:
105
stepsize:
2.0518e-002
firstorderopt:
9.4180e-005
algorithm:
'medium-scale:
Quasi-Newtonlinesearch'
message:
[1x438char]
ans=
++++resultsofsolutions++++++
ans=
1.7954e+0001.3779e+0001.6904e-0019.0000e+000
1.7954e+0001.3779e+0001.6904e-0011.1000e+001
1.7954e+0001.3779e+0001.6904e-0019.0000e+000
1.7954e+0001.3778e+0001.6904e-0011.0500e+002
1.7954e+0001.3779e+0001.6904e-0019.0000e+000
1.7954e+0001.3779e+0001.6904e-0011.1000e+001
1.7954e+0001.3779e+0001.6904e-0019.0000e+000
1.7954e+0001.3778e+0001.6904e-0011.0500e+002
clearall;
clc;
%comparingdifferentalgorithms:
usinggradientvector
formatshorte
x0=[-1,2];
'---case1:
bfgs,hybrid2,3poly-------'
opt1=optimset('LargeScale','off','MaxFunEvals',1000,'GradObj','on');
[x1,v1,exit1,out1]=fminunc(@exam07051grad,x0,opt1)
pause
'---case2:
dfp,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','dfp');
[x2,v2,exit2,out2]=fminunc(@exam07051grad,x0,fopt)
pause
'---case3:
bfgs,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','bfgs');
[x3,v3,exit3,out3]=fminunc(@exam07051grad,x0,fopt)
pause
'---case4:
steep,hybrid2,3poly-------'
fopt=optimset(opt1,'HessUpdate','steepdesc');
[x4,v4,exit4,out4]=fminunc(@exam07051grad,x0,fopt)
pause
'---case5:
bfgs,3rdpoly-------'
opt2=optimset(opt1,'LineSearchType','cubicpoly');
[x5,v5,exit5,out5]=fminunc(@exam07051grad,x0,opt2)
pause
'---case6:
dfp,3rdpoly-------'
fopt=optimset(opt2,'HessUpdate','dfp');
[x6,v6,exit6,out6]=fminunc(@exam07051grad,x0,fopt)
pause
'---case7:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数学 实验 作业 第五