3% [H, NFV] = num_hess(func, X, NFV, h)
5% Function to compute the numerical Hessian of an arbitrary objective
9% -> func: Function handle
for which numerical Hessian
is to be
11% -> X: Sink of interest about which Hessian
is to be obtained.
12% -> NFV: Accumulator to keep track of number of function
14% -> h: Tolerance
for differentiation.
17% -> H: Numerical Hessian of function func (square symmetric
18% matrix of size n=length(X)).
19% -> NFV: Accumulator incremented by the number of function
20% evaluations which have taken place.
22% Created by: Brendan C. Wood
23% Created on: February 14, 2011
25% Copyright (c) 2011, Brendan C. Wood <b.wood@unb.ca>
28function [H] = num_hess(func, X, h)
32%
for each dimension of objective function
34 % derivative at first point (left)
37 [df1] = num_grad(func, x1, h);
39 % derivative at second point (right)
42 [df2] = num_grad(func, x2, h);
44 % differentiate between the two derivatives
45 d2f = (df2-df1) / (2*h);
47 % assign as row i of Hessian