The computation of the Hessian of the squared euclidean norm results in an interesting output:
using ForwardDiff;
f(x::Vector) = .5*norm(x, 2)^2;
x = zeros(2);
ForwardDiff.hessian(f, x)
which is
However, the codes
f(x::Vector) = .5*x[1]^2 + .5*x[2]^2;
ForwardDiff.hessian(f, x)
and
f(x::Vector) = .5*dot(x, x);
ForwardDiff.hessian(f, x)
provide the correct result. Why is that?
The computation of the Hessian of the squared euclidean norm results in an interesting output:
which is
However, the codes
and
provide the correct result. Why is that?