Docsity

Monte Carlo Methods: Direct Sampling Technique for Integral Calculation, Slides of Computational Physics

Partial preview of the text

Download Monte Carlo Methods: Direct Sampling Technique for Integral Calculation and more Slides Computational Physics in PDF only on Docsity!

Stochastic Methods

Topic: Direct Sampling – II

Dr. Nasir M Mirza

Computational Physics^ Computational Physics

Email: [email protected]

Lecture Two: Direct Sampling -

II

Monte Carlo Methods^ Monte Carlo Methods

Direct Sampling – continued

( )

uniform

is

where

F

x

ξ^

(^1) −

uniform

is

where

x

F

(^

The cumulative distribution function for x is determined by solvingthe following equation:^ And x is determined from following:^ To find the integral, we first generate the normalized pdf f(x), thenuse these as

x

values

i^

i

x

g

N

I

This will be the value of integral.

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

I

∫

1 0

2 dx

x

x

I

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:

π

π

∫^0

sin

xdx

x

I

∫

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:

RESULTS

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:

RESULTS

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