0

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]]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Ruzayqat
  • 109
  • 3

1 Answers1

3

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.

yohbs
  • 7,046
  • 3
  • 29
  • 60
  • 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)? – Ruzayqat Jul 26 '17 at 04:59
  • yes. Why don't you try it? – yohbs Jul 26 '17 at 13:08
  • 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 – Ruzayqat Jul 26 '17 at 13:32
  • 1
    It means run from a[i,1] until a[i,3] and return the result in a Table. – yohbs Jul 26 '17 at 13:36