symHessLag
Return a symbolically generated Hessian of the Lagrangian from the objective and nonlinear constraint function handles
Syntax
hess = symHessLag(obj,nlcon)
hess = symHessLag(obj,nlcon,nvar)
hess = symHessLag(obj,nlcon,nvar,isTril)
hess = symHessLag(obj,nlcon,nvar,isTril,var)
[hess,pattern] = symHessLag(fun)
[hess,pattern,symhess] = symHessLag(fun)
Description
hess = symHess(obj,nlcon) converts the function handles obj and nlcon into symbolic expressions, differentiates them using the Symbolic Toolbox command Hessian, converts them to the Hessian of the Lagrangian then converts it back to a function handle as hess.
hess = symHess(obj,nlcon,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(obj,nlcon,nvar,isTril) specifies if the returned Hessian should be Symmetric Lower Triangular.
hess = symHess(obj,nlcon,nvar,isTril,var) allows a variable other than 'x' to be parsed from the expression.
[hess,pattern] = symHess(obj,nlcon) returns the Hessian sparsity pattern as a function handle.
[hess,pattern,symjac] = symHess(obj,nlcon) 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 handles must be as follows:
obj = @(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
>> obj = @(x) x(1)*x(4)*(x(1) + x(2) + x(3)) + x(3);
>> nlcon = @(x) [ x(1)*x(2)*x(3)*x(4);
x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2 ];
>> hess = symHessLag(obj,nlcon)
hess =
@(x,sigma,lambda)[[2*lambda(2)+2*sigma*x(4),0,0,0];[sigma*x(4).....
Copyright © 2011-2013 Jonathan Currie (I2C2)