# Calculating electrostatic potential from arbitrary charge density

In electrostatics, one often desires to know the electrostatic potential generated from the outside of a charge distribution; however, I am interested in finding the electrostatic potential inside of a charge distribution.

For example, let's consider a parabolic charge distribution: $\rho(x) = x(L-x)$ Where L is the length of the distribution. Now if we wish to calculate the electrostatic potential, we would need to calculate:

$\Phi(z) = \int_0^L \frac{\rho(x)}{|z-x|} dx = \int_0^L \frac{x(L-x)}{|z-x|} dx$

In turn one could take the derivative of $\Phi(z)$ to obtain the electric field inside the distribution.

My attempt to do this in mathematica:

L = 1;
s[z_] := z (L-z)
fen[x_] := Integrate[s[z]/Abs[z - x], {z, 0, L}, PrincipalValue -> True, Assumptions :> {L > x > 0}]
V = fen[x]
El = fen'[x]
Plot[{V, El}, {x, 0, 1}]


Any ideas? Thanks!

-
This does not gives us much to work with to be honest. What have you tried? Give examples of your distribution etc. – RunnyKine Jan 16 '14 at 22:50
For any distribution, i.e. ellipse: $\rho(x) = x(1-x)$ I've tried using Principal Value to no avail also. – StarStrides Jan 16 '14 at 23:00
@StarStrides Your question is not very clear. Please edit the original post (not just comment) and rephrase it a bit: in particular show us a short example illustrating what you have tried and what went wrong. By example I mean Mathematica code with explanation. – Szabolcs Jan 16 '14 at 23:10
For arbitrary charge density in 2D, you may also want to have a look at: Poisson solver using Mathematica – Jens Jan 17 '14 at 4:26

Surely you can do it for any charge distribution as it is just evaluating integrals!

However, I have to point out a severe problem in what you are going to calculate. What I am going to say may not be an answer to your question. (I would like to make this a comment but I dont have enough reputation to do so.)

Your charge distribution is 1-dimensional, $$\rho(x) = x(L-x).$$

The problem is, you are using a 3-D green function $\frac{1}{|\vec{x}-\vec{x}'|}$ of the 3-D Laplacian $\nabla^2$ to calculate a 1-D problem. The correct result is not showing up for sure.

Instead you should use the 1-D green function $\frac{1}{2}|x-x'|$ for the potential, i.e.

$$\Phi(x) = \int_0^L\frac{1}{2}|x-x'|\rho(x') dx'$$

-
First, thank you for understanding that I did not understand @LeonidShifrin comment/answer in my original question's comment. Second, it is to my surprise that I have not covered this (or perhaps forgotten) that these Green's function's are dimension-dependent. Lastly for discussion, I am somewhat disturbed by the implication that it is only in 3D, that the force between two charged particles scales as 1/r^2. Many thanks, my simulations make much more sense now :)! – StarStrides Jan 18 '14 at 17:19