# Electric Potential and Field of a Dipole

Mathematica 9 can not only compute in different coordinate systems but also transform between them. In this example, Mathematica computes an electric field from a potential in spherical coordinates, then transfroms to Cartesian coordinates to create a visualization.

#### Compute the electric field of a dipole from its potential and verify that it is a vacuum solution by computing the divergence:

 In[1]:= XVs = (p Cos[\[Theta]])/r^2
 Out[1]=
 In[2]:= XEs = -Grad[Vs, {r, \[Theta], \[CurlyPhi]}, "Spherical"]
 Out[2]=
 In[3]:= XDiv[Es, {r, \[Theta], \[CurlyPhi]}, "Spherical"] == 0
 Out[3]=

#### Compute the equivalent fields in Cartesian coordinates for p=1 and visualize the equipotential surfaces and lines of force:

 In[4]:= XVc = TransformedField[ "Spherical" -> "Cartesian", Vs, {r, \[Theta], \[CurlyPhi]} -> {x, y, z}] /. p -> 1
 Out[4]=
 In[5]:= XEc = TransformedField["Spherical" -> "Cartesian", Es, {r, \[Theta], \[CurlyPhi]} -> {x, y, z}] /. p -> 1
 Out[5]=
 In[6]:= Xequipotentials = ContourPlot3D[Vc, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, ContourStyle -> Table[{Opacity[.5], Hue[i/10]}, {i, 7}], Contours -> {-50, -5, -1, 0, 1, 5, 50}, Mesh -> None];
 In[7]:= XelectricField = VectorPlot3D[Ec, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, VectorScale -> {Medium, .5, (3 &)}];
 In[8]:= XShow[equipotentials, electricField]
 Out[8]=