7
$\begingroup$

I have a multidimensional integration of the form:

  somefunc[t] = NIntegrate[ otherfunc[x, y, z, t ],
  {z, z1[t], z2[t]}, {y, y1[t, z], y2[t, z]}, {x, x1[t, z, y], x2[t, z, y]}];

This needs to be evaluated only when $z2 > z1$, $y2 > y1$ and $x2 > x1$. However mathematica still evaluates the integrand backwards even if $y2 < y1$. My question is how to tell NIntegrate to simply give 0 in such cases and move on the next integration step. I tried to modify the upper integration boundary as follows:

 y2p[t, z] = Max[y1[t, z], y2[t, z]]

But this is not accepted by Mathematica as an integration boundary. How can I fix this?

$\endgroup$
2
  • 3
    $\begingroup$ Please post your complete and valid code. $\endgroup$
    – Mr.Wizard
    Mar 6, 2012 at 10:10
  • $\begingroup$ Are you missing a pattern from the LHS? Looks like somefunc[t] = should be somefunc[t_] :=. It also looks like most answers have copied this problem without noticing it. $\endgroup$
    – Szabolcs
    Mar 13, 2012 at 5:21

4 Answers 4

9
$\begingroup$

A better option than using Boole would be to use Piecewise. Using that you can define a function that returns 0 when your conditions aren't met and otherfunc otherwise.

So, define a function otherfunc2 and integrate that:

otherfunc2[x_, y_, z_, t_] := 
 Piecewise[
  {
   {otherfunc[x, y, z, t],
    z1[t] <=z<= z2[t] && y1[t, z] <=y<= y2[t, z] && x1[t, z, y] <=x<= x2[t, z, y]},
   {0, True}
   }
  ] 
$\endgroup$
3
$\begingroup$

Maybe you can try

   somefunc[t] = NIntegrate[ 
   Boole[z1[t] <= z <= z2[t]
   && y1[t, z] <= y <= y2[t, z] 
   && x1[t, z, y] <= x <= x2[t, z, y]]
   otherfunc[x, y, z, t ],
   {z, z0, z1},{y, y0, y1}, {x, x0, x1}];

where the integration limits are appropriate constants.

$\endgroup$
3
$\begingroup$

The integral is well defined whether y1 > y2, y1 < y2, or one or both of y1 and y2 is complex (so that < and > have no meaning). That's why NIntegrate proceeds with integration in any of these cases.

Therefore if you want these cases to return a special value, such as 0, you should do it manually with something like this:

somefunc[t] := If[z1[t] < z2[t] && ..., NIntegrate[...], 0];

(Definitely use := instead of =.)

$\endgroup$
2
$\begingroup$

Can't you do something like

somefunc[t] = NIntegrate[ otherfunc[x, y, z, t ],
  {z, z1[t], Max[z1[t], z2[t]]}, {y, y1[t, z], Max[y1[t, z], y2[t, z]]}, 
  {x, x1[t, z, y], Max[x1[t, z, y], x2[t, z, y]]}];
$\endgroup$

Your Answer

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

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