TransWikia.com

RandomPoint fails for any higher dimension

Mathematica Asked by YUNFENG GUO on October 7, 2020

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

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}} *)

Answered by Bob Hanlon on October 7, 2020

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}}

Answered by Carl Woll on October 7, 2020

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]]

projected to xyz plane. enter image description here

Answered by cvgmt on October 7, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP