This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
OM/Claudio_Maggioni_midterm/dogleg.m
2021-05-03 16:32:30 +02:00

20 lines
498 B
Matlab

function pk = dogleg(B, g, deltak)
pnewton = - (B \ g);
if norm(pnewton, 2) <= deltak
pk = pnewton;
else
pu = - dot(g, g) / (g' * B * g) * g;
if norm(pu, 2) > deltak
pk = cauchy(B, g, deltak);
else
syms taux
eqn = norm(pu + taux * (pnewton - pu))^2 == deltak^2;
tau = solve(eqn, taux);
tau = double(max(tau));
pk = pu + tau * (pnewton - pu);
end
end
end