ihessian

Hessian of a multivariate, scalar-valued function using the complex-step and central difference approximations.

Back to Numerical Differentiation Toolbox Contents.

Contents

Syntax

H = ihessian(f,x0)
H = ihessian(f,x0,hi,hc)

Description

H = ihessian(f,x0) numerically evaluates the Hessian of $f$ with respect to $\mathbf{x}$ at $\mathbf{x}=\mathbf{x}_{0}$ using a hybrid of complex-step and central difference approximations with default step sizes of $h_{i}=10^{-200}$ (an absolute step size) and $h_{c}=\varepsilon^{1/3}$ (a relative step size), respectively, where $\varepsilon$ is the machine zero.

H = ihessian(f,x0,hi,hc) numerically evaluates the Hessian of $f$ with respect to $\mathbf{x}$ at $\mathbf{x}=\mathbf{x}_{0}$ using a hybrid of complex-step and central difference approximations with user-specified step sizes $h_{i}$ and $h_{c}$, respectively.

Input/Output Parameters

Variable Symbol Description Format
Input f multivariate, scalar-valued function () 1×1
function_handle
x0 evaluation point n×1
double
hi (OPTIONAL) step size for complex-step approximation (defaults to ) 1×1
double
hc (OPTIONAL) relative step size for central difference approximation (defaults to ) 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 ihessian 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 = ihessian(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-05 *

    0.1036    0.0011
    0.0011    0.0049

See also

chessian | fhessian