Densities in Spherical Coordinates

Spheres occur frequently in applications, and as a result, questions involving densities for spheres are commonplace.  For example, let's consider the charge density given by

rho(x,y,z) = 1000/Pi*sqrt(x^2+y^2+z^2)

Below we have distributed 1,000 "charges" in a sphere of radius 1 meter based on this density.

   [Maple Plot]

(commands used to generate figure above)

In cartesian coordinates, the total charge is given by 3 iterated integrals:

>    Q:=Int(Int(Int(1000/Pi*sqrt(x^2+y^2+z^2),z=-sqrt(1-x^2-y^2)..sqrt(1-x^2-y^2)),y=-sqrt(1-x^2)..sqrt(1-x^2)),x=-1..1);
value(%);

>   

In cartesian coordinates, Maple is unable to evaluate the integral. However, in spherical coordinates, the triple integral would instead result in

>    Q:=Int(Int(Int((1000/Pi*rho)*rho^2*sin(phi),rho=0..1),phi=0..Pi),theta=0..2*Pi);
Q:=value(%);

>   

Let's look at another example.  Let's consider a solid sphere with a uniform mass density of mu(x,y,z)  = 5 kg/(m^3) .    If we assume that each small "chunk" of a solid with mass dM  exerts a small amount of potential dU , then the inverse square field potential on an object at (0,0,3) due to the "chunk" is given by

dU = 5*dV/sqrt(x^2+y^2+(z-3)^2)

Let's convert this into spherical coordinates and then integrate to find the total potential acting on an object at (0,0,2).

To begin with, let's define dU in cartesian coordinates.

>    dU:=5*dV/sqrt(x^2+y^2+(z-3)^2);

>   

 Next, let's convert the integrand into spherical coordinates by substituting for x, y , and z :   Also, we let dV  = rho^2*sin(phi)  since the differentials will be handled by the Int  command.

>    dU:=subs(x=rho*sin(phi)*cos(theta),y=rho*sin(phi)*sin(theta),z=rho*cos(phi),dV=rho^2*sin(phi),dU);
dU:=simplify(%);

>   

Now let's integrate dU over the sphere to find the total potential U.

>    U:=Int(Int(Int(dU,rho=0..1),phi=0..Pi),theta=0..2*Pi);
U:=value(%);

>