Generating random radii of circle
2 次查看(过去 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!