I would like to get a different solution to a problem I have solved “symbolically” and through a little simulation. Now, I would like to know how could I have got the integration directly using Mathematica.
Please consider a target represented by a disk with r = 1, centered at (0,0).I want to do a simulation of my probability to hit this target throwing darts.
Now, I have no biases throwing them, that is on average I shall hit the center mu = 0 but my variance is 1.
Considering the coordinate of my dart as it hit the target (or the wall 🙂 ) I have the following distributions, 2 Gaussians:
XDistribution : 1/Sqrt[2 \[Pi]\[Sigma]^2] E^(-x^2/(2 \[Sigma]^2))
YDistribution : 1/Sqrt[2 \[Pi]\[Sigma]^2] E^(-y^2/(2 \[Sigma]^2))
With those 2 distribution centered at 0 with equal variance =1 , my joint distribution becomes a bivariate Gaussian such as :
1/(2 \[Pi]\[Sigma]^2) E^(-((x^2 + y^2)/(2 \[Sigma]^2)))
So I need to know my probability to hit the target or the probability of x^2 + y^2 to be inferior to 1.
An integration after a transformation in a polar coordinate system gave me first my solution : .39 . Simulation confirmed it using :
Total@ParallelTable[
If[
EuclideanDistance[{
RandomVariate[NormalDistribution[0, Sqrt[1]]],
RandomVariate[NormalDistribution[0, Sqrt[1]]]
}, {0, 0}] < 1, 1,0], {1000000}]/1000000
I feel there were more elegant way to solve this problem using the integration capacities of Mathematica, but never got to map ether work.
There are actually several ways you can do this.
The simplest would be to use
NIntegrateas:This is another way to do it empirically (similar to your example above), but a lot slower than using
NIntegrate: