Message Boards Message Boards

3 Replies
3 Total Likes
View groups...
Share this post:

Hessian matrix and gradient vector of functions

Posted 10 years ago
Hi all, I am writing to inquire about the Hessian matrix and the gradient vector of some functions, this because I have left several exercises functions of two variables and three variables, to find the Hessian matrix and the gradient vector, there is some way to make these calculations in Mathematica?
POSTED BY: Luis Ledesma
3 Replies

You can do this using D[]. Given a function with (say) arguments x and y you can write:

D[f[x,y], {{x,y},2}]

You can use Grad[] twice, of course, but D[] will get you there directly.

Some background info here:

On that page, they present an implementation of a Hessian operator:

HessianH[f_, x_] := D[f, {x,2}]

You'd call it like this:

HessianH[f[x,y], {x,y}]

If you don't want to have to repeat the argument list, you could do something like:

H[f_, x_]:= HessianH[Apply[f, x], x]

So now you can say:

H[f, {x,y}]

As of v12, you can access a pre-defined version of this function as follows:

ResourceFunction["HessianMatrix"][f[x,y], {x,y}]

which emits a matrix in the normal way. More info here:

POSTED BY: Matthew Heaney
Posted 10 years ago
Thanks for helping David, I consulted the links that you have shown me and I found everything I needed. They are very useful for the job I'm doing,. Thanks again
POSTED BY: Luis Ledesma
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract