# Defining a two variables function by Hessian Matrix

I need to define a function h by the Hessian matrix:

f[x_, y_] := x^3 + y^2
h[x_, y_] := D[f[x, y], {{x, y}, 2}]


and evaluating it on a point, e.g. (0,0). But I obtained the following error:

General: 0 is not a valid variable.


Someone knows what should I do?

• This is one of the rare occasions where I would suggest to use Set instead of SetDelayed. Try h[x_, y_] = D[f[x, y], {{x, y}, 2}]. It should work provided that both x and y have no values assigned to them. Feb 23 '19 at 15:00
• Variant of @HenrikSchumacher suggestion is h[x_, y_] := Evaluate @ D[f[x, y], {{x, y}, 2}] Feb 23 '19 at 16:49

f[x_, y_] := x^3 + y^2

h[x1_, y1_] := D[f[x, y], {{x, y}, 2}] /. {x -> x1, y -> y1}

h[0, 0]


{{0, 0}, {0, 2}}

• Using h[x1_, y1_] = Block[{x, y}, D[f[x, y], {{x, y}, 2}] /. {x -> x1, y -> y1}] provides robustness towards potential values for x and y as well as performance (since the symbolical computation for the derivatives has to be performed only once). Feb 23 '19 at 15:10
• @HenrikSchumacher Thx I got it now
– zhk
Feb 24 '19 at 3:32