Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simulation of Random Walk How do we investigate this numerically? Choose the step length to be a=1 Use a computer to generate random numbers r i uniformly.

Similar presentations


Presentation on theme: "Simulation of Random Walk How do we investigate this numerically? Choose the step length to be a=1 Use a computer to generate random numbers r i uniformly."— Presentation transcript:

1

2 Simulation of Random Walk How do we investigate this numerically? Choose the step length to be a=1 Use a computer to generate random numbers r i uniformly in the range [0,1] if r i  p then increase x by 1 => x=x+1 otherwise decrease x by 1 => x=x-1 calculate total x(N) after N steps any value in the range -N< x < +N is possible calculate and - 2 by repeated trials

3 Monte Carlo Simulation of 1-d Random Walk Two trials with N=5000 steps

4 Random Walk in 2 dimensions Let the walker start at the origin and choose each of the four directions with equal probability (p=1/4) at each step choose random number r i if r i .25 x=x+1 if.25< r i .5 x=x-1 if.5 < r i .75 y=y+1 if.75 < r i  1 y=y-1

5 Random walk in 2 dimensions

6 Random Walk Walk2d simulation

7 Monte Carlo Method Perform many trials and calculate the average of any quantity calculate the variance [ - 2 ] error in   [( - 2 )/ntrial] 1/2

8 Random Walks and the Diffusion Equation This is the diffusion equation for the probability of finding a particle at position x at time t what is the dependence of and on t? the average of any function f(x) is

9 Multiply the diffusion equation on both sides by x and integrate over x Left side becomes Right side is zero since Hence

10 To calculate, two integrations by parts are needed and we find Random walk and diffusion equation have the same time dependence

11 Monte Carlo Methods Consider the problem of integration in one dimension b F =  f(x) dx a The classical methods of numerical integration are based on the geometrical interpretation of the integral as the area under the curve of f(x) from x=a to x=b

12 For some choices of f(x) the integral can be evaluated analytically eg. cos(x) classical methods of numerical integration are based on the geometrical interpretation of the integral as the ‘area’ under the curve of the function f(x) from x=a to x=b divide the x-axis into n equal intervals of width  x, where  x=(b-a)/n Integration

13

14 cos(x) an estimate of the area is Rectangular Approximation

15 f(x)=cos(x) Consider f(x)= cos(x) with a=0 and b=  /2 compare with numerical results error decreases as 1/n

16

17 Trapezoidal Rule A better approximation to the area is given by the trapezoidal rule rather than using f(x i )  x we use the average of f(x) at the beginning and end of the interval (1/2)[f(x i+1 )+f(x i )]  x error decreases as 1/n 2

18

19 Simpson’s Rule A more accurate method is to use a quadratic or parabolic interpolation procedure Simpson’s rule error decreases as 1/n 4 adequate for well behaved functions But a function such as f(x)= x -1/3 is poorly behaved at x=0 and would present problems

20 Simpson’s Rule Simpson’s Rule chapter 11 integtrap

21 Can we evaluate this using random numbers? Consider a rectangle of height H, width (b-a), and area A= H x (b-a) such that f(x) lies within the rectangle

22 hit or miss algorithm Compute ‘n’ pairs of random numbers (x i, y i ) with a  x i  b and 0  y i  H The fraction of the points that satisfy y i  f( x i ) is an estimate of the ratio of the integral to the area of the rectangle F n = A (n s / n) where n s is the number of "splashes" below the curve and ‘n’ is the number of trials.

23

24 Eg. f(x) = 4 sqrt( 1 – x 2 ) on the interval 0  x  1 F(exact) =  = 3.14159 Hit

25

26 Sample mean approach Choose the x i at random and sample the value of f(x i ) Mean-value theorem of calculus: F = (b-a) For n trials, F n = (b-a)(1/n)  i=1,n f(x i ) where the x i are distributed uniformly on the interval a  x i  b

27

28 f(x) = 4 sqrt( 1. – x 2 ) [0,1] The exact value of the integral is  = 3.14159

29

30 Now fix the number of trials and repeat with a different set of random numbers The mean value is = 3.14080 The standard deviation of the means is  = ( - 2 ) 1/2 = 9.46813E-03   n /n 1/2 Hence, F = (b-a)  (b-a) ( - 2 ) 1/2 n 1/2

31

32 In general dimension, F = V  V ( - 2 ) 1/2 n 1/2

33 Example: Multidimensional Integrals Consider a small atom such as magnesium with 12 electrons To calculate electronic properties we need to integrate over all coordinates 3 x 12 = 36 dimensional integral! With 64 points for each integration, this requires 64 36 ~ 10 65 evaluations of the integrand => impossible ! =155/6 = 25.83333 integ10


Download ppt "Simulation of Random Walk How do we investigate this numerically? Choose the step length to be a=1 Use a computer to generate random numbers r i uniformly."

Similar presentations


Ads by Google