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



$\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}]]

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]]
  • $\begingroup$ Showing what you've tried will increase your chances (from close to zero) of getting help. Please include the code. $\endgroup$
    – JimB
    Jul 25, 2017 at 17:54
  • $\begingroup$ I added my attempt which is not working $\endgroup$
    – Ruzayqat
    Jul 25, 2017 at 18:28

1 Answer 1


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.

  • $\begingroup$ I have done the calculation with pen and paper. But me and my advisor and some papers have different answers. So we decided to stick the function in Mathematica and have it do the math. Regarding your answer, will this give me a symbolic answer ( which what I want)? $\endgroup$
    – Ruzayqat
    Jul 26, 2017 at 4:59
  • $\begingroup$ yes. Why don't you try it? $\endgroup$
    – yohbs
    Jul 26, 2017 at 13:08
  • $\begingroup$ 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 $\endgroup$
    – Ruzayqat
    Jul 26, 2017 at 13:32
  • 1
    $\begingroup$ It means run from a[i,1] until a[i,3] and return the result in a Table. $\endgroup$
    – yohbs
    Jul 26, 2017 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.