ivechessian

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

Back to Numerical Differentiation Toolbox Contents.

Contents

Syntax

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

Description

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

H = ivechessian(f,x0,hi,hc) numerically evaluates the vector Hessian of $\mathbf{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 relative step sizes $h_{i}$ and $h_{c}$, respectively.

Input/Output Parameters

Variable Symbol Description Format
Input f multivariate, vector-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 vector Hessian of with respect to , evaluated at n×n×m
double

Note

Example

Approximate the vector Hessian of

$$\mathbf{f}(\mathbf{x})=\pmatrix{f_{1}(\mathbf{x}) \cr f_{2}(\mathbf{x})}=
\pmatrix{x_{1}^{5}x_{2}+x_{1}\sin^{3}{x_{2}} \cr x_{1}^{3}+x_{2}^{4}-
3x_{1}^{2}x_{2}^{2}}$$

at $\mathbf{x}=\mathbf{x}_{0}=(5,8)^{T}$ using the ivechessian function, and compare the result to the true result of

$$\mathbf{H}(\mathbf{f}(\mathbf{x}_{0}))=(\mathbf{H}(f_{1}
(\mathbf{x}_{0})),\mathbf{H}(f_{2}(\mathbf{x}_{0})))$$

where

$$\mathbf{H}(f_{1}(\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)}}$$

$$\mathbf{H}(f_{2}(\mathbf{x}_{0}))=\left.\pmatrix{6x_{1}^{2}-6x_{2}^{2}
& -12x_{1}x_{2} \cr -12x_{1}x_{2} & 12x_{2}^{2}-6x_{1}^{2}}\right|_
{(x_{1},x_{2})=(5,8)}=\pmatrix{6(5)-6(8^{2}) & -12(5)(8) \cr -12(5)(8) &
12(8^{2})-6(5^{2})}=\pmatrix{-354 & -480 \cr -480 & 618}$$

Approximating the Hessian,

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

   1.0e+04 *

    2.0000    0.3125
    0.3125   -0.0014


H(:,:,2) =

 -354.0000 -480.0000
 -480.0000  618.0000

Defining the true vector Hessian,

H_true = zeros(2,2,2);
H_true(:,:,1) = [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];
H_true(:,:,2) = [-354,-480;-480,618];

Calculating the errors,

error = H-H_true
error(:,:,1) =

   1.0e-05 *

    0.1036    0.0011
    0.0011    0.0049


error(:,:,2) =

   1.0e-07 *

    0.0533    0.0095
    0.0095    0.1131

See also

cvechessian | fvechessian