def sample():
'''
Draw a sample from the distribution of polar angle of the angular
momentum vector, :math:`\\theta`, computed using the Monte Carlo
technique discussed in the paper.
.. plot::
:align: center
from planetplanet.photo import theta
import matplotlib.pyplot as pl
x = [theta.sample() for i in range(10000)]
pl.hist(x, bins = 50)
pl.xlabel(r'$\\theta$ [deg]', fontweight = 'bold')
pl.ylabel('Probability', fontweight = 'bold')
pl.show()
'''
y = np.random.random()
f = lambda x: CDF(x) - y
while np.sign(f(0)) == np.sign(f(1)):
y = np.random.random()
f = lambda x: CDF(x) - y
return brentq(f, 0, 1)
评论列表
文章目录