chessian

Hessian of a multivariate, scalar-valued function using the central difference approximation.

Back to Numerical Differentiation Toolbox Contents.

Contents

Syntax

H = chessian(f,x0)
H = chessian(f,x0,h)

Description

H = chessian(f,x0) numerically evaluates the Hessian of $f$ with respect to $\mathbf{x}$ at $\mathbf{x}=\mathbf{x}_{0}$ using the central difference approximation with a default relative step size of $h=\varepsilon^{1/3}$, where $\varepsilon$ is the machine zero.

H = chessian(f,x0,h) numerically evaluates the Hessian of $f$ with respect to $\mathbf{x}$ at $\mathbf{x}=\mathbf{x}_{0}$ using the central difference approximation with a user-specified relative step size $h$.

Input/Output Parameters

Variable Symbol Description Format
Input f multivariate, scalar-valued function () 1×1
function_handle
x0 evaluation point n×1
double
h (OPTIONAL) relative step size (defaults to $h=\varepsilon^{1/3}$) 1×1
double
Output H Hessian of with respect to , evaluated at n×n
double

Note

Example

Approximate the Hessian of $f(\mathbf{x})=x_{1}^{5}x_{2}+x_{1}\sin^{3}{x_{2}}$ at $\mathbf{x}=\mathbf{x}_{0}=(5,8)^{T}$ using the chessian function, and compare the result to the true result of

$$\mathbf{H}(\mathbf{x}_{0})=\left.\pmatrix{20x_{1}^{3}x_{2} & 5x_{1}^{4}
+3\sin^{2}{x_{2}}\cos{x_{2}} \cr 5x_{1}^{4}+3\sin^{2}{x_{2}}\cos{x_{2}} &
6x_{1}\sin{x_{2}}\cos^{2}{x_{2}}-3x_{1}\sin^{3}{x_{2}}}\right|_{(x_{1},
x_{2})=(5,8)}=\pmatrix{20(5)^{3}(8) & 5(5)^{4}+3\sin^{2}{(8)}\cos{(8)}
\cr 5(5)^{4}+3\sin^{2}{(8)}\cos{(8)} & 6(5)\sin{(8)}\cos^{2}{(8)}
-3(5)\sin^{3}{(8)}}$$

Approximating the Hessian,

f = @(x) x(1)^5*x(2)+x(1)*sin(x(2))^3;
x0 = [5;8];
H = chessian(f,x0)
H =

   1.0e+04 *

    2.0000    0.3125
    0.3125   -0.0014

Calculating the error,

error = H-[20*5^3*8,5*5^4+3*sin(8)^2*cos(8);5*5^4+3*sin(8)^2*cos(8),...
    6*5*sin(8)*cos(8)^2-3*5*sin(8)^3]
error =

   1.0e-03 *

    0.0072    0.2459
    0.2459    0.1293

See also

fhessian | ihessian