# 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:= XVs = (p Cos[\[Theta]])/r^2
 Out= In:= XEs = -Grad[Vs, {r, \[Theta], \[CurlyPhi]}, "Spherical"]
 Out= In:= XDiv[Es, {r, \[Theta], \[CurlyPhi]}, "Spherical"] == 0
 Out= #### Compute the equivalent fields in Cartesian coordinates for p=1 and visualize the equipotential surfaces and lines of force:

 In:= XVc = TransformedField[ "Spherical" -> "Cartesian", Vs, {r, \[Theta], \[CurlyPhi]} -> {x, y, z}] /. p -> 1
 Out= In:= XEc = TransformedField["Spherical" -> "Cartesian", Es, {r, \[Theta], \[CurlyPhi]} -> {x, y, z}] /. p -> 1
 Out= In:= 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:= XelectricField = VectorPlot3D[Ec, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, VectorScale -> {Medium, .5, (3 &)}];
 In:= XShow[equipotentials, electricField]
 Out= 