# Hessian for a function including a double summation

I am new to mathematica and I really struggling at finding the hessian for this function:

$$U=\sum_{i=1}^{N-1}\sum_{j=i+1}^{N}\varphi(r_{ij}),$$

where

$\qquad r_{ij}=\sqrt{(x_i^1-x_j^1)^2+(x_i^2-x_j^2)^2+(x_i^3-x_j^3)^2}$

$\qquad \varphi =4\epsilon_{ij} \left[\left(\frac{\sigma_{ij}}{r_{ij}}\right)^{12}-\left(\frac{\sigma_{ij}}{r_{ij}}\right)^{6}\right]$

$(x_i^1,x_i^2,x_i^3)$ are the Cartezian coordinates in $\mathbb{R}^3$ and $\epsilon_{ij}$ and $\sigma_{ij}$ are constants.

I looked at this answer, especially the second answer, but it is very complicated to follow. I don't understand the steps.

Any help is appreciated.

My try:

Format[r[i_, j_]] = Subscript[r, i, j]
Format[x[i_, m_]] = Subsuperscript[x, i, m]

r[i_, j_] = Sqrt[Sum[(x[i, m] - x[j, m])^2, {m, 1, 3}]]

Clear[U]
U =
4*eps*Sum[Sum[(sig/r[i, j])^12 - (sig/r[i, j])^6, {j, i + 1, n}], {i, 1, n - 1}]

D[D[U, x[i, m]], x[j, l]]

• Showing what you've tried will increase your chances (from close to zero) of getting help. Please include the code.
– JimB
Jul 25, 2017 at 17:54
• I added my attempt which is not working Jul 25, 2017 at 18:28

The problem is that x[i,m] and x[j,l] do not appear in U, so the derivative is 0. You should use explicit values":
Table[D[U, x[i, a], x[j, b]], {a, 3}, {b, 3}]

By the way, a tip: the calculation you're trying to do can be easily calculated with pen an paper and going through Mathematica only makes thins more difficult. To make things concrete I'd use a definite value of n (say, 5) which will make Mathematica's work easier.
• I tried and got very large answer. What does {a,3}, {b,3} mean? Is it something like $\partial^6 U/\partial x_i^3 \partial x_j^3$? a and b should be super indices that ranges from 1 to 3, and what I need is $\partial^2U/\partial x_i^3 \partial x_j^3$ for example Jul 26, 2017 at 13:32
• It means run from a[i,1] until a[i,3] and return the result in a Table. Jul 26, 2017 at 13:36