DELFT UNIVERSITY OF TECHNOLOGY Faculty of Electrical Engineering, Mathematics and Computer Science ANSWERS OF THE TEST NUMERICAL METHODS FOR DIFFERENTIAL EQUATIONS ( WI3097 TU AESB0 ) Thursday April 6 05, 8:30-:30. [a] The test equation is given by y = λy, and we bear in mind that the amplification factor is defined by w n+ = Q(hλ)w n. () Then for the Trapezoidal Rule, we get w n+ = w n + h (λwn + λw n+ ) = w n + hλ (wn + w n+ ). () The above equation is rewritten as w n+ ( hλ ) = wn ( + hλ ). (3) Then, using the definition of the amplification factor, we immediately have Q T (hλ) = + hλ hλ The Modified Euler Method is treated analogously, to get. (4) ŵ n+ = w n + hλw n, w n+ = w n + h (λwn + λŵ n+ ), Combining the predictor and corrector, gives predictor corrector. (5) w n+ = w n + hλ (wn + w n + hλw n ) = w n ( + hλ + (hλ) ). (6) Finally, the definition of the amplification factor implies that [b] The local truncation error is defined by Q ME (hλ) = + hλ + (hλ). (7) τ n+ (h) = yn+ z n+, (8) h
where y n+ and z n+, respectively, denote the exact solution and the numerical approximation at time t n+ under using y n. Since, we use the test equation to estimate the local truncation error, we get z n+ = Q(hλ)y n. (9) The exact solution to the test equation at time t n+ is expressed in terms of y n by y n+ = y n e λh. (0) Substitution into the definition of the local truncation error, gives τ n+ (h) = yn h (ehλ Q(hλ)) = yn (hλ) ( + hλ + h + (hλ)3 3! + O(h 4 ) Q(hλ)), () where we used the Taylor expansion of the exponential around 0. For the Trapezoidal Rule, we have Q T (hλ) = + hλ hλ + hλ + (hλ) = ( + hλ )( + hλ + (hλ ) + ( hλ )3 + O(h 4 )) = + (hλ)3 4 + O(h 4 ). Using equation (), we get after some rearrangements () τ n+ (h) = yn λ 3 h + O(h 3 ) = O(h ). (3) The Modified Euler Method is treated similarly with to give via equation () Q ME (hλ) = + hλ + (hλ), (4) τ n+ (h) = yn λ 3 h + O(h 3 ) = O(h ). (5) 6 [c] Let y = y and let y = y, then y = y = y. Hence we have y = y, y = 4y + t. (6) The two equations are linear and therewith, one can rewrite this system using a matrix representation: ( ) ( ) ( ) ( ) y 0 y 0 = +, (7) 4 0 t y y
Further, we have y (0) = y(0) = and y (0) = y (0) = 0. [d] We use h =, and let A = ( ) ( ) 0 w, w = 4 0 w, w 0 = ( ), (8) 0 where the subscript stands for the component, whereas the superscript denotes the time index. The Trapezoidal Rule gives w = w 0 + h ( ) 0 (Aw0 + Aw + ). (9) This gives (I h A)w = (I + h A)w0 + h ( ) 0. (0) Substitution of h =, gives the following linear system ( ) ( ) 4 w = 3. () 4 This system is solved by w = ( ) 0.65.4 Next, we treat the Modified Euler Method. First, we carry out the prediction step ( ) ŵ = w 0 + haw 0 = + ( ) 0 =. (3) 0 4 Subsequently, we perform the corrector step Using h =, gives w = w = w 0 + h ( ) + (( ) 0 + 0 4 4 ( Aw 0 + Aŵ + ( ) + 4 () ( )) 0. (4) ( )) 0 = 3 4 [e] The local truncation errors for both methods are approximated by. (5) τn+(h) T = yn λ 3 h, τn+ EM (h) = yn λ 3 h. (6) 6 3
From these equations, it can be seen that the errors have the same order, although the error from the Trapezoidal Rule is about twice as small as the one from the Modified Euler Method in the limit for h 0. With regard to stability, the eigenvalues of A in the present initial value problem, are given by λ = ±i. Herewith, the following amplification factors are obtained: This gives the following moduli Q T (h) = + ±ih ±ih, Q ME(h) = ± ih h. (7) Q T (h) =, Q ME (h) = ( h ) + 4h = + 4h 4 >. (8) Hence the Trapezoidal Rule is neutrally stable, whereas the Modified Euler Method is unstable. The workload is smaller for the Modified Euler Method, since no linear system needs to be solved. Although the solution of the linear system may require considerable computation time if A is a very large matrix, the issue is not very important for the present case. Therefore, the Trapezoidal Rule is to be preferred for the present system since the system is just a two-by-two set of equations. Furthermore the Modified Euler Method is instable.. (a) Consider y(x) = x, then y (x) = x and y (x) =, substitution into the differential equation yields y (x) + xy = + xx = x 3, (9) hence y(x) = x satisfies the differential equation. Next, we check the boundary conditions: y (0) = 0 = 0 and y() = = which proves that the boundary conditions are also satisfied. Hence, y(x) = x is a solution of the boundary value problem. (b) Using central differences for the second order derivative at a node x j = jh, gives y (x j ) y j+ y j + y j h =: Q(h). (30) Here y j := y(x j ). Next, we will prove that this approximation is second order accurate, that is y (x j ) Q(h) = O(h ). Using Taylor s Theorem around x = x j, gives y j+ = y(x j + h) = y(x j ) + hy (x j ) + h y (x j ) + h3 3! y (x j ) + h4 4! y (η + ), y j = y(x j h) = y(x j ) hy (x j ) + h y (x j ) h3 3! y (x j ) + h4 4! y (η ). (3) 4
Here, η + and η are numbers within the intervals (x j, x j+ ) and (x j, x j ), respectively. Substitution of these expressions into Q(h) gives y (x j ) Q(h) = O(h ). This leads to the following discretization formula for internal grid nodes: w j + w j w j+ h + x j w j = x 3 j. (3) Here, w j represents the numerical approximation of the solution y j. To deal with the boundary x = 0, we use a virtual node at x = h, and we define y := y( h). Then, using central differences at x = 0 gives Using Taylor s Theorem, gives 0 = y (0) y y h =: Q b (h). (33) Q b (h) = y(0) + hy (0) + h y (0) + h3 3! y (η + ) (y(0) hy (0) + h y (0) h3 3! y (η )) h = y (0) + O(h ). Again, we get an error of O(h ). (c) With respect to the numerical approximation at the virtual node, we get (34) w w h The discretization at x = 0 is given by = 0 w = w. (35) w + w 0 w h =. (36) Substitution of equation (35) into the above equation, yields w 0 w h =. (37) Subsequently, we consider the boundary x =. To this extent, we consider its neighboring point x n, here substitution of the boundary condition w n = y() = y n = into equation (3), gives w n + w n h + x n w n = x 3 n + h = ( h)3 + h. (38) This concludes our discretization of the boundary conditions. In order to get a symmetric discretization matrix, one divides equation (37) by. 5
Next, we use h = /3, then, from equations (3, 37, 38), one obtains the following system 9w 0 9w = 9w 0 + 8 3 w 9w = 53 7 (39) 9w + 8 3 w = 97 7. (d) The truncation errors from the virtual grid point and internal points contain a third- and fourth order derivative, respectively (see part b). Since the exact solution is given by y(x) = x, the third and fourth order derivatives are zero. Hence, the error is zero at all grid points. Therefore, the numerical solution is given by w 0 = y 0 = 0, w = y = /9 and w = y = 4/9. Remark: This numerical solution can also be obtained from the solution of system (39). (e) Consider an interval of integration [x j, x j ], then the Rectangle Rule reads The composed integration rule is derived by I R j = hf(x j ), h = x j x j. (40) I R = h(i R + I R +... + I R n ) = h(f(x 0 ) +... + f(x n )), (4) which yields I R = 3 (0 + ( 3 ) + ( 3 ) ) = 5 7. (4) (f) For the interval of integration [x j, x j ] the Trapezoidal Rule is The composed integration rule is derived by I T = h(i T + I T +... + I T n ) = h( f(x 0) I T j = h (f(x j ) + f(x j )). (43) + f(x ) +... + f(x n ) + f(x n) ), (44) which leads to I T = 3 (0 + ( 3 ) + ( 3 ) + ) = 9 54. (45) (g) For a general number of subintervals, say n, the magnitude of the composed Rectangle- and Trapezoidal Rules, is bounded from above by ε R h max x [0,] y (x) h = n, ε T h max x [0,] y (x) h 6 = 6n. (46) 6
Here, the exact solution y(x) = x was used. Hence, the error from the Trapezoidal Rule is much smaller. Furthermore, from the composed Rules, it is easy to see that the number of function evaluations for the composed Rectangle- and Trapezoidal Rules is given by n and n +, respectively. Since n + lim n n =, (47) it follows that the amount of work for the Trapezoidal Rule is not significantly higher than it is for the Rectangle Rule. Hence, it is more attractive to use the Trapezoidal Rule. 7