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?

 채택된 답변

Roger Stafford
Roger Stafford 2014년 5월 29일
편집: Roger Stafford 2014년 5월 29일

0 개 추천

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)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Polar Plots에 대해 자세히 알아보기

제품

질문:

2014년 5월 28일

편집:

2014년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by