CODES / common / hess_fd

Hessian of f at x using finite difference

Contents

Syntax

Usage

size(x,1) must be equal to 1. Returns the (size(x,2) x size(x,2)) Hessian matrix.

Parameters

param value Description
'rel_diff' positive numeric, {1e-5} Finite difference step size.
'fx' numeric, { [ ] } Function value at x f(x) (save one function evaluation).

Example

Compute finite diffence for:

$$f(x)=3x_1^2+x_2^3+x_1x_2\quad,\quad \left.\frac{\mathrm d^2f}{\mathrm d\mathbf{x}^2}\right|_{\mathbf{x}=[2,3]}=\left[\begin{array}{cc}6 & 1\\1 & 18\end{array}\right]$$

f=@(x)3*x(:,1).^2+x(:,2).^3+x(:,1)*x(:,2);
H=CODES.common.hess_fd(f,[2 3]);

CODES.common.disp_matrix(H,{'d2fdX12','d2fdX1X2'},...
    {'d2fdX2X1','d2fdX22'})
          d2fdX2X1  d2fdX22
 d2fdX12   5.99982  1.00002
d2fdX1X2   1.00002  17.9995

See also

grad_fd

Copyright © 2015 Computational Optimal Design of Engineering Systems (CODES) Laboratory. University of Arizona.

Computational Optimal Design of
Engineering Systems