# hessp, hesscplx¶

## Purpose¶

Computes the matrix of second partial derivatives (Hessian matrix) of a function defined as a procedure. hesscplx() allows for complex arguments.

## Format¶

h = hessp(&f, x0)
Parameters
• &f (function pointer) – pointer to a single-valued function $$f(x)$$, defined as a procedure, taking a single Kx1 vector argument (f: $$Kx1 → 1x1$$); $$f(x)$$ may be defined in terms of global arguments in addition to x.

• x0 (Kx1 vector) – the point at which the Hessian of $$f(x)$$ is to be computed

Returns

h (KxK matrix) – Second derivatives of f with respect to x at x0; this matrix will be symmetric.

## Examples¶

// X matrix
x = { 1, 2, 3 };

proc g(b);
retp( exp(x'b));
endp;

// Parameter startvalues
b0 = { 3, 2, 1 };

// Compute Hessian
h = hessp(&g, b0);


The resulting matrix of second partial derivatives of $$g(b)$$ evaluated at $$b = b0$$ is:

     22026.865  44053.686  66080.596
h =  44053.686  88107.753 132161.059
66080.596 132161.059 198240.695


## Remarks¶

This procedure requires $$K*(K+1)/2$$ function evaluations. Thus if K is large, it may take a long time to compute the Hessian matrix.

No more than 3-4 digit accuracy should be expected from this function, though it is possible for greater accuracy to be achieved with some functions.

It is important that the function be properly scaled, in order to obtain greatest possible accuracy. Specifically, scale it so that the first derivatives are approximately the same size. If these derivatives differ by more than a factor of 100 or so, the results can be meaningless.

hessp.src