MATLAB代做  | MATLAB代写  | MATLAB有偿编程
首 页
当前位置:MATLAB代做|MATLAB代写|MATLAB有偿编程matlab源码算法设计
共轭梯度法源码程序        [↓跳到下载地址]
官方主页:源码共享网站:www.buycode.cn

联系方式:客服QQ:1747812398 买代码源码软件站,欢迎咨询

运行环境:Win9X/2000/XP/2003/

源码语言:简体中文

源码类型:源码程序 - 算法设计

推荐星级:

更新时间:2013-12-29 21:59:39

源码简介

%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<6
    error('输入参数必须为6');
end
n=length(G);
if n==2
format   long e %rat
syms x1 x2
f=1/2*[x1,x2]*G*[x1;x2]+b'*[x1;x2]+c;
g=[diff(f,x1);diff(f,x2)];
g1=subs(subs(g,x1,X(1,1)),x2,X(2,1));
d=-g1;
a=-(d'*g1)/(d'*G*d);%        a=-((X(:,1)'*G*d+b'*d)/(d'*G*d));          a=g1(:,1)'*g1(:,1)/(d(:,1)'*G*d(:,1));
X(:,2)=X(:,1)+a*d;
g1=[g1 subs(subs(g,x1,X(1,2)),x2,X(2,2))];
m1=norm(g1(:,1));
m=norm(g1(:,2));
i=2;
k=zeros(1);
switch method
    case 'FR'
        while m>=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)/(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=[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=norm(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(:,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(:,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))/(m1^2);
            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))];
            m1=m;
            m=norm(g1(:,i+1));
            i=i+1;
        end
end
fv=subs(subs(f,x1,X(1,i)),x2,X(2,i));
end
l1=X(1,i);l2=X(2,i);
w1=X(1,1);w2=X(2,1);
v1=min(l1,w1)-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;
    end
end
[px,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*:');       
 


 


提 示:本站所有源码只提供浏览,需要定制的朋友可以联系在线客服!
注意:价格根据项目的难易程度来定价格业务咨询

共轭梯度法源码程序 --下载地址

注意:为避免不必要的误会,本站项目里的源码只公开部分需要的联系在线客服

本站长期招聘程序代写高手,欢迎加入华南地区matlab团队

想创业却没有经验的人

无论你是否有过网上开店的经验,都可以随时联系在线客服,建立自己独立的网站
想开网店却不知道如何入手

淘宝创业成本低而且风险小,如果想开淘宝店的朋友可以联系在线客服。
想兼职创业,却不擅长交际与服务的人

在家创业月入5000元。网站程序+百套群发工具+网赚资料+域名+空间+本站终身代理资格,这样你网赚的条件全具备了。每天3小时管理、推广、收钱。
缺乏能快速赢利型产品的人

导入多种最新流行营销软件+网赚教程,让入驻者轻松加盟、复制有效成交技巧、快速赚钱。
·上一源码:人脸识别源码程序
·下一源码:MATLAB字符串连接问题

源码评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

浏览说明

* 本站所有源码全部公开,随时随地浏览!
* MATLAB软件如用于商业用途,请购买正版!
* 如果您发现下载链接错误,请点击报告错误谢谢!
* 站内提供的所有软件包含破解及注册码均是由网上搜集,若侵犯了你的版权利益,敬请来信通知我们!
Copyright © 2008-2014 www.buycode.cn. All Rights Reserved.
页面执行时间:171.87500 毫秒