# Gradient and Hessian of the Coulomb/Electrostatic Energy

1. Feb 15, 2016

### decerto

I have a function

$$\displaystyle V(x)=\frac{1}{2}\sum_i \sum_{j \neq i} q_i q_j \frac{1}{\left|r_i - r_j\right|}$$ where $r_i=\sqrt{x_i^2+y_i^2+z_i^2}$ which is the coulomb potential energy of a system of charges.

I need to calculate $\frac{\partial V}{\partial x_k}$ and $\frac{\partial^2 V}{\partial x_k \partial x_l}$ for an optimization routine.

I guess I want to treat the set $(x_i , y_i, z_i)$ where i runs from 1 to N as independent variables $(x_j)$ where j runs from 1 to 3N (the direct sum of the position vectors).

Would $r_i = \sqrt{x_{3i-2}+x_{3i-1}+x_{3i}}$ then?

I ask because but I am not sure how to calculate the $\frac{\partial r_i}{\partial x_k}$ term

I was also thinking maybe I can just calculate $\frac{\partial r_i}{\partial x_k}, \frac{\partial r_i}{\partial y_k}, \frac{\partial r_i}{\partial z_k}$ separately and then just relabel them as independent variables but I am not sure if this will work.

Any help would be appreciated

Last edited by a moderator: Feb 15, 2016
2. Feb 15, 2016

### BvU

Hi,

$r_i$ is not $\sqrt{x_i^2+y_i^2+z_i^2}$ !
$r_i$ is simply a vector $\vec r_i = (x_i, y_i,z_i)$ !
You need $| \vec r_i - \vec r_j |$ which is the square root of $(\vec r_i - \vec r_j) \cdot (\vec r_i - \vec r_j)$

In your notation (somewhat awkward) this would be $$| \vec r_i - \vec r_j | = \sqrt{ ( x_{3i-2} - x_{3j-2} )^2 + ( x_{3i-1} - x_{3j-1} )^2 + ( x_{3i} - x_{3j} )^2 }$$

3. Feb 15, 2016

### decerto

Thanks for that correction, bit of an oversight!

How would you suggest I calculate the gradient and the hessian analytically without that notation?

4. Feb 15, 2016

### BvU

Your $V$ looks an awful lot like the $\ \ W\quad (1.51)\ \$ in my 1974 Jackson 2nd edition, except that $W$ is a scalar and you write $V(x)$. What does this $x$ stand for ? And how do you intend to optimize if $V$ diverges when $\vec r_i \rightarrow \vec r_j$ ? Are there any boundary conditions ? In short: could you tell us a little more of your plans ?

5. Feb 16, 2016

### decerto

Sorry V is the coulomb potential for a system of charges each with position $r_i=(x_i, y_i, z_i)$, it is a scalar function as you say of these positions. I want to create a gradient $\frac{\partial V}{\partial x_k}$ and a hessian $\frac{\partial^2 V}{\partial x_k \partial x_l}$ where the coordinates $x_k$ are the direct sum of the $(x_i, y_i, z_i)$

So for a system of two charges I would have $r_1=(x_1, y_1, z_1) \ , \ r_2=(x_2, y_2, z_2)$ so $\textbf{x}=(x_1, y_1, z_1, x_2, y_2, z_2)$ and my gradient would look like $(\frac{\partial V}{\partial x_1}, \frac{\partial V}{\partial y_1}, \frac{\partial V}{\partial z_1}, \frac{\partial V}{\partial x_2}, \frac{\partial V}{\partial y_2}, \frac{\partial V}{\partial z_2})$

I originally thought it would be a good idea to rewrite $\textbf{x}=(x_1, y_1, z_1, x_2, y_2, z_2)$ as $(x_1, x_2, x_3, x_4, x_5, z_6)$ using the coordinate transformations $x_i \to x_{3i-2}, \ y_i \to x_{3i-1}, \ z_i \to x_{3i}$ but as you said the notation is clunky.