fhessian
Hessian of a multivariate, scalar-valued function using the forward difference approximation.
Back to Numerical Differentiation Toolbox Contents.
Contents
Syntax
H = fhessian(f,x0) H = fhessian(f,x0,h)
Description
H = fhessian(f,x0) numerically evaluates the Hessian of with respect to at using the forward difference approximation with a default relative step size of , where is the machine zero.
H = fhessian(f,x0,h) numerically evaluates the Hessian of with respect to at using the forward difference approximation with a user-specified relative step size .
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 ) | 1×1 double |
||
Output | H | Hessian of with respect to , evaluated at | n×n double |
Note
- This function requires evaluations of .
Example
Approximate the Hessian of at using the fhessian function, and compare the result to the true result of
Approximating the Hessian,
f = @(x) x(1)^5*x(2)+x(1)*sin(x(2))^3; x0 = [5;8]; H = fhessian(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 = 0.4348 0.0462 0.0462 0.0020