- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
精品学习资料
名师归纳总结——欢迎下载
优化方法上机大作业
优化方法上机大作业
学 院:
姓 名:
学 号:
指导老师 : 肖 现 涛
. 专业.专心 .
精品学习资料
名师归纳总结——欢迎下载
第一题
第一题
源程序如下 :
function zy_x = di1ti(x)
%di1ti 是用来求解优化作业第一题的函数 ;
x0=x; yimuxulong=0.000001; g0=g(x0);s0=-g0; A=2*ones(100,100);
k=0;
while k100
lanmed=-(g0)*s0/(s0*A*s0); x=x0+lanmed*s0;
g=g(x); k=k+1;
if norm(g)yimuxulong
. 专业.专心 .
精品学习资料
名师归纳总结——欢迎下载
zy_x=x;
fprintf(After %d iterations,obtain the optimal solution.\n \n The optimal solution is \n %f.\n\nThe optimal x is ans.,k,f(x) )
break;
end miu=norm(g)^2/norm(g0)^2; s=-g+miu*s0;
g0=g; s0=s;x0=x;
end
function f=f(x) f=(x*ones(100,1))^2-x*ones(100,1);
function g=g(x) g=(2*x*ones(100,1))*ones(100,1)-ones(100,1);
代入x0,运行结果如下 :
x=zeros(100,1);
di1ti(x)
After 1 iterations,obtain the optimal solution.
The optimal solution is
. 专业.专心 .
精品学习资料
名师归纳总结——欢迎下载
-0.250000.
-0.250000.
The optimal x is ans.
ans =0.005*ones(100,1).
其次题
最速下降法 ;源程序如下 :
function zy_x=di2titidu(x)
%该函数用来解大作业其次题 ;x0=x; yimuxulong=1e-5; k=0; g0=g(x0); s0=-g0;
. 专业.专心 .
精品学习资料
名师归纳总结——欢迎下载
while k=0
if norm(g0)yimuxulong break;
else
lanmed=10;c=0.1;i=0; while i=0i100
x=x0+lanmed*s0;
if f(x)(f(x0)+c*lanmed*g0*s0) lanmed=lanmed/2;
i=i+1;
else
break;
end
end x=x0+lanmed*s0; x0=x;
g0=g(x); s0=-g0;
k=k+1;
end end zy_x=x; zyj=f(x);
fprintf(after %d iterations,obtain the optimal solution.\n\nThe optimal solution is %f.\n\n The optimal x is ans.\n,k,zyj);
. 专业.专心 .
精品学习资料
名师归纳总结——欢迎下载
function f=f(x) x1=[1 0 0 0]*x;
x2=[0 1 0 0]*x;
x3=[0 0 1 0]*x;
x4=[0 0 0 1]*x;
f=(x1-1)^2+(x3-1)^2+100*(x2-x1^2)^2+100*(x4-x3^2)^2;
function g=g(x) x1=[1 0 0 0]*x;
x2=[0 1 0 0]*x;
x3=[0 0 1 0]*x;
x4=[0 0 0 1]*x;
g=[2*(x1-1)-400*x1*(x2-x1^2);200*(x2-x1^2);2*(x3-1)-400*x3*(x4-x3^2);200*(x4-x3^ 2)];
x=[-1.2 1 -1.2 1];
di2titidu(x)
after 5945 iterations,obtain the optimal solution.
The optimal solution is 0.000000.
The optimal x is ans.
. 专业.专心 .
精品学习资料
名师归纳总结——欢迎下载
ans =
1.0000
1.0000
1.0000
1.0000
牛 顿 法 源程序如下 :
function zy_x=di2tinewton(x)
%该函数用来解大作业其次题 ;
x0=x; yimuxulong=1e-5; k
文档评论(0)