Borrar filtros
Borrar filtros

Generating random radii of circle

2 visualizaciones (últimos 30 días)
1234
1234 el 17 de Sept. de 2018
Editada: Johannes Thewes el 18 de Sept. de 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 comentarios
Image Analyst
Image Analyst el 17 de Sept. de 2018
Alright. Good luck with it.
Walter Roberson
Walter Roberson el 17 de Sept. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Johannes Thewes
Johannes Thewes el 17 de Sept. de 2018
Editada: Johannes Thewes el 18 de Sept. de 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!

Translated by