共轭梯度法MATLAB程序.doc

上传人:壹****1 文档编号:560619569 上传时间:2023-09-08 格式:DOC 页数:4 大小:31.02KB
返回 下载 相关 举报
共轭梯度法MATLAB程序.doc_第1页
第1页 / 共4页
共轭梯度法MATLAB程序.doc_第2页
第2页 / 共4页
共轭梯度法MATLAB程序.doc_第3页
第3页 / 共4页
共轭梯度法MATLAB程序.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《共轭梯度法MATLAB程序.doc》由会员分享,可在线阅读,更多相关《共轭梯度法MATLAB程序.doc(4页珍藏版)》请在金锄头文库上搜索。

1、%conjugate gradient methods%method:FR,PRP,HS,DY,CD,WYL,LS%精确线搜索,梯度终止准则function m,k,d,a,X,g1,fv = conjgradme( G,b,c,X,e,method)if nargin=e k(i-1)=(m/m1)2; d(:,i)=-g1(:,i)+k(i-1)*d(:,i-1); a(i)=-(d(:,i)*g1(:,i)/(d(:,i)*G*d(:,i); %a1(i)=-(X(:,i)*G*d(:,i)+b*d(:,i)/(d(:,i)*G*d(:,i);a(i)=g1(:,i)*g1(:,i)/(

2、d(:,i)*G*d(:,i); X(:,i+1)=X(:,i)+a(i)*d(:,i); g1=g1 subs(subs(g,x1,X(1,i+1),x2,X(2,i+1); m1=m; m=norm(g1(:,i+1); i=i+1; end case PRP while m=e k(i-1)=g1(:,i)*(g1(:,i)-g1(:,i-1)/(norm(g1(:,i-1)2; d(:,i)=-g1(:,i)+k(i-1)*d(:,i-1); a(i)=-(d(:,i)*g1(:,i)/(d(:,i)*G*d(:,i); X(:,i+1)=X(:,i)+a(i)*d(:,i); g1=

3、g1 subs(subs(g,x1,X(1,i+1),x2,X(2,i+1); m=norm(g1(:,i+1); i=i+1; end case HS while m=e k(i-1)=g1(:,i)*(g1(:,i)-g1(:,i-1)/(d(:,i-1)*(g1(:,i)-g1(:,i-1); d(:,i)=-g1(:,i)+k(i-1)*d(:,i-1); a(i)=-(d(:,i)*g1(:,i)/(d(:,i)*G*d(:,i); X(:,i+1)=X(:,i)+a(i)*d(:,i); g1=g1 subs(subs(g,x1,X(1,i+1),x2,X(2,i+1); m=no

4、rm(g1(:,i+1); i=i+1; end case DY while m=e k(i-1)=g1(:,i)*g1(:,i)/(d(:,i-1)*(g1(:,i)-g1(:,i-1); d(:,i)=-g1(:,i)+k(i-1)*d(:,i-1); a(i)=-(d(:,i)*g1(:,i)/(d(:,i)*G*d(:,i); X(:,i+1)=X(:,i)+a(i)*d(:,i); g1=g1 subs(subs(g,x1,X(1,i+1),x2,X(2,i+1); m=norm(g1(:,i+1); i=i+1; end case LS while m=e k(i-1)=g1(:,

5、i)*(g1(:,i)-g1(:,i-1)/(d(:,i-1)*(-g1(:,i-1); d(:,i)=-g1(:,i)+k(i-1)*d(:,i-1); a(i)=-(d(:,i)*g1(:,i)/(d(:,i)*G*d(:,i); %a(i)=-(X(:,i)*G*d(:,i)+b*d(:,i)/(d(:,i)*G*d(:,i); X(:,i+1)=X(:,i)+a(i)*d(:,i); g1=g1 subs(subs(g,x1,X(1,i+1),x2,X(2,i+1); m=norm(g1(:,i+1); i=i+1; end case CD while m=e k(i-1)=g1(:,

6、i)*g1(:,i)/(d(:,i-1)*(-g1(:,i-1); d(:,i)=-g1(:,i)+k(i-1)*d(:,i-1); a(i)=-(d(:,i)*g1(:,i)/(d(:,i)*G*d(:,i); X(:,i+1)=X(:,i)+a(i)*d(:,i); g1=g1 subs(subs(g,x1,X(1,i+1),x2,X(2,i+1); m=norm(g1(:,i+1); i=i+1; end case WYL while m=e k(i-1)=g1(:,i)*(g1(:,i)-(m/m1)*g1(:,i-1)/(m12); d(:,i)=-g1(:,i)+k(i-1)*d(

7、:,i-1); a(i)=-(d(:,i)*g1(:,i)/(d(:,i)*G*d(:,i); %a(i)=-(X(:,i)*G*d(:,i)+b*d(:,i)/(d(:,i)*G*d(:,i); X(:,i+1)=X(:,i)+a(i)*d(:,i); g1=g1 subs(subs(g,x1,X(1,i+1),x2,X(2,i+1); m1=m; m=norm(g1(:,i+1); i=i+1; endendfv=subs(subs(f,x1,X(1,i),x2,X(2,i); endl1=X(1,i);l2=X(2,i);w1=X(1,1);w2=X(2,1);v1=min(l1,w1)

8、-abs(l1-w1)/10:abs(l1-w1)/10:max(l1,w1)+abs(l1-w1)/10;v2=min(l2,w2)-abs(l2-w2)/10:abs(l2-w2)/10:max(l2,w2)+abs(l2-w2)/10;x,y=meshgrid(v1,v2);s=size(x);z=zeros(size(x);for i=1:s(1) for j=1:s(2) z(i,j)=1/2*x(i,j),y(i,j)*G*x(i,j);y(i,j)+b*x(i,j);y(i,j)+c; endendpx,py = gradient(z,.2,.2);contour(v1,v2,z), hold on, quiver(v1,v2,px,py)C,h = contour(x,y,z);set(h,ShowText,on,TextStep,get(h,LevelStep)*2)x1=X(1,:);y1=X(2,:);plot(x1,y1,r*:);

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号