tridiagonal matrix 12 The explicit time integrations The

  • Slides: 51
Download presentation

係數為 tri-diagonal matrix! 12

係數為 tri-diagonal matrix! 12

The explicit time integrations The 1 st order Euler method The 2 nd order

The explicit time integrations The 1 st order Euler method The 2 nd order Runge-Kutta method 16

圖解法 • The 1 st order Euler method y n+1 y yn tn tn+1

圖解法 • The 1 st order Euler method y n+1 y yn tn tn+1 t • The 2 nd order Runge-Kutta method (y*)n+1/2 y y n+1 yn tn tn+1 t 17

The 4 th order Runge-Kutta method 18

The 4 th order Runge-Kutta method 18

圖解法 • The 4 nd order Runge-Kutta method (y*)n+1/2 (y*)n+1 (y**)n+1/2 (y**)n+1 (y***)n+1 y

圖解法 • The 4 nd order Runge-Kutta method (y*)n+1/2 (y*)n+1 (y**)n+1/2 (y**)n+1 (y***)n+1 y yn tn tn+1 t 19

當問題為n元一次聯立方程式,且 係數矩陣為tri-diagonal matrix • The diffusion equation • The implicit scheme where 22

當問題為n元一次聯立方程式,且 係數矩陣為tri-diagonal matrix • The diffusion equation • The implicit scheme where 22

The 4 th Order Predictor-Corrector Method (Shampine and Gordon, 1975) • 預測步驟:利用 yn, yn-1,

The 4 th Order Predictor-Corrector Method (Shampine and Gordon, 1975) • 預測步驟:利用 yn, yn-1, yn-2, yn-3 , 預測yn+1之值 (the 4 th order Adams’ open formula) • 校正(疊代)步驟:利用前一次預測所得的 yn+1 ,以及原有之 yn, yn-1, yn-2, 重新預測 yn+1 之值 (the 4 th order Adams’ close formula) • 重複校正(疊代)數次,直到收斂,即可進行下一步的預測 • 因為當 n < 4 時, the 4 th order Adams’ open formula 不適用,故利 用 the 4 th order Runge-Kutta method 來求 y 1, y 2, y 3之值 25

預測用Explicit Scheme: Cannot self-start Cannot self-start 26

預測用Explicit Scheme: Cannot self-start Cannot self-start 26

校正用Implicit Scheme: 27

校正用Implicit Scheme: 27

Based on Runge-Kutta Method and Adams Formula Predictor-Corrector Method 28

Based on Runge-Kutta Method and Adams Formula Predictor-Corrector Method 28

疊代法與機器誤差估算 • Iteration – – • Interations are commonly used in solving Laplace equation,

疊代法與機器誤差估算 • Iteration – – • Interations are commonly used in solving Laplace equation, Poison equation, or use implicit scheme to solve differential equation(s). 疊代法通常需要藉由相對誤差或絕對誤差來判斷 是否可以停止疊代,找到解了。 Machine error (relative error) – Let U be the relative error of 1, then • • – The computer cannot distinguish the differences between U+1 and 1 The relative error of a real number A will be U*A Example: (Shampine and Gordon, 1975) 31

C--SUB. GETRERR--------------C Determine the relative error of the system SUBROUTINE GETRERR C To get

C--SUB. GETRERR--------------C Determine the relative error of the system SUBROUTINE GETRERR C To get relative error with respect to 1 IMPLICIT DOUBLE PRECISION (A-H, O-Z) COMMON /GET_RERR/ RELERR, ABSERR A 1=1 AH=0. 5 D 00 U=A 1 1 CONTINUE U=U*AH TEMP=A 1 -U IF(TEMP. LT. A 1) GO TO 1 RELERR=U*2 ABSERR=U*200 RETURN END 32

C fun. ran: 0~1 Uniform Random Generator C Argument 'ix' is the seed of

C fun. ran: 0~1 Uniform Random Generator C Argument 'ix' is the seed of C the random number generating function. C In order to get really 'random' numbers, C initial value of ix must be an odd number. C function ran(ix) iy=ix*65539 if(iy)5, 6, 6 5 iy=iy+2147483647+1 6 yfl = iy yfl = yfl*. 4656613 E-9 ran=yfl ix=iy return end 35

C C==RANORM=================== C FUNCTION RANORM(A) COMMON IRR ! seed of random numbers A=0. DO

C C==RANORM=================== C FUNCTION RANORM(A) COMMON IRR ! seed of random numbers A=0. DO 999 II=1, 16 999 A=RAN(IRR)+A A = A-8. 0 ! A=A-(nsum/2) where nsum=16 A = A*0. 866 ! A=A*sqrt(12. /nsum) RANORM=A RETURN END 37

參考文獻 Shampine, L. F. , and M. K. Gordon, Computer Solution of Ordinary Differential

參考文獻 Shampine, L. F. , and M. K. Gordon, Computer Solution of Ordinary Differential Equation: the Initial Value Problem, W. H. Freeman and Company, San Francisco, 1975. Snell, J. L. , Introduction to Probability Theory With Computing, Prentice-Hall, Inc. , Englewood Cliffs, New Jersey, 1975. System/360 Scientific Subroutine Package Version III, Programmer’s Manual, 5 th edition, IBM, New York, 1970. 51