6
$\begingroup$

I have a complex and long piecewise function to integrate, so I have written a Mathematica script that cuts the whole range of integration, evaluates the integrand in each region and then integrates it.

In order to integrate the evaluated function on the right range, I set the integration on the whole original range and I use Boole to define the appropriate region.

Now, it happens that both the integrand and the region depends on other parameters, say a and b, so I should get an integral which depends on these, as in the following WORKING example

Assuming[0 < 2 a < 1, 
 Integrate[
  Exp[-t] Boole[(b < 0.5 && a < t < 2 a) || (b > 0.5 && 
       0 < t < a)], {t, 0, 1}]]

which gives

$\begin{cases} e^{-2. a} \left(e^a-1.\right) & 0.<a<0.5\land b<0.5 \\ e^{-1. a} \left(e^a-1.\right) & 0.<a<0.5\land b>0.5 \\ 0. & \text{True} \end{cases}$

However, when the range of integration becomes too complex, Mathematica stops to evaluate the integral and give me back an implicit solution. For example, consider the following code

r = (0 < b < 1/
     2 && ((0 < a < b && 
        b + a < z < 
         1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z && 
            0 < y < z - x))) || (a == b && b + a < z < 1 && 
        z - a < x < z && 0 < y < z - x) || (b < a < 1 - b && 
        b + a < z < 1 && z - b < x < z && 0 < y < z - x))) || (1/2 <= 
     b < 1 && 0 < a < 1 - b && 
    b + a < z < 
     1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z && 
        0 < y < z - x)))
int = Exp[-0.5 y1^2 y - 
    2 (y2^2 (z - b - a) + y1^2 (-z + b + x + a))] y1^2 Boole[r]
Integrate[int, {z, a, 1}, {x, a, z}, {y, 0, a}]

The last line gives me $\text{y1}^2 \int _a^1\int _a^z\int _0^a\exp \left(-2 \text{y1}^2 (a+b+x-z)+2 \text{y2}^2 (a+b-z)-0.5 y \text{y1}^2\right) \text{Boole}[...]dydxdz$

The same happens if I isolate intervals with respect to a,b , as in

r = LogicalExpand[(0 < b < 
      1/2 && ((0 < a < b && 
         b + a < z < 
          1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z &&
              0 < y < z - x))) || (a == b && b + a < z < 1 && 
         z - a < x < z && 0 < y < z - x) || (b < a < 1 - b && 
         b + a < z < 1 && z - b < x < z && 0 < y < z - x))) || (1/2 <=
       b < 1 && 0 < a < 1 - b && 
     b + a < z < 
      1 && ((z - b < x <= z - a && 0 < y < a) || (z - a < x < z && 
         0 < y < z - x)))]
s = Reduce[r[[2]], {x, y}]
int = Exp[-0.5 y1^2 y - 
    2 (y2^2 (z - b - a) + y1^2 (-z + b + x + a))] y1^2 Boole[s]
Integrate[int, {z, a, 1}, {x, a, z}, {y, 0, a}]

or if I split the Integrate function

Integrate[
 Integrate[Integrate[int, {y, 0, a}], {x, a, z}], {z, a, 1}]

Why Mathematica cannot evaluate the integral?

$\endgroup$
  • $\begingroup$ As a user, maybe we can never truely know why.. But I guess maybe when the expression gets too complex, there are criteria (maybe based on time and memory comsumptions) to determine whether go on evaluation or not. Also, multiple integrals might use their own algorithms other than repeated univariate integrals. $\endgroup$ – Silvia Jan 27 '14 at 20:09
4
$\begingroup$

It helps to tell Integrate a little about your parameters:

int = Exp[-1/2 y1^2 y - 2 (y2^2 (z - b - a) + y1^2 (-z + b + x + a))] y1^2 Boole[r];
Integrate[int, {z, a, 1}, {x, a, z}, {y, 0, a}, 
 Assumptions -> 0 < a < b < 1/2 && y1 > 0 && y2 > 0]
(*
   -(1/(6 y1^2 y2^2))
    E^(-((5 a y1^2)/2) - 2 b y1^2 - 2 (a + b) y1^2 - 
      2 y2^2) (-1 + E^((a y1^2)/2)) (E^((5 a y1^2)/2 + 2 b y1^2) + E^(
       3 a y1^2 + 2 b y1^2) + E^((7 a y1^2)/2 + 2 b y1^2) - 
       3 E^(4 a y1^2 + 2 b y1^2) + 3 E^(2 a y1^2 + 2 (a + b) y1^2) - 
       3 E^(2 b y1^2 + 2 (a + b) y1^2)) (E^(2 y2^2) - E^(2 (a + b) y2^2))
*)


int = Exp[-1/2 y1^2 y - 2 (y2^2 (z - b - a) + y1^2 (-z + b + x + a))] y1^2 Boole[s];
Integrate[int, {z, a, 1}, {x, a, z}, {y, 0, a}, 
 Assumptions -> 0 < a < b < 1/2 && y1 > 0 && y2 > 0]
(*
   (E^(-2 (a + b) y1^2 - 
     2 y2^2) (-1 + E^((a y1^2)/2))^2 (1 + 2 E^((a y1^2)/2) + 
      3 E^(a y1^2)) (E^(2 y2^2) - E^(2 (a + b) y2^2)))/(6 y1^2 y2^2)
*)

(I'm just guessing that y1 and y2 are real.)

$\endgroup$
  • $\begingroup$ Thanks for the useful suggestions. It seems to me that I have to split the conditions on the parameter a,b and put them in the assumption, while leaving in the Boole function only the logic expression with the variables of integration. $\endgroup$ – Nicola Feb 3 '14 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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