马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
function [x,minf] = minLM(f,x0,beta,u,v,var,eps)
format long;
if nargin == 6
eps = 1.0e-6;
end
S = transpose(f)*f;
k = length(f);
n = length(x0);
x0 = transpose(x0);
A = jacobian(f,var);
tol = 1;
while tol>eps
Fx = zeros(k,1);
for i=1:k
Fx(i,1) = Funval(f(i),var,x0);
end
Sx = Funval(S,var,x0);
Ax = Funval(A,var,x0);
gSx = transpose(Ax)*Fx;
Q = transpose(Ax)*Ax;
while 1
dx = -(Q+u*eye(size(Q)))\gSx;
x1 = x0 + dx;
for i=1:k
Fx1(i,1) = Funval(f(i),var,x1);
end
Sx1 = Funval(S,var,x1);
tol = norm(dx);
if tol<=eps
break;
end
if Sx1 >= Sx+beta*transpose(gSx)*dx
u = v*u;
continue;
else
u = u/v;
break;
end
end
x0 = x1;
end
x = x0;
minf = Funval(S,var,x);
format short;
|