Monte carlo integration in spherical coordinates

I was experimenting with creating a code for Montecarlo integration of a function specified in spherical coordinates. As a first straightforward quick examination I determined to write an examination code to get the strong angle under an angle $\theta_m$. For 2 arbitrary number $u$ and also $v$ in $[0,1)$. I create an uniform arbitrary tasting of the round angle making use of $\phi=2\pi u$ and also $\theta =\arccos(1-2v)$.

For N created factors, I have M factors for which $\theta < \theta_m$. My first suggestion was that given that I have an uniform tasting I need to have gotten the proper strong angle $\Omega=2 \pi (1-\cos (\theta_m))$ merely as $4\pi\times \frac{M}{N}$. In fact it resembles I the proper outcome appears just if I make use of:

$$\Omega=\sum_{i=1}^M \frac{4\pi}{N} 2 cos(\theta_i)$$

I can not see the reason that this needs to be proper. The chance circulation function in $\theta$ is $PDF=\frac{1}{2} \sin(\theta)$ so I prefer to anticipate I need to stabilize each factor of the amount by this function yet this does not jobs. What am I doing incorrect and also just how could I warrant the cosinus? Several many thanks!

2022-06-07 14:34:49
Source Share
Answers: 1

You can substantially streamline this. The angle $\phi$ does not take place anywhere, so you are not in fact making use of $u$ or $\phi$, so we can overlook them. The angle $\theta$ just takes place in the kind $\cos\theta$, so it makes good sense to switch over to $z=\cos\theta$ rather.

Reiterated this way, your inquiry is whether creating (probably evenly dispersed) arbitrary numbers $v$ in $[0,1)$ and also computing $z=1-2v$ will certainly bring about $z>z_m$ in a portion $M/N=2\pi(1-z_m)/(4\pi)=(1-z_m)/2$ of instances. This straight partnership is plainly proper, so your formula is alright and also it appears there have to be something incorrect in your program rather if this is not functioning.

Extra usually talking, when you are making use of both mathematics and also code, it is constantly vital to maintain an open mind concerning in which of both domain names the mistake could exist. Your inquiry appears to show that you might have too soon determined that the code was alright and also the mistake has to remain in the mathematics.

2022-06-07 15:00:41