suffer 发表于 2006-10-20 15:07

最优化计算的牛顿法+共轭梯度法的MATLAB程序

共包含五个 m文件

main.m

function y=main(x)
%This program uses the steepest_down + conjugate_grad method
%to calculate the minimum of the function f(x)=x(1)^2+2*x(2)^2

format long
eps=input('please input your accuracy:');
%eps is the demmanded accuracy on the norm of
%the gradient of the objective function

m=1;
%m is the count of the iteration step of the algorithm

iterstep(1,:)=x;
%iterstep contains the intermediate points of iteration

while m<=3
   while norm(gradobject1(x))>eps
   grad=gradobject1(x);
   alpha=goldsplictobj(x);
   x=x-alpha*grad;
   iterstep(m+1,:)=x;
   m=m+1;
end
end

while norm(gradobject1(x))>eps
    x1=iterstep(m-1,:);
    x2=iterstep(m,:);
    grad1=gradobject1(x1);
    grad2=gradobject1(x2);
    beta=(norm(gradobject1(x2))/norm(gradobject1(x1)))^2;
    S=-grad2-beta*grad1;
    x2=x2-alpha*S;
    x=x2;
    iterstep(m+1,:)=x;
    m=m+1;
end


step=max(size(iterstep))-1
x
iterstep
plot(iterstep(:,1),iterstep(:,2));
%Draw the search trajectory

[ 本帖最后由 suffer 于 2006-10-20 15:10 编辑 ]

suffer 发表于 2006-10-20 15:08

gradobject1.m

%The following subfunction is on the gradient of
%the objective function
function y=gradobject1(v)
y(1)=2*v(1)-v(2)-10;
y(2)=2*v(2)-v(1)-4;

suffer 发表于 2006-10-20 15:09

goldsplictobj.m

%The following subfunction is on the goldspliction
%search of the substi function
function y=goldsplictobj(x)
a=0;
b=10;
eps=0.01;
y1=a+0.382*(b-a);
y2=a+0.618*(b-a);
while abs(b-a)>eps
   if substi(y1,x)>substi(y2,x)
      a=y1;
      b=b;
      y1=a+0.382*(b-a);
      y2=a+0.618*(b-a);
   elseif substi(y2,x)>substi(y1,x)
      a=a;
      b=y2;
      y1=a+0.382*(b-a);
      y2=a+0.618*(b-a);
   else
      a=y1;
      b=y2;
      y1=a+0.382*(b-a);
      y2=a+0.618*(b-a);
   end
end
y=(y1+y2)/2;

suffer 发表于 2006-10-20 15:10

object1.m

%The following subfunction is on the objective function
function y=object1(v)
y=v(1)^2+v(2)^2-v(1)*v(2)-10*v(1);

suffer 发表于 2006-10-20 15:10

substi.m

%The following subfunction is on the comming
%search function of alpha
function y=substi(alpha,x)
y=feval(@object1,x-alpha*gradobject1(x));

lnljun 发表于 2008-10-26 14:07

谢谢,初学最优化。

yisuibinlan 发表于 2009-11-21 09:24

谢谢

真的很谢谢楼主你!我想问下楼主拟牛顿法的程序,你懂吗?

ChaChing 发表于 2009-11-21 10:25

回复 7楼 yisuibinlan 的帖子

新手无法看到登录资讯吗?
楼主是位高手, 但快一年没来了!

qqchun 发表于 2009-11-29 22:51

非常感谢,
页: [1]
查看完整版本: 最优化计算的牛顿法+共轭梯度法的MATLAB程序