region = ImplicitRegion[x^2 + y^2 + z^2 + p^2 == 1, {x, y, z, p}]; RandomPoint[region] The result is RandomPoint[ImplicitRegion[x^2 + y^2 + z^2 + p^2 == 1, {x, y, z, p}]],and how can I attain two random number in this condition。
3 Answers
You can use Sphere
instead of ImplicitRegion
:
RandomPoint[Sphere[{0,0,0,0}, 1], 2]
{{0.318231, -0.429109, -0.496487, 0.684175}, {-0.623644, 0.379281, -0.651925, 0.205445}}
Or with higher dimensions:
RandomPoint[Sphere[{0,0,0,0,0,0,0,0,0,0}, 1], 2]
{{-0.17768, 0.211006, -0.112154, 0.200347, -0.282798, -0.433921, -0.502452, 0.126637, 0.0389269, 0.576989}, {-0.391113, 0.0430085, -0.771695, -0.203369, -0.0604124, 0.248403, 0.346597, 0.0345813, -0.0161699, 0.146178}}
x^2 + y^2 + z^2 + p^2 == 1
is the surface of a hypersphere. Since the surface has no thickness, RandomPoint
has difficulty in locating a point. If instead you give the surface some small thickness, it can more readily be done.
Clear["Global`*"]
region = ImplicitRegion[1 - 10^-5 < x^2 + y^2 + z^2 + p^2 <= 1,
{x, y, z, p}];
SeedRandom[1234]
RandomPoint[region]
(* {-0.703156, -0.411576, -0.579139, -0.0276921} *)
RandomPoint[region, 2]
(* {{0.229318, 0.519268, 0.821769,
0.0496847}, {0.0387424, -0.286988, -0.048466, -0.955917}} *)
-
-
3$\begingroup$ @YUNFENGGUO you can also use
ImplicitRegion[0 < x^2 + y^2 + z^2 + p^2 <= 1, {x,y,z,p}]
which is equivalent toBall[{0,0,0,0},1]
and generate the random points on the interior, then just callNormalize
on the points which will flatten them onto the surface. $\endgroup$– flintyCommented Aug 3, 2020 at 10:57
Clear["`*"];
x := Sin[a] Sin[b] Sin[c];
y := Sin[a] Sin[b] Cos[c];
z := Sin[a] Cos[b];
p := Cos[a];
x^2 + y^2 + z^2 + p^2 // FullSimplify;
pts = Table[{x, y, z, p} /.
Thread[{a, b, c} -> {RandomReal[{0, Pi}], RandomReal[{0, Pi}],
RandomReal[{0, 2 Pi}]}], 10000];
Graphics3D[Point[Most /@ pts]]
-
1$\begingroup$ See
MatrixPlot[Covariance@pts]
and your points have consistently different diagonal entries in the covariance matrix fromMatrixPlot[Covariance@RandomPoint[Sphere[{0,0,0,0},1],10000]
. In the limit as n->Infinity the covariance should be a scaled IdentityMatrix[4]. Are the equations correct? $\endgroup$– flintyCommented Aug 3, 2020 at 15:03