Presentation is loading. Please wait.

Presentation is loading. Please wait.

Komputasi Numerik: Integrasi dan Differensiasi Numerik Agus Naba Physics Dept., FMIPA-UB.

Similar presentations


Presentation on theme: "Komputasi Numerik: Integrasi dan Differensiasi Numerik Agus Naba Physics Dept., FMIPA-UB."— Presentation transcript:

1 Komputasi Numerik: Integrasi dan Differensiasi Numerik Agus Naba Physics Dept., FMIPA-UB

2 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 2 Ordinary Differential Equation Ordinary Differential Equation (ODE) is a differential equation in which all dependent variables are functions of a single independent variable.

3 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 3 ODE’s Problem First-order Ordinary Differential Equation (ODE):

4 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 4 Euler’s Method

5 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 5 tntn t n+1 It enables us to calculate all of y n = y (t n ), given y(t 0 ). y(t) ynyn Slope:

6 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 6 Numerical Errors Truncation Errors, depending on numerical methods Round-off Errors, depending on capability of computer in storing floating-point number

7 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 7 Truncation Errors The curve y(t) is not generally a straight-line between the neighbouring grid-times t n and t n+1 as assumed. According to Taylor Series: O(  t 2 ) Truncation Error Each step incurs truncation error ~  t 2 Net truncation errors of Euler’s Method ~  t

8 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 8 Round-off Errors For every type of computer, there is a charasteristic number, , which defined as the smallest number which when added to a number of order unity gives rise to a new number. For example:  = 2.2 x 10 -16 (for double precision number in IBM-PC )  = 1.19 x 10 -7 (for single precision number in IBM-PC ) The net round-off errors of Euler’s Method   /  t.

9 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 9 Net Numerical Errors of Euler’s Method At large  t, the error is dominated by the truncation errors, whereas the round-off errors dominates at small  t. Minimum net numerical errors are achieved when

10 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 10 tt   t~  1/2  ~  1/2

11 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 11 t y(0)=1 Numerical Instalibilities

12 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 12 Solusi Numerik Numerical Instabilities y(0) t t

13 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 13 Defect of Euler’s Method Not generally used in scientific computing: Truncation errors is far larger than other, more advanced, methods. Too prone to numerical instabilities

14 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 14 Main reason of large truncation errors: Euler’s method only evaluates derivative at the beginning of the interval [t n,t n+1 ], i.e., at t n. ( Very asymetric with respect to the beginning and the end of the interval)

15 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 15 tntn t n+1 t n + h /2 h y(t) Runge-Kutta (RK) Methods k1k1 k2k2 ynyn f1f1 f2f2 y(t) k 1 /2 The 2 nd order RK Method Euler’s Method

16 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 16 Modified Euler’s Method tntn t n + h h y(t) f1f1 ynyn k1k1 f2f2 k2k2 (k 1 +k 2 )/2 y n+1 = y n + (k 1 +k 2 )/2 Modified Euler’s Method

17 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 17 tntn t n + h/2t n + h f1f1 f2f2 f3f3 f4f4 The 4 th order RK method

18 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 18 The 4 th order RK method

19 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 19

20 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 20 Net Numerical Errors of RK Methods

21 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 21 orderh min  min 11.5 x 10 -8 26.1 x 10 -6 3.7 x 10 -11 31.2 x 10 -4 1.8 x 10 -12 47.4 x 10 -4 3.0 x 10 -13 52.4 x 10 -3 9.0 x 10 -14 RK Methods Performance on IBM-PC for double precision h min increases and  min decreases as order gets larger, but needs more computational effort.

22 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 22 Example

23 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 23 Global integration errors associated with Euler's method (solid curve) and the 4 th order Runge-Kutta method (dotted curve) plotted against the step- length h. Single precision calculation. err = y analitic -y numeric

24 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 24 Global integration errors associated with Euler's method (solid curve) and the 4 th order Runge-Kutta method (dotted curve) plotted against the step-length h. Double precision calculation.

25 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 25 Adaptive Integration Method Consider the following ODE: Analitic solution:

26 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 26 Global integration error associated with a xed step-length (h = 0:01), 4 th order RK method, plotted against the independent variable, t, for a system of o.d.e.s in which the variation scale-length decreases rapidly with increasing t. Double precision calculation. err = x analitic -x numeric

27 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 27 It can be seen that, although the error starts off small, it rises rapidly as the variation scale-length of the solution decreases (i.e., as t increases), and quickly becomes unacceptably large. Of course, we could reduce the error by simply reducing the step-length, h. However, this is a very inefficient solution. The step-length only needs to be reduced at large t. There is no need to reduce it, at all, at small t. Solution: h should be large at small t but needs to be reduced at large t

28 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 28 The step-length h should be increased if the truncation error per step is too small, and vice versa, in such a manner that the error per step remains relatively constant at  0.

29 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 29 Global integration errors associated with fixed step-length (h = 0.01), 4 th order RK method (solid curve) and a corresponding adaptive method (0 = 10 -8 ) (dotted curve), plotted against the independent variable, t, for a system of o.d.e.s in which the variation scale-length decreases rapidly with increasing t. Double precision calculation.

30 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 30 Differentiation An object is moving through space, its position as a function of time x(t) is recorded in a table. Problem: Determine the object’s velocity v(t)=dx/dt and acceleration a(t)=d 2 x/dt 2

31 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 31 Method: Numeric Even a computer runs into errors with such a method because of its subtraction operations: the numerator tends to fluctuate between 0 and the machine precision  as the denominator approaches zero.

32 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 32 Method: Forward Difference (FD) c denotes a computed expression.

33 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 33 xx+h f(x) FD: using two points to represent the 1 st derivative function by a straight line in the interval from x to x+h h

34 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 34 Error

35 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 35 Example of FD

36 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 36 FD solution This clearly becomes a good approximation only for small h, i.e., h << 2x

37 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 37 Method: Central Difference (CD)

38 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 38 x-h/2 xx+h/2 f(x) CD: using two points to represent the function by a straight line in the interval from x-h/2 to x+h/2 h

39 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 39 Error

40 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 40 Example of CD

41 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 41 CD solution CD Method gives the exact answer regardless of the size of h !

42 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 42 Method: Extrapolated Difference (ED) The error in FD ~ h The error in CD ~ h 2 The error in ED ~ h 4

43 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 43

44 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 44 x-h/2 x x+h/2 f(x) x-h/4 x+h/4 h h/2

45 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 45 Extrapolated Difference

46 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 46 x-h/2 x x+h/2 f(x) x-h/4 x+h/4 h h/2

47 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 47 Error

48 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 48 A Good Way of Computing for ED It reduces the loss of precision that occurs when large and small numbers are added together, only to be subtracted from other large numbers. Subtract the large number from each other and then add the difference to the small numbers !

49 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 49 Attention ! Regardless of the algorithm, evaluating the derivative of f(x) at x requires us to know the values of f surrounding x ! HOW ? Once we have the derivative of f(x) at x, USE the integration methods, ex., RK Method, to approximate the values of f surrounding x !

50 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 50 Error Analysis The approximation/truncation errors in numerical differentiation decrease with decreasing step size h while roundoff errors increase with a smaller step size. Total error is minimum if minimum. This occurs when

51 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 51 Roundoff Error The limit of roundoff error is essentially machine precision:

52 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 52 Truncation Errors Truncation Error of FD: Truncation Error of CD:

53 AGUS NABA-Computational Physics-Physics. Dept., FMIPA-UB 53 Best h The h value for which roundoff and truncation errors are equal is Ex., for single precision  10 -7 for f(x)=e x or cos(x) h fd  0.0005 and h cd  0.01


Download ppt "Komputasi Numerik: Integrasi dan Differensiasi Numerik Agus Naba Physics Dept., FMIPA-UB."

Similar presentations


Ads by Google