• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

最速下降法--MATLAB程序

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

function x = fxsteep(f,e,a,b)
x1 = a;
x2 = b;
Q = fxhesson(f,x1,x2);
x0 = [x1,x2]';
temp = [x0];
fx1 = diff(f,'x1');
fx2 = diff(f,'x2');
g = [fx1,fx2]';
g1 = subs(g);
d = - g1;
while (abs(norm(g1))> e)
lamda = (-d)'*d/((-d)'*Q*d);
x0 = x0 - lamda *g1;
temp = [temp;x0];
a = [1,0] * x0;
b = [0,1] * x0;
x1 = a;
x2 = b;
g1 = subs(g);
d = - g1;
end
x = temp;
end

 

function Q = fxhesson(f,a,b)
x1 = a;
x2 = b;
fx1 = diff(f,1,'x1');
fx2 = diff(f,1,'x2');
fx1x1 = diff(fx1,1,'x1');
fx1x2 = diff(fx1,1,'x2');
fx2x2 = diff(fx2,1,'x2');
fx2x1 = diff(fx2,1,'x1');
fx1x1 = subs(fx1x1);
fx1x2 = subs(fx1x2);
fx2x1 = subs(fx2x1);
fx2x2 = subs(fx2x2);
Q = [fx1x1,fx1x2;fx2x1,fx2x2];

end

 

syms x1 x2;
X=[x1,x2];
fx=X(1)^2+4*X(2)^2;
z=fxsteep(fx,0.0001,1,1)

 

 

ans

1
1
48/65
-3/65
36/325
36/325
1728/21125
-108/21125
1296/105625
1296/105625
62208/6865625
-3888/6865625
46656/34328125
46656/34328125
2239488/2231328125
-139968/2231328125
1679616/11156640625
1679616/11156640625
80621568/725181640625
-5038848/725181640625
60466176/3625908203125
60466176/3625908203125
2902376448/235684033203125
-181398528/235684033203125

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap