预览加载中,请您耐心等待几秒...
1/5
2/5
3/5
4/5
5/5

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

实验的题目和要求所属课程名称:最优化方法实验日期:实验目的掌握最速下降法,牛顿法和共轭梯度法的算法思想,并能上机编程实现相应的算法。二、实验要求用MATLAB实现最速下降法,牛顿法和共轭梯度法求解实例。四、实验原理最速下降法是以负梯度方向最为下降方向的极小化算法,相邻两次的搜索方向是互相直交的。牛顿法是利用目标函数在迭代点处的Taylor展开式作为模型函数,并利用这个二次模型函数的极小点序列去逼近目标函数的极小点。共轭梯度法它的每一个搜索方向是互相共轭的,而这些搜索方向仅仅是负梯度方向与上一次接待的搜索方向的组合。五.运行及结果如下:最速下降法:题目:f=(x-2)^2+(y-4)^2M文件:function[R,n]=steel(x0,y0,eps)symsx;symsy;f=(x-2)^2+(y-4)^2;v=[x,y];j=jacobian(f,v);T=[subs(j(1),x,x0),subs(j(2),y,y0)];temp=sqrt((T(1))^2+(T(2))^2);x1=x0;y1=y0;n=0;symskk;while(temp>eps)d=-T;f1=x1+kk*d(1);f2=y1+kk*d(2);fT=[subs(j(1),x,f1),subs(j(2),y,f2)];fun=sqrt((fT(1))^2+(fT(2))^2);Mini=Gold(fun,0,1,0.00001);x0=x1+Mini*d(1);y0=y1+Mini*d(2);T=[subs(j(1),x,x0),subs(j(2),y,y0)];temp=sqrt((T(1))^2+(T(2))^2);x1=x0;y1=y0;n=n+1;endR=[x0,y0]调用黄金分割法:M文件:functionMini=Gold(f,a0,b0,eps)symsx;formatlong;symskk;u=a0+0.382*(b0-a0);v=a0+0.618*(b0-a0);k=0;a=a0;b=b0;array(k+1,1)=a;array(k+1,2)=b;while((b-a)/(b0-a0)>=eps)Fu=subs(f,kk,u);Fv=subs(f,kk,v);if(Fu<=Fv)b=v;v=u;u=a+0.382*(b-a);k=k+1;elseif(Fu>Fv)a=u;u=v;v=a+0.618*(b-a);k=k+1;endarray(k+1,1)=a;array(k+1,2)=b;endMini=(a+b)/2;输入:[R,n]=steel(0,1,0.0001)R=1.999994136676423.99999120501463R=1.999994136676423.99999120501463n=1牛顿法:题目:f=(x-2)^2+(y-4)^2M文件:symsx1x2;f=(x1-2)^2+(x2-4)^2;v=[x1,x2];df=jacobian(f,v);df=df.';G=jacobian(df,v);epson=1e-12;x0=[0,0]';g1=subs(df,{x1,x2},{x0(1,1),x0(2,1)});G1=subs(G,{x1,x2},{x0(1,1),x0(2,1)});k=0;mul_count=0;sum_count=0;mul_count=mul_count+12;sum_count=sum_count+6;while(norm(g1)>epson)p=-G1\g1;x0=x0+p;g1=subs(df,{x1,x2},{x0(1,1),x0(2,1)});G1=subs(G,{x1,x2},{x0(1,1),x0(2,1)});k=k+1;mul_count=mul_count+16;sum_count=sum_count+11;end;kx0mul_countsum_count结果::k=1x0=24mul_count=28sum_count=17共轭梯度法:题目:f=(x-2)^2+(y-4)^2M文件:functionf=conjugate_grad_2d(x0,t)x=x0;symsxiyiaf=(xi-2)^2+(yi-4)^2;fx=diff(f,xi);fy=diff(f,yi);fx=subs(fx,{xi,yi},x0);fy=subs(fy,{xi,yi},x0);fi=[fx,fy];count=0;whiledouble(sqrt(fx^2+fy^2))>ts=-fi;ifcount<=0s=-fi;elses=s1;endx=x+a*s;f=subs(f,{xi,yi},x);f1=diff(f);f1=solve(f1);iff1~=0ai=doub