Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: nummath
See also: nmgraddiff nmgraditer nmjacobian

Quantlet: nmhessian
Description: computes the hessian matrix of a function func at a point x0 using the difference with a step h: d_(xy) f(x,y) = [f(x+h,y+h) - f(x+h,y-h) - f(x-h,y+h) + f(x-h,y-h)] / (4*h^2)

Reference(s):

Usage: hess = nmhessian(func, x0{, h, arraycap})
Input:
func string, name of the function whose gradient is to be computed. The function should have just one parameter x, which is a n x k matrix (k >= 1) x = (x1,x2,...,xk); xi (n x 1 vector; i=1..k) represents points at which the function should be evaluated. As a result, the function should return k real numbers in the form of a 1 x k vector.
x0 n x 1 vector representing the point at which the hessian is to be computed
h optional n x 1 vector or scalar (in the latter case, h <- h * matrix(n) will be used); vector of stepsizes for partial derivatives; default value is 0.0001
arraycap optional scalar, indicates whether function func is capable to deal with 3-dimensional arrays on input (arraycap = 1, default) or not (arraycap = 0)
Output:
hess n x n matrix, contains the computed hessian

Note:

Example:
library("nummath")
;
; definition of function f(x),
; f(x) = 1 - x1^3 + x1*x2^2 + 3*x1*x3 - x2*x3^4
;
proc(r)=f(x)
  r=1-x[1,]^3+x[1,].*x[2,]^2+3*x[1,].*x[3,]-x[2,].*x[3,]^4
endp
;
hess = nmhessian("f",#(1,1,1))
hess

Result:
Contents of hess
[1,]       -6        2        3
[2,]        2        2       -4
[3,]        3       -4      -12
Example:
library("nummath")
proc(r)=f(x)
  r=cos(x[1,]).*sin(x[2,])
endp
;
hess = nmhessian("f",#(pi/4,-pi/4))
hess

Result:
Contents of hess
[1,]      0.5     -0.5
[2,]     -0.5      0.5
Example:
library("nummath")
hess = nmhessian("sin",pi/2)
hess

Result:
Contents of hess
[1,]       -1



Author: L. Cizkova, 20010625 license MD*Tech
(C) MD*TECH Method and Data Technologies, 05.02.2006