声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 8041|回复: 8

[共享资源] 最速下降梯度法matlab程序

 关闭 [复制链接]
发表于 2005-8-2 10:40 | 显示全部楼层 |阅读模式

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

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

x
  1. % Steepest Descent Method
  2. % By Kshitij Deshpande
  3. clc
  4. clear all
  5. warning off
  6. prompt = {'Coeficients if X1=','Coefficients of X2=','Coefficeint of X1X2=','Initial Point='};
  7. def = {'[2 1 0]','[1 -1 0]','2','[0 0]'};
  8. a=inputdlg(prompt,'Data',1,def);
  9. a=char(a);
  10. [m,n]=size(a);
  11. x1 = eval(a(1,1:n));x2=eval(a(2,1:n));x1x2=eval(a(3,1:n));X1=eval(a(4,1:n));
  12. delf1(1) = polyval(polyder(x1),X1(1));
  13. delf1(1) = (delf1(1))+(x1x2*X1(2));
  14. delf1(2) = polyval(polyder(x2),X1(1));
  15. delf1(2) = (delf1(2))+(x1x2*X1(1));
  16. s=-delf1;
  17. %%%%%%%%%%
  18. %report
  19. srep(1,1:2)=s;
  20. %%%%%%%%%%
  21. x1new(1)=s(1)^2;x1new(2)=2*X1(1)*s(1);x1new(3) = X1(1)^2;
  22. x1new=x1new*x1(1);
  23. x1new_(2)=x1(2)*s(1);x1new_(3)=x1(2)*X1(1);
  24. x1new = x1new+x1new_;

  25. x2new(1)=s(2)^2;x2new(2)=2*X1(2)*s(2);x2new(3) = X1(2)^2;
  26. x2new=x2new*x2(1);
  27. x2new_(2)=x2(2)*s(2);x2new_(3)=x2(2)*X1(2);
  28. x2new = x2new+x2new_;
  29. x1x2new(1)=s(1)*s(2);x1x2new(2)=X1(1)*s(2)+X1(2)*s(1);x1x2new(3)=X1(1)*X1(2);
  30. x1x2new=x1x2*x1x2new;
  31. df = polyder(x1new+x2new+x1x2new);
  32. lambda(1) = roots(df);

  33. X1=X1+lambda(1)*s;
  34. Xrep(1,1:2)=X1;
  35. delf1(1) = polyval(polyder(x1),X1(1));
  36. delf1(1) = (delf1(1))+(x1x2*X1(2));
  37. delf1(2) = polyval(polyder(x2),X1(2));
  38. delf1(2) = (delf1(2))+(x1x2*X1(1));
  39. if all(X1)== 0
  40. fprintf('%d %d is the optimum point',X1(1),X1(2));
  41. end
  42. itrep(1)=1;
  43. it=2;
  44. while all(delf1)==1
  45. s=-delf1;
  46. x1new(1)=s(1)^2;x1new(2)=2*X1(1)*s(1);x1new(3) = X1(1)^2;
  47. x1new=x1new*x1(1);
  48. x1new_(2)=x1(2)*s(1);x1new_(3)=x1(2)*X1(1);
  49. x1new = x1new+x1new_;

  50. x2new(1)=s(2)^2;x2new(2)=2*X1(2)*s(2);x2new(3) = X1(2)^2;
  51. x2new=x2new*x2(1);
  52. x2new_(2)=x2(2)*s(2);x2new_(3)=x2(2)*X1(2);
  53. x2new = x2new+x2new_;
  54. x1x2new(1)=s(1)*s(2);x1x2new(2)=X1(1)*s(2)+X1(2)*s(1);x1x2new(3)=X1(1)*X1(2);
  55. x1x2new=x1x2*x1x2new;
  56. df = polyder(x1new+x2new+x1x2new);
  57. lambda(it) = roots(df);
  58. X1=X1+lambda(it)*s;
  59. delf1(1) = polyval(polyder(x1),X1(1));
  60. delf1(1) = (delf1(1))+(x1x2*X1(2));
  61. delf1(2) = polyval(polyder(x2),X1(2));
  62. delf1(2) = (delf1(2))+(x1x2*X1(1));
  63. itrep(it)=it;
  64. srep(it,1:2)=s;
  65. Xrep(it,1:2)=X1;
  66. it=it+1;
  67. end
  68. [m,n]=size(itrep);
  69. matrix=[itrep' srep(1:n,1) srep(1:n,2) Xrep(1:n,1) Xrep(1:n,2)];
  70. answer = char(num2str(X1));
  71. answer = ['The optimal point is [' answer ']'];
  72. msgbox(answer,'Solution');
  73. disp(' Press Any key to View Detailed Report............');
  74. pause
  75. echo off
  76. report steep;
  77. clc
复制代码

[ 本帖最后由 suffer 于 2006-10-9 20:37 编辑 ]
回复
分享到:

使用道具 举报

发表于 2006-5-15 22:02 | 显示全部楼层
这个是用什么语言写的?有点没看懂  土人啊~~
发表于 2006-5-16 23:05 | 显示全部楼层
<P>最速下降法我一直都没学会,看来我的水平还很差</P>
发表于 2006-8-20 10:55 | 显示全部楼层
看到程序才感到自己真应该在细读基础课本了。
发表于 2006-8-23 10:50 | 显示全部楼层
把这些常用的数学算法编程实现太让我们感谢了!盼多见到这类作品亚
发表于 2006-10-9 20:39 | 显示全部楼层
原帖由 broad 于 2006-5-15 22:02 发表
这个是用什么语言写的?有点没看懂  土人啊~~


当然是matlab版了,没看这里是matlab实例赏析吗?
发表于 2006-10-10 22:50 | 显示全部楼层
有没有共轭梯度的算法实现啊
发表于 2006-10-11 09:15 | 显示全部楼层
原帖由 freeway 于 2006-10-10 22:50 发表
有没有共轭梯度的算法实现啊


http://forum.vibunion.com/forum/viewthread.php?tid=27826

[ 本帖最后由 eight 于 2007-2-3 17:48 编辑 ]
发表于 2006-10-20 15:13 | 显示全部楼层
原帖由 freeway 于 2006-10-10 22:50 发表
有没有共轭梯度的算法实现啊


http://forum.vibunion.com/forum/viewthread.php?tid=28933

[ 本帖最后由 eight 于 2007-2-3 17:48 编辑 ]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-11-14 22:00 , Processed in 0.062109 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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