Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to evaluate an Integral of a Heaviside function, but it turns out with an erroneous output(zero). Here is my integral:

Integrate[HeavisideTheta[k - Sqrt[kx^2 + ky^2 + kz^2]], 
          {kx, -Infinity, Infinity}, 
          {ky, -Infinity, Infinity}, 
          {kz, -Infinity, Infinity}, {kx, ky, kz} ∈ Reals]

The right answer should be a volume of a sphere, but it seems Mathematica doesn't know it.

share|improve this question
Define k first. – Spawn1701D May 13 '13 at 18:21
How to define k? Can you make it clear? I add Assumptions->k>0 in the integral. It returns 0. – buzhidao May 13 '13 at 19:13
up vote 3 down vote accepted

You can use :

Integrate[UnitStep[k - Sqrt[kx^2 + ky^2 + kz^2]], 
{kx, -Infinity, Infinity}, {ky, -Infinity, Infinity}, {kz, -Infinity, Infinity}, 
  Assumptions -> {k \[Element] Reals}]
(* -(4/3) k^3 \[Pi] (-1 + UnitStep[-k]) *)

Integrate[Boole[k - Sqrt[kx^2 + ky^2 + kz^2] >= 0],
{kx, -Infinity, Infinity}, {ky, -Infinity, Infinity}, {kz, -Infinity, Infinity}, 
 Assumptions -> {k \[Element] Reals}]
(* Piecewise[{{(4*k^3*Pi)/3, k >= 0}}, 0] *)
share|improve this answer
UnitStep doesn't work. It result 0 as same as Heaviside Step. I need to Integrate a lot of HeavisideStep functions, What can I do? – buzhidao May 13 '13 at 19:04
@luming Why doesn't it work ? I think it's giving the correct result; if you supplement the more stringent assumption k>0 then you get the volume of the sphere as you expect. – b.gatessucks May 13 '13 at 20:05
In version 8, both methods work even if I leave out the Assumptions. – Jens May 14 '13 at 3:36
@Jens I try the code on two differnt computers, both run mathematica7 for students on Windows7. And one of the computers running mathematica8 on linux Fedora16. All of them give the answer 0 when usingUnitStepandHevisideTheta function with or without Assumptions. – buzhidao May 14 '13 at 5:19
I can confirm that. In version 7 only the 1 dimensional case Integrate[UnitStep[k - Sqrt[kx^2]], {kx, -Infinity, Infinity}] seems to work. – b.gatessucks May 14 '13 at 5:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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