I have the pseudocode function f(x,y)=x+y
, and I want to find the symbolic Hessian matrix (2x2 second order partial derivative matrix) using Matlab. How do I do this?
Here is my first attempt, which is very far from the correct syntax:
syms x y
f=x+y
f_jacobian = jacobian(f, [x, y])
f_hessian = jacobian(f_jacobian,[x,y])
You can use hessian
. From the example:
syms x y z
f = x*y + 2*z*x;
hessian(f,[x,y,z])
ans =
[ 0, 1, 2]
[ 1, 0, 0]
[ 2, 0, 0]