Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

New answers tagged

4

Just make a random matrix with all positive eigenvalues and then add a minus sign: r = 4; M = -#.ConjugateTranspose[#]&[RandomVariate[NormalDistribution[], {r,r,2}].{1,I}]


0

You can use Archimedes' result (https://en.wikipedia.org/wiki/On_the_Sphere_and_Cylinder) that the area between two lines of latitude is the same as the corresponding area of the enclosing cylinder. This gives a fairly simple result for sampling the top of the sphere, above height Z pt[Z_] := Module[{z, θ, r}, z = RandomVariate[UniformDistribution[{Z, 1}]...


-2

Let's imagine Earth. To get a uniform distribution of points on the Earth's surface, we need to sample two angles - latitude and longitude. The longitude may have a uniform distribution. However, for latitude, we have to have more points closer to the equator and less in the poles. In fact, the distribution function should be proportional to the cosine ...


7

We can also take RandomPoints in boolean region obtained by the RegionIntersection of a Sphere and a Ball with radius r centered at a random point on the sphere: SeedRandom[1] r = .7; ctr = RandomPoint[Sphere[]]; pts = RandomPoint[RegionIntersection[Ball[ctr, r], Sphere[]], 1000]; Graphics3D[{Red, Point@pts, White, Opacity[.5], Sphere[]}]


10

Using Christian Blatter's results from this math.SE answer, here is how to randomly sample a spherical cap: randomCapPoint[{r_, r2_}, dir_?VectorQ] := With[{h = RandomReal[{Sqrt[1 - (r2/r)^2], 1}]}, RotationTransform[{{0, 0, 1}, Normalize[dir]}][r Append[Sqrt[1 - h^2] Normalize[RandomVariate[NormalDistribution[], 2]], h]]] For example, ...


19

You can intersect the sphere and a cylinder, and then use RandomPoint. For example, here is a random point on the sphere: sphere = Sphere[]; SeedRandom[1] pt = RandomPoint[sphere] {0.707037, 0.595614, 0.381239} Then, you create a cylinder in he direction of the random point with a radius: r = .7; cylinder = Cylinder[{{0,0,0},pt}, r]; Now, intersect ...


4

For this question, I can find some code of python version, Refs. here. And I rewrote this Ising simulation as Mathematica version, as follow, 1. Define a function used for generating a table (as configuration) Initialstate[n_Integer] := 2*Table[RandomInteger[], {n}, {n}] - 1 where n as the number of points. And define a function used for getting any point'...


1

Your probability distribution has a mean of 2. That means the expected value of 500 random variates will be 1000. Therefore, the following will work: SeedRandom[42] sample = With[{sum = 1000, d = 10}, Module[{testSum = 1, sample}, While[testSum < sum - d || testSum > sum + d, sample = Quiet @ RandomVariate[ ...


6

To generate the correlated pairs you could use the BinormalDistribution function: dist = BinormalDistribution[{0, 0}, {1/Sqrt[n], 1/Sqrt[n]}, τ]; Expectation[n x1 x2 , {x1, x2} \[Distributed] dist] (* τ *) To put this all together to obtain a realization of the random matrix $\boldsymbol{A}$, the following brute force approach could work. (Only $n(n+1)/2$ ...


6

To generate two Gaussian random numbers that both have zero mean and unit variance, and that have a covariance of $\tau\in[-1,1]$, you can do twoCorrelatedGaussianRandoms[τ_] := ({{Sqrt[1+τ]+Sqrt[1-τ], Sqrt[1+τ]-Sqrt[1-τ]}, {Sqrt[1+τ]-Sqrt[1-τ], Sqrt[1+τ]+Sqrt[1-τ]}}/2) . RandomVariate[NormalDistribution[], 2] Try it out by generating a million pairs ...


2

If the number of possible points is large, than enumerating them all and taking a random sample won't be feasible. For example, suppose you have integer points in a 1000 x 1000 x 1000 box. Then, the number of possible points is 10^9, and it is unlikely that your computer will be able to generate the full list. Instead, it makes sense to index the points, and ...


0

Here is a Code that @kglr developed as an answer to my Linear Programming problem. The flow between any source s and any target t can be found for directed graphs with vertices having two types of capacities: Absorption and Distribution capacities. One can find out all the existing pathways between a source s and a target t, as well as the associated maximum ...


Top 50 recent answers are included