To find the volume of the following region:
fn[x_, y_, z_]:= Abs[0.7*x*Exp[I*y] + 0.3*Sqrt[x^2 + 8*10^-5]
+ Sqrt[x^2 + 3*10^-3]*0.02*Exp[I*z]]
R = ImplicitRegion[fn[x, y, z]<=3*10^-3, {{x, 0, 0.015}, {y, 0, 2*Pi}, {z, 0, 2*Pi}}]
RegionPlot3D[
fn[x, y, z] <= 3*10^-3, {x, 0, 0.015}, {y, 0, 2*Pi}, {z, 0, 2*Pi},
PlotPoints -> 50, AxesLabel -> {x, y, z},
PlotStyle -> Directive[Yellow, Opacity[0.5]], Mesh -> None]
Using Volume
:
Volume[R]
Volume::nmet: Unable to compute the volume of region
Using NIntegrate
:
NIntegrate[
Boole[fn[x, y, z] <= 3*10^-3], {x, 0, 0.015}, {y, 0, 2*Pi}, {z, 0,
2*Pi}, Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 50000},
PrecisionGoal -> 3] // Timing
NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 50000 times. The global error is expected to decrease monotonically after a number of integrand evaluations... NIntegrate obtained 0.12219642052793653 and 0.007515502934285486 for the integral and error estimates.
{19.25, 0.122196}
The result does not converge.
Using MonteCarlo
:
NIntegrate[
Boole[fn[x, y, z] <= 3*10^-3], {x, 0, 0.015}, {y, 0, 2*Pi}, {z, 0,
2*Pi}, Method -> {"MonteCarlo", "MaxPoints" -> 10^12,
"RandomSeed" -> 9}, PrecisionGoal -> 3] // Timing
{8.39063, 0.121479}
This is slow, and if PrecisionGoal -> 5
is set,
NIntegrate[
Boole[fn[x, y, z] <= 3*10^-3], {x, 0, 0.015}, {y, 0, 2*Pi}, {z, 0,
2*Pi}, Method -> {"MonteCarlo", "MaxPoints" -> 10^12,
"RandomSeed" -> 9}, PrecisionGoal -> 5]
It does not give a result even after running for more than 2 minutes.
I hope to find a better way to calculate the volume of this region with:
- High accuracy: at least
PrecisionGoal -> 5
- Good error estimate
- Fast
Volume[DiscretizeRegion[R,MaxCellMeasure->0.01]]
with different values forMaxCellMeasure
. However, it fails in this case for some reason... $\endgroup$ – Henrik Schumacher Feb 10 '18 at 8:35Rationalize
the expression you use infn
and use symbolic bounds over numerical constants whenever possible (e.g. 15/1000 instead of 0.015). This often helps, because it enables arbitrary precision results without loss of precision/accuracy, which can cause problems (slow convergence warnings) in numerical methods likeNIntegrate
. It also helps avoid ugly results when a symbolic integration is possible. $\endgroup$ – Thies Heidecke Feb 10 '18 at 9:20DiscretizeRegion[R]
failed in this case. $\endgroup$ – K.D Feb 10 '18 at 12:26