声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 6853|回复: 8

[共享资源] 最优化计算的牛顿法+共轭梯度法的MATLAB程序

[复制链接]
发表于 2006-10-20 15:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
共包含五个 m文件

main.m

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

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

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

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

  12. while m<=3
  13.    while norm(gradobject1(x))>eps
  14.      grad=gradobject1(x);
  15.      alpha=goldsplictobj(x);
  16.      x=x-alpha*grad;
  17.      iterstep(m+1,:)=x;
  18.      m=m+1;
  19.   end
  20. end

  21. while norm(gradobject1(x))>eps
  22.     x1=iterstep(m-1,:);
  23.     x2=iterstep(m,:);
  24.     grad1=gradobject1(x1);
  25.     grad2=gradobject1(x2);
  26.     beta=(norm(gradobject1(x2))/norm(gradobject1(x1)))^2;
  27.     S=-grad2-beta*grad1;
  28.     x2=x2-alpha*S;
  29.     x=x2;
  30.     iterstep(m+1,:)=x;
  31.     m=m+1;
  32. end


  33. step=max(size(iterstep))-1
  34. x
  35. iterstep
  36. plot(iterstep(:,1),iterstep(:,2));
  37. %Draw the search trajectory
复制代码

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

评分

1

查看全部评分

回复
分享到:

使用道具 举报

 楼主| 发表于 2006-10-20 15:08 | 显示全部楼层
gradobject1.m

  1. %The following subfunction is on the gradient of
  2. %the objective function
  3. function y=gradobject1(v)
  4. y(1)=2*v(1)-v(2)-10;
  5. y(2)=2*v(2)-v(1)-4;
复制代码
 楼主| 发表于 2006-10-20 15:09 | 显示全部楼层
goldsplictobj.m

  1. %The following subfunction is on the goldspliction
  2. %search of the substi function
  3. function y=goldsplictobj(x)
  4. a=0;
  5. b=10;
  6. eps=0.01;
  7. y1=a+0.382*(b-a);
  8. y2=a+0.618*(b-a);
  9. while abs(b-a)>eps
  10.    if substi(y1,x)>substi(y2,x)
  11.       a=y1;
  12.       b=b;
  13.       y1=a+0.382*(b-a);
  14.       y2=a+0.618*(b-a);
  15.    elseif substi(y2,x)>substi(y1,x)
  16.       a=a;
  17.       b=y2;
  18.       y1=a+0.382*(b-a);
  19.       y2=a+0.618*(b-a);
  20.    else
  21.       a=y1;
  22.       b=y2;
  23.       y1=a+0.382*(b-a);
  24.       y2=a+0.618*(b-a);
  25.    end
  26. end
  27. y=(y1+y2)/2;
复制代码
 楼主| 发表于 2006-10-20 15:10 | 显示全部楼层
object1.m

  1. %The following subfunction is on the objective function
  2. function y=object1(v)
  3. y=v(1)^2+v(2)^2-v(1)*v(2)-10*v(1);
复制代码
 楼主| 发表于 2006-10-20 15:10 | 显示全部楼层
substi.m

  1. %The following subfunction is on the comming
  2. %search function of alpha
  3. function y=substi(alpha,x)
  4. y=feval(@object1,x-alpha*gradobject1(x));
复制代码
发表于 2008-10-26 14:07 | 显示全部楼层
谢谢,初学最优化。
发表于 2009-11-21 09:24 | 显示全部楼层

谢谢

真的很谢谢楼主你!我想问下楼主拟牛顿法的程序,你懂吗?
发表于 2009-11-21 10:25 | 显示全部楼层

回复 7楼 yisuibinlan 的帖子

新手无法看到登录资讯吗?
楼主是位高手, 但快一年没来了!
发表于 2009-11-29 22:51 | 显示全部楼层
非常感谢,
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 04:23 , Processed in 0.056852 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表