1
NIntegrate[
 If[x1^2 + y1^2 + z1^2 < 1 && 
   x2^2 + y2^2 + z2^2 < 1 && 
   (x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2 <1,
   (1 + Min[0, x1, x2]) *
   (1 + Min[0, y1, y2]) *
   (1 + Min[0, z1, z2])
   , 0],
   {x1, -1, 1},
   {y1, -1, 1},
   {z1, -1, 1},
   {x2, -1, 1},
   {y2, -1, 1} ,
   {z2, -1, 1},
   MinRecursion -> 9,
   MaxRecursion -> 15,
   PrecisionGoal -> 6,
   AccuracyGoal -> 5,
   Method -> {"GlobalAdaptive", 
          MaxErrorIncreases ->85000}
 ]

It gives a result of 3.16466 with slow convergence warning, the error estimate is 0.5547. The error is too big.

If I change the strategy to "LocalAdaptive", the result is 3.25953 without warning. I don't know if I can trust this result.

  • 1
    "Local Adaptive" samples more in region where the integrand changes fast. Therefore, I think you can trust this result. – Daniel Huber Sep 17 '23 at 07:56

1 Answers1

2

If you change If to Boole Mathematica evaluates NIntegrate[...,Method->"LocalAdaptive"] the integral without error message

int = NIntegrate[
   Boole[x1^2 + y1^2 + z1^2 < 1 && 
      x2^2 + y2^2 + z2^2 < 
       1 && (x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2 < 1] (1 + 
      Min[0, x1, x2])*(1 + Min[0, y1, y2])*(1 + 
      Min[0, z1, z2]) , {x1, -1, 1}, {y1, -1, 1}, {z1, -1, 
    1}, {x2, -1, 1}, {y2, -1, 1}, {z2, -1, 1}   , Method -> "LocalAdaptive"];
 (*3.26577*)

Unfortunately evaluation takes 2800seconds (Mathematica v12.2, Windows 10)

The obvious variant using sphere-region (Method->"LocalAdaptive" not allowed here)

kugel = ImplicitRegion[x^2 + y^2 + z^2 <= 1, {x, y, z}]
intk = NIntegrate[
Boole[ (x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2 <= 1] 
(1 +Min[0, x1, x2])*(1 + Min[0, y1, y2])*(1 + Min[0, z1, z2]) , 
Element[{x1, y1, z1}, kugel], Element[{x2, y2, z2}, kugel]
]

evaluates faster but shows convergence message ...NIntegrate obtained 3.29746 and 0.252064 for the integral and error\estimates

Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55
  • Good to know there is a Boole[] function, I think it's faster than If[]. But I didn't get warnings when I use "If" and "LocalAdaptive" either. I am not sure about the precision of the result. When I use "QausiMonteCarlo" for 3x10^8 points, it gives 3.26822 and 0.00064 as the error estimate. Your "LocalAdaptive" result 3.26577 is out of the range. So is my "LocalAdaptive" result 3.25953. – user1477339 Sep 17 '23 at 13:49
  • I don't know how to compare these numerical results perhaps NIntegrate error bound helps? – Ulrich Neumann Sep 18 '23 at 07:10