1
$\begingroup$

I need to be able to calculate an integral with this implicit region:

ImplicitRegion[
  16 π^2 - 
    Sqrt[32 π^2 + Abs[Cos[θ1] r1]^2 + 
      Abs[r1 Sin[θ1]]^2] Sqrt[
     Abs[Cos[θ1] r1]^2 + 
      Abs[Cos[φ1] r1 Sin[θ1]]^2 + 
      Abs[r1 Sin[φ1] Sin[θ1]]^2] + Cos[θ1]^2 r1^2 +
     Cos[φ1] r1^2 Sin[θ1]^2 <= 0.5 && 
  16 π^2 - 
    Sqrt[32 π^2 + Abs[Cos[θ1] r1]^2 + 
      Abs[r1 Sin[θ1]]^2] Sqrt[
     Abs[Cos[θ1] r1]^2 + 
      Abs[Cos[φ1] r1 Sin[θ1]]^2 + 
      Abs[r1 Sin[φ1] Sin[θ1]]^2] + Cos[θ1]^2 r1^2 +
     Cos[φ1] r1^2 Sin[θ1]^2 >= -0.5 && 
  16 π^2 - 
    Abs[r2] Sqrt[32 π^2 + Abs[r2]^2 + 
        Abs[r1 Sin[φ1] Sin[θ1]]^2 + 
        Abs[r1 Sin[θ1] - Cos[φ1] r1 Sin[θ1]]^2] + 
    r2^2 <= 0.5 && 
  16 π^2 - 
    Abs[r2] Sqrt[32 π^2 + Abs[r2]^2 + 
        Abs[r1 Sin[φ1] Sin[θ1]]^2 + 
        Abs[r1 Sin[θ1] - Cos[φ1] r1 Sin[θ1]]^2] + 
    r2^2 >= -0.5 && 160 <= r1 <= 300 && 160 <= r2 <= 300 && 
  0 <= φ1 <= 2 π && 0 <= θ1 <= 2 π, 
  {r1, r2, φ1, θ1}]

I'm sorry if it's difficult to visualize, but I wouldn't know how to do it properly in a reasonable time here. Anyway, it's the same expression four times basically ( $f(\theta1,\phi1, r1,r2) \leq 0.5)$ and Mathematica tells me:

Unable to compute the dimension of region

and I don't understand what's wrong, apart from the fact that it might have problems because it's in 4D. How could I formulate it differently?

Edit

I managed to simplify it by making some assumptions:

ImplicitRegion[
  -633.655 <= 
  r1 (r1 (4. + 1. θ1^4 - 2. θ1^2 ϕ1^2) - 
        Sqrt[(128 π^2 + r1^2 (4 + θ1^4)) (4 + θ1^4 + θ1^2 ϕ1^4)]) <= 
  -629.655 && 
  314.827 + 2. r2^2 <= 
  r2 Sqrt[128 π^2 + 4 r2^2 + r1^2 θ1^2 ϕ1^2 (4 + ϕ1^2)] && 
  r2 Sqrt[128 π^2 + 4 r2^2 + r1^2 θ1^2 ϕ1^2 (4 + ϕ1^2)] <= 
  316.827 + 2 r2^2 &&
  r1 >= 0 && r2 >= 0 && 160 <= r1 <= 200 && 160 <= r2 <= 200 &&
  -0.1 <= θ1 <= 0.1 && -0.1 <= ϕ1 <= 0.1, 
 {r1, r2, θ1, ϕ1}]

Now it doesn't give that error anymore, but instead it never finishes calculating.

Edit

I need to integrate a function over that region: NIntegrate[fn[r1, r2, θ1, ϕ1], {r1, r2, ϕ1, θ1} ∈ IntegrationZone, Method -> "MonteCarlo"] but what my problem is, is that NIntegrate[], or more precisely, Volume[], cannot calculate the area of that function. If I change the method to e.g. GlobalAdaptive, I get:

iCopyExpr() called on symbol.

so that's why I'm trying MonteCarlo.

$\endgroup$
  • 3
    $\begingroup$ It is necessary to fix Pi instead of \pi,` Sqrt[]` instead of Sqrt(), theta1 instead of theta_1,phi1 instead of phi_1 . If everything is fixed in the code, then an error occurs during numerical integration: DiscretizeRegion::cdim: The region given at position 1 in DiscretizeRegion[ImplicitRegion[...,{r1,r2,phi1,theta1}]] is in dimension 4. DiscretizeRegion only supports dimensions 1 through 3. $\endgroup$ – Alex Trounev May 31 at 18:38
  • $\begingroup$ Please replace in your WL code the LaTeX notation/code with proper WL symbols. (As pointed out in the previous comment.) $\endgroup$ – Anton Antonov May 31 at 19:16
  • $\begingroup$ @AntonAntonov done $\endgroup$ – LowFieldTheory May 31 at 19:44
  • $\begingroup$ @MichaelE2 if I paste the fragment above (the first one) into M (v10.0), and try to calculate the Volume, I get the error $\endgroup$ – LowFieldTheory Jun 1 at 15:01
5
$\begingroup$

You can use Boole and integrate numerically:

NIntegrate[
Boole[-633.655`30 <= r1 (r1 (4+ θ1^4-2 θ1^2 ϕ1^2) - Sqrt[(128 π^2+r1^2 (4+θ1^4)) (4+θ1^4+θ1^2 ϕ1^4)]) <= -629.655`30 && 314.827`30+2 r2^2 <= r2 Sqrt[128 π^2+4 r2^2+r1^2 θ1^2 ϕ1^2 (4+ϕ1^2)] && r2 Sqrt[128 π^2+4 r2^2+r1^2 θ1^2 ϕ1^2 (4+ϕ1^2)] <= 316.827`30+2 r2^2]
, {r1,160,200}, {r2,160,200}, {θ1,-1/10,1/10}, {ϕ1,-1/10,1/10}
, Method->"MonteCarlo", WorkingPrecision->30]

I get the result $61.4(5)$. You can probably reduce WorkingPrecision to machine precision and get the same result; I leave this to you.

$\endgroup$
  • $\begingroup$ how do I integrate a(n) (explicit) function using the above region? That was the question actually.. $\endgroup$ – LowFieldTheory Jun 1 at 17:15
  • $\begingroup$ @LowFieldTheory Just introduce the function inside the integral: NIntegrate[a[r1,r2,θ1,ϕ1] Boole[...] ...]. $\endgroup$ – AccidentalFourierTransform Jun 1 at 17:21
  • $\begingroup$ so simple and yet so powerful, I suppose this was it, thx $\endgroup$ – LowFieldTheory Jun 1 at 17:29

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.