hessMT

Purpose

Computes numerical Hessian.

Format

h = hessMT(&fct, par1, data1)
Parameters:
  • &fct (scalar) – pointer to procedure returning either Nx1 vector or 1x1 scalar.

  • par1 (struct) – an instance of structure of type PV containing parameter vector at which Hessian is to be evaluated

  • data1 (struct) – structure of type DS containing any data needed by fct

Returns:

h (KxK matrix) – Hessian.

Examples

// Define a PV structure
struct PV p1;

// Create p1 PV structure
p1 = pvCreate;

// Fill PV structure
p1 = pvPack(p1, 0.1|0.2, "P");

// Create data matrix
x = seqa(1, 1, 15);

// Write procedure for computing Hessian
proc fct(struct PV p0, x);
   local p, y;

   // Unpack PV structure to get parameters
   p = pvUnpack(p0, "P");

   // Compute the hessian
   y = p[1] * exp( -p[2] * x);

   retp(y);
endp;

// Find Hessian
h = hessMT(&fct, p1, x);

Remarks

par1 must be created using the pvPack() procedures.

Source

hessmt.src