0
$\begingroup$

The problem to solve is as follows. In a unit cube $\left(x,y,z\right) = (0,1)^2$ find a volume of a shape produced by following inequlity: $$2 x^2 + y (1 + z) + x (z-y-2)<0$$

Eventually, I need an exact result. However, my approach seems to be wrong for some reason I don't see. If I write

NIntegrate[If[2 x^2 + y (1 + z) + x (-2 - y + z) < 0, 1, 0], {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]

I get $0.205431$. On the other hand, if I solve for $z$ in the inequality, i.e.

$$z < \frac{(1-x) (2 x-y)}{x+y}$$

and treat the problem as a double integral, i.e.

NIntegrate[If[0 < ((1 - x) (2 x - y))/(x + y) < 1, ((1 - x) (2 x - y))/(x + y), 0], {x, 0, 1}, {y, 0, 1}]

I get the result $0.181523$.

Why these results are different? I would be very greatful.

$\endgroup$
2
  • $\begingroup$ How is it possible? Since the coefficient by $z$ is $(x+y)$, which is allways positive in the unit square so we can divide by it in the inequality? $\endgroup$
    – Machinato
    Nov 12, 2020 at 12:07
  • 1
    $\begingroup$ Your first sentence is very confusing! What is "unit cube $(x,y,z)=(0,1)^2$". $\endgroup$
    – yarchik
    Nov 12, 2020 at 18:58

3 Answers 3

5
$\begingroup$

Better use Boole instead of If here:

NIntegrate[Boole[2 x^2 + y (1 + z) + x (-2 - y + z) < 0], {x, 0, 1}, {y, 0,1}, {z, 0,1}]
(*0.205431*)

Beneath the inequality z< … don't forget to require 0<z<1! This gives

NIntegrate[Boole[0 < z < 1], {x, 0, 1}, {y, 0, 1}, {z,0, -(((-1 + x) (2 x - y))/(x +y))}]
 (*0.205431*)

The reduction of the second integral in your question to a double integral is unclear.

$\endgroup$
6
$\begingroup$

By using a region you can abstract the details of the integration away:

R = ImplicitRegion[2 x^2 + y (1 + z) + x (-2 - y + z) < 0,
                   {{x, 0, 1}, {y, 0, 1}, {z, 0, 1}}];

RegionMeasure[R, 3] // FullSimplify
(*    3/2 + Log[(81 Sqrt[3])/512]    *)

% // N
(*    0.205431    *)
$\endgroup$
1
$\begingroup$

If you solve $z$ by $x$ and $y$,then the integral should separate into three parts.

Reduce[2 x^2 + y (1 + z) + x (-2 - y + z) < 0 && 0 <= x <= 1 && 
  0 <= y <= 1 && 0 <= z <= 1, z]
(0 < x <= 1/
    2 && ((0 <= y < (-x + 2 x^2)/(-2 + x) && 
       0 <= z <= 1) || (y == (-x + 2 x^2)/(-2 + x) && 
       0 <= z < 1) || ((-x + 2 x^2)/(-2 + x) < y < 2 x && 
       0 <= z < (2 x - 2 x^2 - y + x y)/(x + y)))) || (1/2 < x < 1 && 
   0 <= y <= 1 && 0 <= z < (2 x - 2 x^2 - y + x y)/(x + y))

So we need to integral the three parts respectively.

{NIntegrate[(-x + 2 x^2)/(-2 + x), {x, 0, 1/2}, {z, 0, 1}], 
 NIntegrate[(2 x - 2 x^2 - y + x y)/(
  x + y), {x, 0, 1/2}, {y, (-x + 2 x^2)/(-2 + x), 2 x}], 
 NIntegrate[(2 x - 2 x^2 - y + x y)/(x + y), {x, 1/2, 1}, {y, 0, 1}]}
% // Total
{0.0239076, 0.0788078, 0.102715}
0.205431
$\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.