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

21 lines
498 B
Mathematica
Raw Normal View History

2021-05-03 14:32:30 +00:00
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