I have a question which I think should be pretty simple. I have written a subroutine in Fortran
which will compute the Gradient at a point of the form
subroutine get_gradient(xyz, Grad)
where xyz
is a 3x1
array and Grad
is also a 3x1
array. The gradient method is a fourth order accurate method where the step is chosen inside the algorithm. Based on this, is there a simple way to use it to then turn around and generate the Hessian at xyz?
for example something like
for i = 1,3
for j = 1,3
txyz = xyz
xyz(i) = xyz(i) + h
xyz(j) = xyz(j) + h
call get_gradient(xyz, Grad)
Hess(i,:) = Hess(i,:) + Grad
Hess(:,j) = Hess(:,j) + Grad
end
end
I know the previous loop will not give the Hessian, but the idea is there - use the gradient method to construct the Hessian. Is there a simple algorithm which will do this?