Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (35 sloc) 1.14 KB
function [lambda, n] = GaussNewton(f, xi, y, lambda0, tol, nmax, pmax)
syms a b;
currentLambda = lambda0';
g = y - f(xi);
dg = jacobian(g, [a b]);
dg = matlabFunction(dg, 'vars', [a b]);
g = matlabFunction(g, 'vars', [a b]);
a = [];
b = [];
n = 0;
while n < nmax
lambda = currentLambda;
[currentLambda, sigma, p] = computeNext(currentLambda, dg, g, pmax);
n = n + 1;
if norm(sigma/2.^p, 2) < tol
lambda = currentLambda;
break;
end
end
function [lambda, sigma, p] = computeNext(currentLambda, dg, g, pmax)
dgCurrent = dg(currentLambda(1), currentLambda(2));
gCurrent = g(currentLambda(1), currentLambda(2));
dgCurrentTdgCurrent = dgCurrent'*dgCurrent;
dgCurrentTgCurrent = -(dgCurrent'*gCurrent');
sigma = linsolve(dgCurrentTdgCurrent, dgCurrentTgCurrent);
p = 0;
while norm(currentLambda + (sigma / 2.^p), 2) >= norm(currentLambda) && p < pmax
p = p+1;
end
if p == pmax
p = 0;
end
lambda = currentLambda + (sigma/2.^p);
end
end
You can’t perform that action at this time.