






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The direct sampling method of monte carlo integration, used to calculate the value of integrals. It includes examples with matlab code and visualizations of error reduction with increasing sample size.
Typology: Slides
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Dr. Nasir M Mirza
Computational Physics^ Computational Physics
Email: [email protected]
Direct Sampling – continued
( )
(^1) −
i^
i
Example 1: As an illustration of this we will try first to find the following integral:
1 0 4
1 0
3
∫
x
dx x
∫
1 0
2
1
2
) (
1 0 2
1 0
1 0
=
=
=^
∫
∫^
A
x A
dx x A
dx x Af
Let us consider f(x) = x and g(x) = x
The exact answer is
Let us first find the normalization constant for f(x): Then comulative pdf is
∫
∫^
x
x
dx x
xdx
x
x
x
0 2
0
0
and the find the area as
. /) (
1 2
N x g
I^
i^
i
∑ ≈
So, we use this equationto generate x
7
Example 1: Results:^ Figure showsthe area versusthe number ofhistories (N).Increasing theN we see adecrease in theerror.
1x
4
2x
4
3x
4
4x
4
5x
4
6x
0.260 0.256 0.252Area0.248 0.244 0.
Number of Trails in a sample
Area from Monte Carlo method Exact Area
Let us try to find the following integral:
π
π
1 0
)
(sin
dx x
x
I^2
0 2
0
0
/ 2 1 2 ) ( π
π
π
π
=
=
=^
∫
∫^
A
x A
dx x A
dx x Af
Let us consider f(x) = x and g(x) = sinx.
The exact answer is
Let us first find the normalization constant for f(x): Then comulative pdf is
ξ π
ξ
=
⇒
=
=
=^
∫
∫
x
x A
dx x A
Axdx
x
x
x
0 2
0
0
2
So, we use the above equation to generate x and the find the area as
. /)
(
(^22)
N
x g
I^
i^
i
∑
≈
π
Example 2:
Figure above shows the area versus the number of histories (N). Increasingthe N we see a decrease in the error. The error bars below are indicating thateffect.
Area
Number of Trails in a sample
x 1000
Area from Monte Carlo method Exact Area
Example 2:
Example 2:^ Figure above shows the area versus the number of histories (N). Increasingthe N we see a decrease in the error. The error bars below are indicating thateffect.
Error in Area
Number of Trails in a sample
x 1000
Error in Area from MC method Zero Error line