I want to generate random polar angles given a uniform distribution on the unit sphere. In other words, I want to generate random numbers from the probability density function p(theta) = sin(theta)/2 in the interval [0,pi]. How do I do this?

 Réponse acceptée

Roger Stafford
Roger Stafford le 29 Mai 2014
Modifié(e) : Roger Stafford le 29 Mai 2014

0 votes

The requested distribution of theta is generated below. Consequently the following code will places yellow dots on the unit sphere surface in a statistically uniform manner.
n = 8192;
theta = acos(1-2*rand(n,1)); % <-- The requested distribution
phi = 2*pi*rand(n,1);
x = sin(theta).*cos(phi);
y = sin(theta).*sin(phi);
z = cos(theta);
plot(x,y,z,'y.')
(Corrected)

Plus de réponses (0)

Catégories

En savoir plus sur Polar Plots dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by