Matlab之Gauss-Newton法

      这一题就是已知初始点,然后求某一点到三个圆的距离的和的最小值。使用的就是大名鼎鼎的Gauss-Newton方法。这里要求雅克比行列式,由函数 jacobian可以求出。所以这就减少了许多不必要的麻烦。


代码如下:        

% using Gauss-Newton method
% initial point(0,0)
% 1、with circul point (0,1),(1,1),(0,-1)
% 2、with circul point (-1,0),(1,1),(1,-1)
% its radius is 1
% output :the sum of distance is the minist
function page_237_1
format long
syms x y
r1      = sqrt(x^2+(y-1)^2) - 1;
r2      = sqrt((x-1)^2+(y-1)^2) - 1;
r3      = sqrt(x^2+(y+1)^2) - 1;
rxk     = [r1;r2;r3];
Drx     = jacobian([r1;r2;r3]);
DrxT    = Drx';
DrxTdrx = DrxT*Drx;                 %Dr(xk)TDr(xk)
DrxTrxk = -1*DrxT*rxk;              %Dr(xk)Tr(xk)
%vk     = DrxTrxk\DrxTdrx;
DrxTdrx_= subs(DrxTdrx,{x,y},{0,0});
DrxTrxk_= subs(DrxTrxk,{x,y},{0,0});
xy      = zeros(2,1);
for k = 1:15
    v       = DrxTdrx_\DrxTrxk_;
    xy      = xy+v;      
    DrxTdrx_= subs(DrxTdrx,{x,y},{xy(1),xy(2)});
    DrxTrxk_= subs(DrxTrxk,{x,y},{xy(1),xy(2)});
end
disp('a with circular initial vector(0,0),Centers(0,1), (1,1), (0,?1)and all radii 1,the point is');
vpa(xy,6)


你可能感兴趣的:(Matlab,&&,Haskell)