How to find random values of variable satisfying multiple conditions?
You can use ImplicitRegion
+ RandomPoint
:
impreg = ImplicitRegion[Abs[x] < (1 - 2 Sqrt[Abs[y]] Sqrt[(1 + Abs[y]) (1 + Abs[z])] +
Abs[y] (2 + Abs[z]))/Abs[z],
{{x, -1, 1}, {y, -1, 1}, {z, -1, 1}}];
RandomPoint[impreg]
{-0.765127, -0.0412526, 0.134246}
SeedRandom[1]
randompoints = RandomPoint[impreg, 20];
Show[RegionPlot3D[impreg, PlotStyle -> Opacity[.3]],
Graphics3D[{Red, Sphere[#, .05] & /@ randompoints}]]
We can modified the inequalities to speed up the calculate. Use RealAbs
instead of Abs
for real numbers.
reg = ImplicitRegion[
RealAbs[x] RealAbs[z] <
1 - 2 Sqrt[RealAbs[y]] Sqrt[(1 + RealAbs[y]) (1 + RealAbs[z])] +
RealAbs[y] (2 + RealAbs[z]), {{x, -1, 1}, {y, -1, 1}, {z, -1,
1}}] // Region
RandomPoint[reg, 1000]
Furthermore, by the symmetric we can assuming that x>=0 && y>=0 && z>=0
and randomly select the sign of the coordinate.
reg = ImplicitRegion[
x*z < 1 - 2 Sqrt[y] Sqrt[(1 + y) (1 + z)] + y (2 + z), {{x, 0,
1}, {y, 0, 1}, {z, 0, 1}}] // Region;
Graphics3D[{Cyan, Point[RandomPoint[reg, 10000]]}]