Generating random radii of circle
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to create a code for generating 10^6 outcomes of R where R is distributed as the distance from a random and uniformly point from the interior of a circle with radius 10 and the origin of the circle.
2 件のコメント
Walter Roberson
2018 年 9 月 17 日
Is the uniform random based upon radius or based upon area? Uniform random with respect to radius gets sparser in area as you get further from the point of origin.
回答 (1 件)
Johannes Thewes
2018 年 9 月 17 日
編集済み: Johannes Thewes
2018 年 9 月 18 日
I assume your question to be intended as follows: You want to sample uniformly 10^6 points inside a circle with radius 10. Then you calculate the distances of these points from the origin, which is your resulting vector R.
This can be simplified with the help of the method of inverse transform sampling. First, it is necessary to compute the cumulative distribution function (cdf). It is given as the probability p(r) to find any point sampled inside the circle with radius 10 inside a smaller circle with radius r<=10. It is the ratio of the respective circle areas, which is p(r) = pi*r^2/(pi*10^2) = r^2/10^2.
The idea of inverse transform sampling is now to first invert the cdf as R = sqrt(p(r)) * 10 and then insert uniformly drawn probabilities between 0 and 1 for p(r). The resulting radii R should then follow your desired probability distribution:
R = sqrt(rand(1e6,1))*10;
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!