6
$\begingroup$

I need to compute: $\int \int \int z dxdydz$

over the domain: $\{x^2+y^2+z^2\leqslant 16,z\geqslant 0\}$

Im trying to use spherical coords as:

$$\int_{0}^{2\pi} \int_{0}^{\frac{\pi}{2}} \int_{0}^{4} r \cos(\theta )r^2\sin(\varphi ) \;dr\,d\theta \,d\varphi $$

I try this on Mathematica:

Integrate[Integrate[Integrate[r *Cos[theta]*r^2*Sin[phi], {r, 0, 4}], {theta, 0, Pi/2}], {phi, 0, 2 Pi}]

But re result is 0. What is wrong here?

$\endgroup$
1
  • 8
    $\begingroup$ What is $\int_0^{2\pi} d\phi\,\sin(\phi)$? $\endgroup$
    – acl
    Commented Jun 28, 2014 at 2:43

6 Answers 6

14
$\begingroup$

In Version 9 currently, we can do (using the Undocumented form of Integrate):

Integrate[Boole[z >= 0] z, {x, y, z} ∈ Sphere[{0, 0, 0}, 4]]

64 Pi

Note: This is undocumented behaviour and functionality may change or behave differently in newer versions of Mathematica so use with caution e.g. as noted by Szabolcs in the comment, Sphere in V10 denotes a surface, whereas in V9 it represents a volume. So we should keep this in mind or we can get as fancy as V10 and use BallRegion (equivalent to Ball as Szabolcs did). To do this, first load the Region context

Graphics`Region`RegionInit[]

Then:

Integrate[ Boole[z >= 0] z, {x, y, z} ∈ BallRegion[{0, 0, 0}, 4]]

64 Pi

$\endgroup$
5
  • $\begingroup$ Ok, thanks, the funny thing is that if i do it by hand it gives me 0 too... $\endgroup$
    – Wyvern666
    Commented Jun 28, 2014 at 4:26
  • $\begingroup$ @Wyvern666 Just keep in mind the caveats about undocumented functionality. In v9 it's a work-in-progress, so it may break, give wrong results, etc. $\endgroup$
    – Szabolcs
    Commented Jun 28, 2014 at 4:31
  • 3
    $\begingroup$ An important note: in version 10 Sphere denotes a surface, not a volume region. So in v10 Integrate[Boole[z >= 0] z, {x, y, z} ∈ Sphere[{0, 0, 0}, 4]] is going to do a surface integral, which accidentally happens to have the same result the volume integral would for a radius of 4 (but not for other values). There might be a lot of confusion because of this accident ... you might want to mention this difference. $\endgroup$
    – Szabolcs
    Commented Jun 28, 2014 at 4:40
  • $\begingroup$ @Szabolcs. Thanks, note added. $\endgroup$
    – RunnyKine
    Commented Jun 28, 2014 at 14:14
  • $\begingroup$ @Wyvern666 that's because you mixed up the polar and azimuthal angles, so the integral you gave really does vanish (as I attempted to hint in my comment to your question). See Jens's answer for the correct form. $\endgroup$
    – acl
    Commented Jun 28, 2014 at 23:56
12
$\begingroup$

Since you explicitly asked for a way to do this integral in spherical coordinates, here is a formulation that works in all versions of Mathematica. First I define the spherical coordinates, and then I do the triple integral using the Jacobi determinant:

{x, y, z} = 
  r {Cos[ϕ] Sin[θ], Sin[ϕ] Sin[θ], Cos[θ]};

Integrate[
 z Abs[Det[D[{x, y, z}, {{r, θ, ϕ}}]]], 
   {r, 0, 4}, {θ, 0, π/2}, {ϕ, 0, 2 Pi}]

(* ==> 64 Pi *)
$\endgroup$
7
$\begingroup$

The more natural way to express this problem is

Integrate[Boole[x^2 + y^2 + z^2 <= 16] z, {x, -4, 4}, {y, -4, 4}, {z, 0, 4}]

(* ==> 64 Pi *)

This works in version 9 and earlier. In version 10 we can get fancy and do

Integrate[Boole[z >= 0] z, {x, y, z} ∈ Ball[{0, 0, 0}, 4]]

(* ==> 64 Pi *)
$\endgroup$
2
  • $\begingroup$ Is version 10 of Mathematica available already? $\endgroup$
    – Vaggelis_Z
    Commented Jun 28, 2014 at 6:48
  • $\begingroup$ @Vaggelis_Z The programming cloud is available. It's possible to try these with a free account. $\endgroup$
    – Szabolcs
    Commented Jun 28, 2014 at 13:07
7
$\begingroup$

You set up the integral incorrectly. You are mixing up $\varphi$ and $\theta$.

$\endgroup$
4
$\begingroup$

There is nothing wrong with your mathematica code. The problem is with the volume element. The volume element in spherical coordinates is $$r^2\sin(\theta ) \;dr\,d\theta \,d\varphi $$ not $$r^2\sin(\varphi ) \;dr\,d\theta \,d\varphi $$ Simply replace $$Sin[phi]$$ with $$Sin[theta]$$ in your code, and you get the answer.

Integrate[Integrate[Integrate[r *Cos[theta]*r^2*Sin[theta], {r, 0, 4}], {theta, 0, Pi/2}], {phi, 0, 2 Pi}]
$\endgroup$
1
$\begingroup$

Another method is using Cartesian coordinate:

4 Integrate[
  Integrate[
   Integrate[z, {x, 0, Sqrt[16 - y^2 - z^2]}], {y, 0, 
    Sqrt[16 - z^2]}], {z, 0, 4}]

(* 64 Pi *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.