Presentation is loading. Please wait.

Presentation is loading. Please wait.

Monte Carlo Simulation Part.1 Dept. Phys., Tunghai Univ. Numerical Methods, C. T. Shih.

Similar presentations


Presentation on theme: "Monte Carlo Simulation Part.1 Dept. Phys., Tunghai Univ. Numerical Methods, C. T. Shih."— Presentation transcript:

1 Monte Carlo Simulation Part.1 Dept. Phys., Tunghai Univ. Numerical Methods, C. T. Shih

2 如何以蒙地卡羅法做數值積分  If we want to find the numerical integration:  We can simply divide the region [0,1] evenly into M slices and the integral can be approximated by:

3 Simple Sampling  On the other hand, we can select x n for n=1,2,...,M from a uniform random number generator (亂數產生器)  If M is large enough, x n is set of numbers uniformly distributed in the region [0,1]

4 Simple Sampling (conti.)  The integral can be approximated by:  Now the error in the integral comes from the fluctuation of the distribution of x n :

5 f(x) 01

6 Random Number Generator  Indeed, there is no real random number generator in a computer program – the program always follows the commands by the programmer  We can only have a “pseudo-random number generator”  A good random number generator: very long period, good randomness (small correlation), fast

7 Pseudo-RNG  Long period: what is the possible longest period on a computer?  Answer: the largest integer, i.e., 2 31 -1 = 2,147,483,647 on a 32-bit computer

8 Linear Congruent Scheme  The random numbers are generated by:  a, b, c are “magic numbers” which determine the quality of the RNG  One possible choice (tested OK): a = 7 5 = 16807, b = 0, and c = 2 31 -1 = 2,147,483,647  Also you need a “seed” of your RNG as the initial x

9 Procedure of the RNG  讀入系統時間(利用內建 TIME() 函數)作 為 ISEED ,也就是 x 0  利用 計算 x 1  將 x 1 作為新的 ISEED ,而所得之 random number 為 x 1 /c  依此類推,可得到一連串介於 (0,1) 之間 的均勻亂數

10 Overflow 問題  由於 可能發生 overflow ,因此程式上必須考慮:

11 練習:  利用 Monte Carlo 法計算以下函數的積分, M (取樣數為 100, 1000, 1000 ), a 取 0.2, 0.5, 1, 5, 10 ,求積分之近似值以及標 準差

12 Alternative:  一維函數的蒙地卡羅積分也可以用以下的方法 計算:  產生兩個亂數所成數對( x,y ), x 的範圍在積 分上下限 [a,b] 之間, y 的範圍在 [c,d] 之間, 且 c 不大於 f(x) 於 [a,b] 間之極小值, d 不小於 f(x) 於 [a,b] 間之極大值  若 0<y<f(x) 則 N + 增加一,若 f(x)<y<0 則 N - 增 加一,若總共產生 N 個亂數,則面積之平均值 為 :

13

14 平均值與標準差計算方式  上述過程每次產生 N 組亂數,可得到一 個 S  重複以上過程 M 次,即可得到 M 個 S i, i=1,2,...,M  求這 M 個 S 的平均值即為面積  標準差


Download ppt "Monte Carlo Simulation Part.1 Dept. Phys., Tunghai Univ. Numerical Methods, C. T. Shih."

Similar presentations


Ads by Google