Generating random radii of circle

2 views (last 30 days)
1234
1234 on 17 Sep 2018
Edited: Johannes Thewes on 18 Sep 2018
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 Comments
Image Analyst
Image Analyst on 17 Sep 2018
Alright. Good luck with it.
Walter Roberson
Walter Roberson on 17 Sep 2018
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.

Sign in to comment.

Answers (1)

Johannes Thewes
Johannes Thewes on 17 Sep 2018
Edited: Johannes Thewes on 18 Sep 2018
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;

Community Treasure Hunt

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

Start Hunting!