symHess

Return a symbolically generated Hessian from a function handle

Syntax

hess = symHess(fun)

hess = symHess(fun,nvar)

hess = symHess(fun,nvar,isTril)

hess = symHess(fun,nvar,isTril,var)

[hess,pattern] = symHess(fun)

[hess,pattern,symhess] = symHess(fun)

Description

hess = symHess(fun) converts the function handle fun into a symbolic expression, differentiates it using the Symbolic Toolbox command Hessian, then converts it back to a function handle as hess.

hess = symHess(fun,nvar) ensures the correct number (nvar) of variables is used in the resulting Hessian. This is useful if your function does not include all indices of x.

hess = symHess(fun,nvar,isTril) specifies if the returned Hessian should be Symmetric Lower Triangular.

hess = symHess(fun,nvar,isTril,var) allows a variable other than 'x' to be parsed from the expression.

[hess,pattern] = symHess(fun) returns the Hessian sparsity pattern as a function handle.

[hess,pattern,symjac] = symHess(fun) also returns the intermediate symbolic expression of the Hessian.

Important Notes

This function uses the Matlab Symbolic Toolbox® thus you must have this installed to use this function. This is also a very basic routine thus you may wish to confirm the solution via one of the other differentiation routines provided.

The form of your function handle must be as follows:

fun = @(x) x(1) + x(2);  where the function is only a function of x, and x is indexed into the expression (no vectorized calls).

Example

>> fun = @(x) 3*x(1)^2 + 4*sin(x(2));

>> hess = symHess(fun)

hess =

@(x)[[6,0];[0,-4*sin(x(2))]]