356 COMPUTER BASED NUMERICAL AND STATISTICAL TECHNIQUES () 4003 , khfxhyk =++ ()( ) 0.2 0 0.2 1 0.0198 =+ − 0.039208= ∴ () () 0 1234 1 0.2 2 2 6 yykkkk =+ +++ ()( )( ) =+ +− +− +− 1 1 0 2 0.02 2 0.0198 0.039208 6 1.0000 0.198013=− = 0.9801986 ≅ 0.9802 The exact value of y(0.2) is 0.9802. Example 3. Solve the equation () yxy ′ =+ with y 0 = 1 by Runge-Kutta rule from x = 0 to x = 0.4 with h = 0.1. Sol. Here () =+ = , , 0.1fxy x yh , given 0 1 y = when 0 0. x = We have, () 100 , khfxy = () 0.1 0 1 0.1 =+= 1 200 , 22 k h khfx y =++ () 0.1 0.05 1.05 =+ 0.11= 2 300 , 22 k h khfx y =++ () 0.1 0.05 1.055 =+ 0.1105= () 4003 , khfxhyk =++ () 0.1 0.1 1.1105 =+ 0.12105= () () 101234 0.1 1 22 6 x yy y k k kk = = =+ +++ () 1 1 0.1 0.22 0.2210 0.12105 6 =+ + + + 1.11034= Similarly for finding () 2 0.2 yyx == , we get () () 111 0.1 0.1 1.11034 0.121034 khfxy == += 1 211 , 22 k h khfx y =++ [] 0.1 0.15 1.11034 0.660517 0.13208 =++ = 2 311 , 22 k h khfx y =++ [] 0.1 0.15 1.11034 0.06604 0.13208 =++ = NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATION 357 () =++ 4113 , khfxhyk [] 0.1 0.20 1.11034 0.13263 0.14263 =++ = ∴ () () 211234 0.2 1 22 6 x yy y k k kk = = =+ +++ () 1 1.11034 0.121034 2 0.13208 0.13263 0.14429 1.2428 6 =+ + ++ = Similarly, for finding () 3 0.3 yyx == , we get () () ==+= 122 0.1 0.2 1.2428 0.14428 khfxy 1 222 , 22 k h khfx y =++ [] 0.1 0.25 132428 0.07214 0.15649 =++= 2 322 , 22 k h khfx y =++ [] 0.1 0.25 1.2428 0.07824 0.15710 =++ = () 4223 , khfxhyk =++ [] 0.1 0.30 1.2428 0.15710 0.16999 =++ = ∴ () () 321234 0.3 1 22 6 x yy y k K Kk = = =+ +++ 0.13997= Similarly, for finding () 4 0.4 yyx == , we get () [] 1 0.1 0.3 1.3997 0.16997 k =+= ⇒ 1 0.16997 k = () [] 2 0.1 0.35 1.3997 0.08949 0.18347 k =++= ⇒ 2 0.18347 k = () [] =++= 3 0.1 0.35 1.3997 0.9170 0.18414 k ⇒ 3 0.18414 k = () [] 4 0.1 0.4 1.3997 0.18414 0.19838 k =++= ⇒ 1 0.19838 k = ∴ () 4 1 1.3997 0.16997 2 0.18347 0.18414 0.19838 6 y =+ + + + 4 1.5836 y = . Ans. Example 4. Given dy yx dx =− with y(0) = 2, find y(0.1) and y(0.2) correct to 4 decimal places. Sol. We have 00 0, 2, 0.1 xy h=== Then, we get () 100 , khfxy = () 0.1 2 0 0.2 =−= 358 COMPUTER BASED NUMERICAL AND STATISTICAL TECHNIQUES 1 200 , 22 k h khfx y =++ 0.2 0.1 0.1 2 0 0.205 22 =+−+= 2 300 , 22 k h khfx y =++ 0.205 0.1 0.1 2 0 0.20525 22 =+−+= () 4003 , khfxhyk =++ [] 0.1 2 0.20525 (0 0.1) 0.210525 =+ −+= Therefore, [] 0 1234 1 22 6 yy k k k k =+ + + + 2 0.2051708 2.2051708=+ = ⇒ () 0.1 2.2052y = Corect to 4 decimal places. For () 0.2y , we have 0 0.1, x = 0 2.2052 y = , we get () 100 , khfxy = () 0.1 2.2052 0.1 0.21052 =−= 1 200 , 22 k h khfx y =++ 0.21052 0.1 0.1 2.2052 0.1 0.216046 22 =+−+= 2 300 , 22 kh khfx y =++ 0.216046 0.1 0.1 2.2052 0.1 0.2163223 22 =+−+= () 4003 , khfxhyk =++ () 0.1 2.2052 0.2163223 0.1 0.1 0.22215223 =+−+= Hence, () [] 1234 1 0.2 2.2052 2 2 6 ykkkk = + +++ 2.2052 0.2162348=+ 2.4214= . Ans. Example 5. Solve 2 2 dy xy dx =− with y(0) = 1 and h = 0.2 on the interval [0.1] using Runge-Kutta fourth order method. NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATION 359 Sol. As per given, we have 0 0, x = 0 1 y = , 0.2h = () 100 , khfxy = ()()() 2 20.2 0 1 0 =− = 1 200 , 22 k h khfx y =++ () () 2 0.2 20.2 1 0.4 2 =− =− 2 300 , 22 k h khfx y =++ () () 2 0.2 2 0.2 0.98 0.38416 2 =− =− () 4003 , khfxhyk =++ ()()( ) 2 22 0.2 0.2 0.961584 0.0739715 =− =− Hence, () [] 01234 1 0.2 2 2 6 yykkkk =+ +++ [] 1 1 0 0.08 0.076832 0.0739715 6 =+ − − − 0.9615328= Now, we have 11 0.2, 0.9615328, 0.2, xy h== = we get () 111 , khfxy = ()()( ) 2 2 0.2 0.2 0.9615328 0.0739636 =− =− 1 211 , 22 k h khfx y =++ ()()( ) =− = 2 2 0.2 0.3 0.924551 0.1025754 2 311 , 22 k h khfx y =++ = – 2(0.2)(0.3)(0.9102451) 2 = 0.0994255 k 4 = hf(x 1 + h, y 1 + k 3 ) ()()( ) 2 2 0.2 0.4 0.8621073 0.1189166 =− =− Thus, () =++++ 11234 1 0.4 2 2 6 yykkkk [] 1 0.9615328 0.0739636 0.2051508 0.1988510 0.1189166 6 =+−−−− 0.8620525= 360 COMPUTER BASED NUMERICAL AND STATISTICAL TECHNIQUES Similarly, we can obtained () 0.6 0.7352784y = () 0.8 0.6097519y = () 1.0 0.500073y = . Ans. Example 6. Solve , dy yz x dx =+ =+; dz xz y dx Given that y(0) = 1, z(0) = –1 for y(0.1), z(0.1). Sol. Here, () 1 ,, f xyz yz x =+ =+ 2 (, ,) fxyz xzy 000 0.1, 0, 1, 1 hxyz====− ()() ==+=− 11000 000 , , 0.1 k hfxyz hyz x ()() 12000 000 ,, 0.1 l hfxyz hxz y ==+= 11 210 0 0 ,, 222 klh khfx y z =+++ () 1 0.05, 0.95, 0.95 0.08525 hf =−=− 11 220 0 0 ,, 222 kl h lhfx y z =+++ 2 (0.05, 0.95, 0.95) 0.09025 hf=−=− 22 310 0 0 ,, 222 kl h khfx y z =+++ () 1 0.05, 0.957375, 0.954875 0.0864173 hf =−=− 22 320 0 0 ,, 222 kl h lhfx y z =+++ 2 (0.05, 0.957375, 0.954875 0.0864173 hf=−=− k 4 = hf 1 (x 0 + h,y 0 + h 3 , z 0 + l 3 ) = –0.073048 l 4 = hf 2 (x 0 + h, y 0 + h 3 , z 0 + l 3 ) = + 0.0822679 () = +++=− 1234 1 2 2 0.0860637 6 kkkkk () 1234 1 2 2 0.0907823 6 lllll =+++= () 10 0.1 1 0.0860637 0.9139363 yy yk ==+=− = () ==+=−+ =− 10 0.1 1 0.0907823 0.9092176 zz zk NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATION 361 7.7 MILNE’S PREDICTOR-CORRECTOR METHOD Predictor-Corrector Methods Predictor-Corrector formulae are easily derived but require the previous evaluation of y and () 1 , yfxy = at a certain number of evenly spaced pivotal point (discrete points of 1 x of x-axis) in the neighbourhood of 0 . x In general the Predictor-Corrector methods are the methods which require the values of y at 12 , , nn n xx x −− For computing the value of y at 1n x + . A Predictor formula is used to predict the value of 1n y + . Now we discuss Milne’s method which is known as Predictor-Corrector methods. Milne’s Method The method is a simple and eresonable accurate method of solving the ordinary first order differential equation numerically. To solve the differential equation () , dy yfxy dx ′ == by this method we first obtain the approximate value of 1n y + by Predictor formula and then improve the value of 1n y + by means of a corrector formula. Both these formulas can be derived from the Newton forward interpolation formula as follows: From Newton’s formula, we have () ( ) () () () () − =+= +∆+ ∆ × 2 000 0 1 12 uu fx fx uh fx ufx fx () 3 0 (1)(2) 123 uu u fx −− +∆+ ×× (1) where 0 , xx u h − = or 0 . xx uh=+ Putting () ′ = yfx and () 00 yfx ′ = in the above formula, we get () ()() ()()() 23 4 00 0 0 0 112123 12 123 1234 uu uu u uu u u yyuy y y y −−−−−− ′′ ′ ′ ′ ′ =+∆+ ∆ + ∆ + ∆ × ×× ××× (2) Intergrating (2) from 0 x to 0 4 xh+ i.e. from 0u = to 4u = , we get () ()() 04 0 4 23 00 0 0 0 112 26 h x x uu uu u ydx h y u y y y + −−− ′′′ ′ ′ =+∆+ ∆+ ∆ ∫∫ 4 0 (1)(2)(3) ] 24 uu u u ydu −−− ′ +∆ (3 hdu = dx) which gives 0 0 23 4 00 0 0 04 20 8 28 48 3390 xxh yyhhy y y y + ′′ ′ ′ ′ − = +∆+∆ +∆+∆ [considering upto fourth differences only] Using 1,E∆= − we get () () () 23 4 40 0 0 0 0 0 20 8 14 48111 3345 yyhy E y E y E y y ′′ ′ ′′ −= + − + − + − +∆ 362 COMPUTER BASED NUMERICAL AND STATISTICAL TECHNIQUES ⇒ [] 2 40 12 3 0 414 22 345 h yy yy y y ′′ ′ ′ −= −+ +∆ (3) This is known as Milne’s predictor formula. The corrector formula is obtained by integrating (2) from x 0 to x 0 + 2h i.e., from u = 0 to u = 2. ydx x xh 0 0 2 + z = hyuy uu ydu′+ ′+ ′+ F H G I K J z 00 2 0 0 2 1 2 ∆∆ – bg ⇒ y 2 – y 0 = hy y y y22 1 3 1 90 00 2 0 4 0 ′+ ′+ ′ ′ L N M O Q P ∆∆ ∆ – Using 1E∆= − , and simplifying we get [] 4 20 0 12 0 4 390 hh yy y yy y ′′′ ′ =+ + + −∆ (4) Expression (4) is called Milne’s corrector formula. The general forms of equations (3) and (4) are [] 13 21 4 22 3 nn nn n h yy yy y +− −− ′′ ′ =+ ++ (5) and [] 11 1 1 4 3 nn n nn h yy y yy +− − + ′′′ =+ ++ (6) i.e., [] 321 1 4 22 3 nnnn n h yy yy y −−− + ′′ ′ −= ++ (7) and [] 11 1 1 4 3 nn n nn h yy y yy +− − + ′′′ =+ ++ (8) In terms of f the Predictor formula is [] 321 1 4 22 3 nnnn n h yy ff f −−− + =+ −+ (9) and the corrector formula is [] 11 1 1 4 3 nn n nn h yy f ff +− − + =+ ++ (10) Example 7. Tabulate by Milne’s method the numerical solution of dy xy dx =+ with initial conditions x 0 = 0, y 0 = 1, from x = 0.20 to x = 0.30. Sol. Here yxy ′ =+ 1 , , , , yyyyyyyy ′′ ′ ′′′ ′′ ′′′′ ′′′ ′′′′′ ′′′′ =+ = = = Hence, 000 011 yxy ′ =+=+= 00 1112 yy ′′ ′ =+ +=+= 00 2 yy ′′′ ′′ == 00 2, 2 yy ′′′′ ′′′′′ == Now taking 0.05,h = we get 1 1.1026, y = 2 1.2104, y = 3 1.3237 y = NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATION 363 Using Milne’s Predictor formula, we get () 40 12 3 4 22 3 h yy yy y ′′ ′ =+ −+ () [] 40.05 1 2.2052 1.2104 2.6474 1.2428 3 =+ − + = 44 4 0.2 1.2428 1.4428 yxy ′ =+= + = Using corrector formula, we get [] 42 2 34 4 3 h yy y yy ′′′ =+ + + () [] 0.05 1.1104 1.2104 5.2948 1.4428 3 =+ ++ 1.2428= which is the same as the predicted value. ∴ 40.20 1.2428 yy== and 4 1.4428 y ′ = and putting n = 4, h = 0.05, we get [] 51 23 4 4 22 3 h yy yy y ′′ ′ =+ −+ [] 4(0.05) 1.0526 2.4208 1.3237 2.8856 3 =+ −+ 1.3181= 555 0.25 1.3181 1.5681 yxy ′ =+= + = . Using Milne’s corrector formula, we get 5 53 3 4 4 3 h yy y yy ′ ′′ =+ + + () [] 0.05 1.1737 1.3237 5.7712 1.5681 3 =+ ++ 1.3181= which is the same as the predicted value. ∴ 50.25 1.3181 yy== and 5 1.5681 y ′ = Again putting 5n = , 0.05h = and using Milne’s predictor formula, we get [] 62 34 5 4 22 3 h yy yy y ′′ ′ =+ −+ () [] 40.05 1.1104 2.6474 1.4428 3.1362 3 == −+ 1.3997= 6 0.3 1.39972 1.6997 y ′ =+ = which is corrected by [] 64 4 56 4 3 h yy y yy ′′′ =+ + + () [] 0.05 1.2428 1.4428 6.2724 1.6997 1.3997 3 =+ ++ = 364 COMPUTER BASED NUMERICAL AND STATISTICAL TECHNIQUES which is same as the predicted value. ∴ 60.30 1.3997 yy== and 6 1.6997 y ′ = The result can be put in the tabular form x 0.20 0.25 0.30 y 1.2428 1.3181 1.3997 y ′ 1.4428 1.5681 1.6997 Example 8. Compute y(2) if y(x) is the solution of () dy 1 =x+y dx 2 using Milne Predictor-corrector method. Given () () () () y 0 = 2, y 0.5 = 2.6336, y 1.0 = 3.595, y 1.5 = 4.968. Sol. Here, we have 00 0, 2 xy== () 0 1 02 1 2 f =+= 11 0.5, 2.636 xy=− = () 1 1 0.5 2.636 1.568 2 f =+ = 22 1, 3.595 xy== () 2 1 1 3.595 2.2975 2 f =+ = 33 1.5, 4.968 xy== () 3 1 1.5 4.968 3.234 2 f =+ = Using Predictor formula, we get y 4 = y 0 + 4 3 h (2f 1 – f 2 + 2f 3 ) = 2.0 + 405 3 × . (2 × 1.568 – 2.2975 + 2 × 3.234) 6.871= and () 444 1 2 6.871 4.4335 2 fxy =+= + = Using corrector formula, we get [] 42 2 34 4 3 h yy f ff =+ + + () 0.5 3.595 2.2975 4 3.234 4.4355 3 =+ +×+ 6.873166=≈ 6.8732 Thus, corrected () () 444 11 2.0 6.8732 4.4366 22 fxy =+= + = Again, using Corrector formula, we get () 42 2 34 4 3 h yy f ff =+ + + () 0.5 3.595 2.2975 4 3.234 4.4366 3 =+ +×+ 6.87335 6.8734=≈ NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATION 365 Example 9. The differential equation dy dx = 1 + y 2 satisfies the following sets of values of x and y. x 0 0.2 0.4 0.6 y 0 0.2027 0.4228 0.6871 Sol. Firstly, we calculate the following f 0 =1 + y 0 2 = 1 f 1 =1 + y 1 2 = 1.0411 f 2 =1 + y 2 2 = 1.1787 f 3 =1 + y 3 2 = 1.4681 Using Predictor formula, we get () =+ −+ 40 12 3 4 22 3 h yy ff f () () 40.2 0 2 1.0411 1.1787 2 1.4681 3 × =+ − + 1.0239= ⇒ () =+ =+ = 2 2 44 1 1 1.0239 2.0480 fy Using Corrector formula, we have [] 42 2 34 4 3 h yy f ff =+ + + () 0.2 0.4228 1.1787 4 1.4681 2.0480 3 =+ +×+ 1.0294= ⇒ () 0.8 1.0294y = The corrected value of 2 44 1 2.0597 fy=+ = Now, to find () 1f we use predictor formula such that y 5 = y 1 + 4 3 h (2f 1 – f 3 + 2f 4 ) = 0.2027 + 402 3 × . [2(1.1787) – 1.4681 + 2(2.0597)] = 1.5384 and f 5 =1 + y 5 2 = 1 + (1.5384) 2 = 3.3667 Finally using corrector formula, we get [] 53 3 45 4 3 h yy f ff =+ + + () () 0.2 0.6841 1.4681 4 2.0597 3.3667 3 =+ + + 1.5556733 1.5557== . . 1.3997 3 =+ ++ = 364 COMPUTER BASED NUMERICAL AND STATISTICAL TECHNIQUES which is same as the predicted value. ∴ 60.30 1.3997 yy== and 6 1.6997 y ′ = The result can be put in the tabular form x 0.20. differential equation () , dy yfxy dx ′ == by this method we first obtain the approximate value of 1n y + by Predictor formula and then improve the value of 1n y + by means of a corrector formula the previous evaluation of y and () 1 , yfxy = at a certain number of evenly spaced pivotal point (discrete points of 1 x of x-axis) in the neighbourhood of 0 . x In general the Predictor-Corrector