# How to make a matrix of derivatives? [duplicate]

For example I can construct:

  row1 = D[f(x,y),x,#]&/@{x,y}
row2 = D[f(x,y),x,#]&/@{x,y}


then:

matrix = {row1,row2}


That yields a matrix like:

$$\left(\matrix{\frac{\partial^2 f}{\partial x^2} \quad\frac{\partial^2 f}{\partial x\partial y}\\ \frac{\partial^2 f}{\partial y\partial x}\quad \frac{\partial^2f}{\partial y^2}}\right)$$

Question: how to construct such matrix in a single line of code?

• Outer[Dt[f, #1, #2] &, #, #] &@{x, y} – wxffles Oct 16 '16 at 20:18
• Also D[f[x, y], {{x, y}, 2}]. – b.gates.you.know.what Oct 16 '16 at 20:29
• – Michael E2 Oct 16 '16 at 20:32

See D (search for Hessian):

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


• Ok that works, but when I do that I cannot perform matrix summation, Mathematica don't evaluate the operation (even if I use Evaluate). – Saavestro Oct 16 '16 at 20:44
• For example, for D[f[x, y], {{x, y}, 2}]+D[g[x, y], {{x, y}, 2}] – Saavestro Oct 16 '16 at 20:44
• Ok, I solved that, I was placing a //MatrixForm that was messing the evaluation, thank you for your helpful answer – Saavestro Oct 16 '16 at 21:09
• @Saavestro You can find out more about the MatrixForm problem here. -- And you're welcome! Thanks, – Michael E2 Oct 16 '16 at 21:19

I think Tuples is the missing element for you:

TraditionalForm[
Partition[D[f[x, y], Sequence @@ #] & /@ Tuples[{x, y}, 2], 2]
]


• Outer is more elegant solution. – Johu Oct 16 '16 at 20:23