MONTE CARLO NUMERICAL METHOD

40
MONTE CARLO NUMERICAL METHOD BY A. Lecture KARRAR DH. MOHAMMED

description

MONTE CARLO NUMERICAL METHOD. BY A. Lecture KARRAR DH. MOHAMMED. History of the Monte Carlo Method. The Monte Carlo name is taken from the Monte Carlo, the capital of Monaco which was a center for gambling. - PowerPoint PPT Presentation

Transcript of MONTE CARLO NUMERICAL METHOD

Page 1: MONTE CARLO       NUMERICAL METHOD

MONTE CARLO NUMERICAL METHOD

BYA. Lecture KARRAR DH.

MOHAMMED

Page 2: MONTE CARLO       NUMERICAL METHOD

History of the Monte Carlo Method

• The Monte Carlo name is taken from the Monte Carlo, the capital of Monaco which was a center for gambling .

Page 3: MONTE CARLO       NUMERICAL METHOD

• Monte Carlo methods are used in many different ways e.g. as a technique of integration of a function. One of this ways is:

The Monte Carlo method as a numerical technique for calculating the integral by using sequences of random numbers.

Page 4: MONTE CARLO       NUMERICAL METHOD

• In mathematics, Monte Carlo integration is numerical integration using random numbers. That is, Monte Carlo integration methods are algorithms for the approximate evaluation of definite integrals, usually multidimensional ones.

Page 5: MONTE CARLO       NUMERICAL METHOD

• The usual algorithms evaluate the integrand at a regular grid.

Monte Carlo methods, however, randomly choose the points at which the integrand is evaluated, informally, to estimate the area of a domain D,

Page 6: MONTE CARLO       NUMERICAL METHOD

• First, pick a simple domain E whose area is easily calculated and which contains D.

• Now pick a sequence of random points that fall within E.

• Some fraction of these points will also fall within D.

Page 7: MONTE CARLO       NUMERICAL METHOD

• The area of D is then estimated as this fraction multiplied by the area of E.

• The traditional Monte Carlo algorithm distributes the evaluation points uniformly over the integration region .

Page 8: MONTE CARLO       NUMERICAL METHOD

Why are Monte Carlo techniques used?

• Two of the main reasons why we use Monte Carlo methods:

• their ant-aliasing properties, and• their ability to approximate quickly

an answer that would be very time-consuming to find out.

Page 9: MONTE CARLO       NUMERICAL METHOD

• if we want to use a method to determine the exact answer, Monte Carlo method can be used to simulate problems that are too difficult and time-consuming.

Page 10: MONTE CARLO       NUMERICAL METHOD

• An example is in the use of Monte Carlo techniques in integrating very complex multidimensional integrals.

• This is a task that other processes can not handle well, but which Monte Carlo can.

Page 11: MONTE CARLO       NUMERICAL METHOD

• The first point refers to the fact that since Monte Carlo methods involve a random component in the algorithm, then they go some way to avoid the problems of ant-aliasing (only for certain applications).

Page 12: MONTE CARLO       NUMERICAL METHOD

• An example that was brought to my attention was that of finding the area of the black squares on a chess board. Now, if I was using an acceptance-rejection method to attack this problem,

I should come out with a fair approximation,

Page 13: MONTE CARLO       NUMERICAL METHOD

• Due to the fact that I would be going to random points on the chessboard, I will do the same process by using an algorithm that moved to a certain next point in a set of distance away and then continued to do this,

Page 14: MONTE CARLO       NUMERICAL METHOD

• thus not having any random point selection, the potential problem is that this person may have a bad step size and may over evaluate or under evaluate the number of successful trials he has, thus inevitably giving a poor approximation.

Page 15: MONTE CARLO       NUMERICAL METHOD

• These are two solid reasons why people use Monte Carlo techniques. Other possible reasons could include its ease in simulating complex physical systems in the fields of physics, engineering and chemistry

Page 16: MONTE CARLO       NUMERICAL METHOD

Transformation Function

•T : [c,d] [0,1]

•is defined by :-

•T (x) =(x-c) / (d-c)

Page 17: MONTE CARLO       NUMERICAL METHOD

Generate a random number x uniform in [X min,X max]:

• Step 1:• A random number generated by

the following relation :-• ni = (k*ni) mod m . such that• ni: integer number• k: multiplier number• m: modulus number• no : initial value

Page 18: MONTE CARLO       NUMERICAL METHOD

• step 2:• ri = ni /m in[0,1] where• ni ={n1,n2 ,n3,………}• m: modulus

• step 3:• Xi (random) =X min + ri * (X max –

X min)

Page 19: MONTE CARLO       NUMERICAL METHOD

Crude Monte Carlo • We are going to use this technique to

solve the integral I.

• I =

• The method is that you take a number N for random number where c ≤ xi ≤ d then for all xi we find the function

• f (xi) .

dxxfd

c )(

Page 20: MONTE CARLO       NUMERICAL METHOD

• For the f(x) we sum all of these values and divide by N to get the mean value for the random number. We then multiply this value by the interval (b-a) to get the integral by:

• I=

n

ixif

n

ab

1)(*

Page 21: MONTE CARLO       NUMERICAL METHOD

EXAMPLE:

• Solve the following integral by using Monte Carlo method

• I=

• Solution:- we use the previous steps to get the solution

3

1

)sin( dxx

Page 22: MONTE CARLO       NUMERICAL METHOD

Step 1:-let no=1,k=3,m=7

• We compute the random numbers (n) as follows:-

• ni=k * (ni-1) mod 7• n1=(3*1) mod 7 =3• n2=(3*3) mod 7 =2• n3=(3*2) mod 7 =6• n4=(3*6) mod 7 =4

Page 23: MONTE CARLO       NUMERICAL METHOD

• n5= (3*4) mod 7 =5• n6= (3*5) mod 7 =1• n7= (3*1) mod 7 =3 ... Stop

• Number of random m-1=7-1=6

Page 24: MONTE CARLO       NUMERICAL METHOD

Step 2:-by the following we shall compute ri

ri=ni/m

r1=3/7=0.42r2=2/7=0.28r3=6/7=0.85r4=4/7=0.57r5=5/7=0.71r6=1/7=0.14

Page 25: MONTE CARLO       NUMERICAL METHOD

Step 3:-now we shall compute xi as following

• Xi= xmin+ri(xmax-xmin)

• X1=1+0.42(2)=1.84• X2=1+0.28(2)=1.56• X3=1+0.85(2)=2.7• X4=1+0.57(2)=2.14• X5=1+0.71(2)=2.42• X6=1+0.44(2)=1.28

Page 26: MONTE CARLO       NUMERICAL METHOD

NirixiF(xi)=sin(xi)

10.421.840.032

20.281.560.027

30.852.70.047

40.572.140.0373

50.712.420.0422

60.141.280.0233

2078.0)(xf

Page 27: MONTE CARLO       NUMERICAL METHOD

• I=

• I= (1/6)*(0.207)=0.0345

n

i

xifn

ab

1

)(*

Page 28: MONTE CARLO       NUMERICAL METHOD

Example:

• Solve the following integral by using Monte Carlo method

• I=

• Solution:- we use the same steps in the previous example to get the solution

dxex3

1

Page 29: MONTE CARLO       NUMERICAL METHOD

Step 1:-let no=1,k=3,m=7

• We compute the random numbers (n) as follows:-

• ni=k * (ni-1) mod 7• n1=(3*1) mod 7 =3• n2=(3*3) mod 7 =2• n3=(3*2) mod 7 =6• n4=(3*6) mod 7 =4

Page 30: MONTE CARLO       NUMERICAL METHOD

• n5= (3*4) mod 7 =5• n6= (3*5) mod 7 =1• n7= (3*1) mod 7 =3 ... Stop

• Number of random

Page 31: MONTE CARLO       NUMERICAL METHOD

• n5= (3*4) mod 7 =5• n6= (3*5) mod 7 =1• n7= (3*1) mod 7 =3 ... Stop

• Number of random m-1=7-1=6

Page 32: MONTE CARLO       NUMERICAL METHOD

Step 2:-by the following we shall compute riri=ni/m

r1=3/7=0.42r2=2/7=0.28r3=6/7=0.85r4=4/7=0.57r5=5/7=0.71r6=1/7=0.14

Page 33: MONTE CARLO       NUMERICAL METHOD

Step 3:-now we shall compute xi as follows

• Xi= xmin+ri(xmax-xmin)

• X1=1+0.42(2)=1.84• X2=1+0.28(2)=1.56• X3=1+0.85(2)=2.7• X4=1+0.57(2)=2.14• X5=1+0.71(2)=2.42• X6=1+0.44(2)=1.28

Page 34: MONTE CARLO       NUMERICAL METHOD

NirixiF(xi)=exi

10.421.846.296

20.281.564.7588

30.852.714.879

40.572.148.4994

50.712.4211.2458

60.141.283.5966

277.49)(xf

Page 35: MONTE CARLO       NUMERICAL METHOD

• I=

• I= (1/6)*(49.277) =8.2128

n

i

xifn

ab

1

)(*

Page 36: MONTE CARLO       NUMERICAL METHOD

The Monte Carlo method program by MATLAB• clc• clear• c=input('please enter the lower bound of interval i.e c =')• d=input('please enter the upper bound of interval i.e d =')• m=input('please enter the modulus number i.e m =')• n=m-1;• trans_fun(c,d)• a=0;• b=1;• s=0;• z=1;• h=(b-a)/n;• k=0;

Page 37: MONTE CARLO       NUMERICAL METHOD

• while k<n• p=3*z;• q=mod(p,m);• z=q;• r=q/m;• x=c+(r*(d-c));• f=sind(x);• s=s+f;• y=h*s;• k=k+1;• end• y

Page 38: MONTE CARLO       NUMERICAL METHOD

The transformation function program

• function [g] = trans_fun(a,b)• if (a~=0)&&(b~=1)• w=input('please enter the number of intervals points

you wont to convert it w = ')• for v = 1:w• x=input('please enter the point of interval you want to

convert it x = ')• g =(x-a)/(b-a)• end• disp('the original interval convert to a=0 & b=1') • else• disp('already a=0 & b=1')• end

Page 39: MONTE CARLO       NUMERICAL METHOD
Page 40: MONTE CARLO       NUMERICAL METHOD