Consider the function f[x,y,z,...]*UnitStep[g1[x,y,z,...]]*UnitStep[g2[x,y,z]].

the variables x,y,z… are defined into the ranges $\{x_{1},x_{2}\},\{y_{1},y_{2}\},...$, while UnitStep functions cut off the domains where the function f is real.

I need to integrate it over all variables. If I use simple code


then the result is zero. The reason is that on most of the domain the function f[x,y,z,...]*UnitStep[g1[x,y,z,...]]*UnitStep[g2[x,y,z]] is identically zero due to UnitSteps, and Monte-Carlo method obviously has problems with giving correct value.

Is there a method of evaluation of the integral only in regions defined by UnitStep functions?

  • 2
    $\begingroup$ well, don't use Monte Carlo. $\endgroup$ Oct 6, 2018 at 0:05
  • 1
    $\begingroup$ Can Reduce[UnitStep[g1[x,y,z,...]]*UnitStep[g2[x,y,z]==1,{x,y,z,...}] give you a sufficiently simple set of bounds for x,y that you can then integrate over that domain? Without the code it is difficult to give any more precise answer $\endgroup$
    – Bill
    Oct 6, 2018 at 0:16
  • $\begingroup$ @AccidentalFourierTransform : any other method does not evaluate the integral. $\endgroup$ Oct 6, 2018 at 8:09
  • $\begingroup$ @Bill : thank you. Do you know how to use the results of Reduce as the integration region? $\endgroup$ Oct 6, 2018 at 8:33
  • $\begingroup$ @Bill : thank you. Do you know how to use the results of Reduce as the integration region without explicit inserting (there is a lot of conditions and it is complicated to insert them)? $\endgroup$ Oct 6, 2018 at 8:40

2 Answers 2


The following is one approach that might work on your problem. You could replace the UnitStep functions with regions. Mathematica might be able to deal with the integral more effectively.

ℛ = ImplicitRegion[x^2 + y^2 < z^2, {{x, 0, 1}, {y, 0, 1}, {z, 0, 1}}];
NIntegrate[Exp[x]/(1 + y + z), {x, y, z} ∈ ℛ]
(* 0.182439 *)
  • 1
    $\begingroup$ He can just use non-Monte-Carlo methods in his original integral computation specification. $\endgroup$ Oct 6, 2018 at 14:48
  • $\begingroup$ @AntonAntonov : another methods don't work, probably because of very large time of determination of the region. $\endgroup$ Oct 6, 2018 at 15:16

Alternatively, if you use a non-Monte-Carlo method you get the result quickly without messages.

In[971]:= Block[{xmax = 100, ymax = 100},
 NIntegrate[UnitStep[9 - x^2 - y^2], {x, 0, xmax}, {y, 0, ymax}]

Out[971]= 7.06858

(Using the integral in the question you linked as "Monte-Carlo having problems".)


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.