码迷,mamicode.com
首页 > 其他好文 > 详细

最速下降法--MATLAB程序

时间:2014-11-21 23:05:43      阅读:851      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   sp   on   2014   log   cti   bs   

bubuko.com,布布扣

bubuko.com,布布扣

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

 

最速下降法--MATLAB程序

标签:blog   http   io   sp   on   2014   log   cti   bs   

原文地址:http://www.cnblogs.com/Kermit-Li/p/4114372.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!