0% found this document useful (0 votes)
401 views

Maths 402

Vnsgu maths 402 book numerical analysis

Uploaded by

Dhruvin Vyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
401 views

Maths 402

Vnsgu maths 402 book numerical analysis

Uploaded by

Dhruvin Vyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 69
MATHS 402 NUMERICAL ANALYSIS Il VEER NARMAD SOUTH GUJARAT UNIVERSITY, SURAT. SYLLABUS FOR B.Sc.((MATHEMATICS) SEMESTER -IV MTH-402 (Numerical Analysis—I)* Effective from June 2018 Marks:70 (20 internal + 50 external) (3 Hours / Week - Credits : 3) Unit I: Finite difference with unequal interval, Lagrange’s Interpolation Formula, Divided Differences, Newton’s General Interpolation Formula. Unit II: Numerical Differentiation: 1‘ and 2™ order derivatives based on Newton’s forward andbackward difference interpolation formulae. Unit III: Numerical Integration: General Integration formula, Trapezoidal Rule, Simpson’s 1/3-Rule, Simpson’s 3/8-Rule. Unit IV: Solution of Ordinary Differential Equations by Taylor’s series method, Picard’s approximation method, Euler’s method. The course is covered by the following reference books : 1. S.S. Sastry : Introductory methods of Numerical Analysis, Prentice-Hall of India Pvt. Ltd.; 4" Edition. 2. M. K. Jain, Iyenger, Jain: Numerical Methods for Scientific and Engineering Computations, New Age International Ltd. 3. Goel, Mittal : Numerical Analysis, Pragati Prakashan, Meerut. 4, Kaiser A. Kunz : Numerical Analysis, McGraw Hill Book Co., London. 5. James I. Buchanan, Peter R. Turner : Numerical Methods and Analysis, McGraw Hill Book Co., London. CONTENTS 3.9 Interpolation with Unevenly Spaced Points (101) 3.9.1 Lagrange's Interpolation Formula (101) 3.9.2 Error in Lagrange’s Interpolation Formula (107) 3.9.3 Hermite's Interpolation Formula (108) 3.10 Divided Differences and Their Properties (111) 3.10.1 Newton's General Interpolation Formula (113) 3.10.2 Interpolation by Iteration (115 ) 3.11 Inverse Interpolation (116) 3.12 Double Interpolation (118) Exercise 3 (119) Answers to Exercise 3 (125) 6.1 Introduction (207) 6.2 Numerical Diferentiation (207) 6.2.1 Errors in Numerical Differentiation (212) 6.2.2 Cubic Splines Method (214) 6.2.3 Differentiation Formulae with Function Values (216) 6.3 Maximum and Minimum Values of a Tabulated Function (217) 6.4 Numerical Integration (218) 6.4.1 Trapezoidal Rule (219) 6.4.2 Simpson's 1/3-Rule (221) 6.4.3 Simpson's 3/8-Rule (222) Exercise 6(247) Answers to Exercise 6(253) 8.1 Introduction (302) 8.2 Solution by Taylor's Series (303) 8.3 Picard's Method of Successive Approximations (305) 8.4 Euler's Method (307) 8.4.1 Error Estimates for the Euler Method (308) 8.4.2 Modified Euler's Method (310) Exercise 8 (335) Answers to Exercise 8 (339) SECTION 3.9: Interpolation with Unevenly Spaced Points 101 This example verifies the result of Section 3.7.5 that Everett’s formula turncated after second differences is equivalent to Bessel’s formula truncated after third differences. When the fourth difference contribution becomes significant (i.e. when they exceed 20 units in magnitude), Everett's formula will be easier to apply since it uses only the even order differences. 3.9 INTERPOLATION WITH UNEVENLY SPACED POINTS In the preceding sections, we have derived interpolation formulae of utmost importance and discussed their practical use in some detail. But, as is well known, they possess the disadvantage of requiring the values of the independent variable to be equally spaced. It is therefore desirable to have interpolation formulae with unequally spaced values of the argument. We discuss, in the present section and the next, four such formulae: (i) Lagrange’s interpolation formula which uses only the function values, (ii) Hermite’s interpolation formula which is similar to Lagrange’s formula, (iii) Newton’s general interpolation formula which uses what are called divided differences and (iv) Aitken’s method of interpolation by iteration. 3.9.1 Lagrange’s Interpolation Formula Let (x) be continuous and differentiable ( + 1) times in the interval (a, 5). Given the (n+ 1) points (x, ¥o)s (21s J1)s -++s Gin Jn) Where the values of x need not necessarily be equally spaced, we wish to find a polynomial of degree n, say L,(x), such that 1, (4) = yi) = yj, f=0,1,...,0 (3.28) Before deriving the general formula, we first consider a simpler case, viz., the equation of a straight line (a linear polynomial) passing through two points (xo, yo) and (x1, y1). Such a polynomial, say L;(x), is easily seen to be 1) = y+ 5, HH) mH AAO t+49OK 1 => Ay G29) 4=0 where h(ye224 and (y= 2, G.30) 4-H 4% 102 Cuarter 3: Interpolation From Eq. (3.30), it is seen that H(a)=1 — H(H)=0, Alm) =0, A(m)=1. These relations can be expressed in a more convenient form as Lif izj Ia) = ix) {c if iz jf 631) The U(x) in Eq, (3.29) also have the property 1 xy H-H H—% G(X) =h() +h (= (3.32) 0 is Equation (3.29) is the Lagrange polynomial of degree one passing through two points (xo, ¥) and (x;, y,). In a similar way, the Lagrange polynomial of degree two passing through three points (xo, Yo). (1s 31) and (x2, 2) is written as 2 1,9 =>) 19 i=0 __(x- x) (x= 9) (x= %) (x- 9) ) (x= 4) = Capa) Og = 99) Og =p) ma)” gH) (9 (3.33) where the /(x) satisfy the conditions given in Eqs. (3.31) and (3.32). To derive the general formula, let Lj (3) = ag + xt aX" $2 ay x” (3.34) be the desired polynomial of the nth degree such that conditions given in Eq. (3.28) (called the interpolatory conditions) are satisfied. Substituting these conditions in Eq. (3.34), we obtain the system of equations 2 n Yo = ay + AM + XQ t+ anNG Jy ay + aya + ayxP tot ayy! Vo = ag + Xp + a_XZ tet a_Xy (3.35) Vn = Ay + Ny + KH Hot XT Secrion 3,9: Interpolation with Unevenly Spaced Points 103 The set of Eqs. (3.35) will have a solution if Lom x ee 1 x ape xf uo ")20. (3.36) 1 Xp xe xh The value of this determinant, called Vandermonde’s determinant, is (a9 — 44) (9 — Hp) «0+ (49 — Hq) (4 = 49) 00 (= Hq) oe (= Ap) Eliminating ao, a), ..., a, from Eqs. (3.34) and (3.35), we obtain L() 1 x ow x oe ee, ee woL ake xt =O, (37) Jo Lh Xho XH which shows that L,(x) is a linear combination of yo, yy, 2 «+s Yn Hence we write B=>. May, (3.38) i=0 where /(x) are polynomials in x of degree n. Since L,(x,) = yy for j = 0, 1, 2, 5 7, Eq. (3.32) gives which are the same as Eq. (3.31). Hence /(x) may be written as = (x= 9) (X= 4). (8 Xe) (X= Xt)» R= Xn) | G39) (4 —%) 04 — 4) Og Xe) 4 > Kian) «OG Ma) which obviously satisfies the conditions (3.31). If we now set T1 ye (9) = (x= 9) (8). OH) (8) (81 jx) 9), G40) then d Tha (4) = Gn Den = (4; = ¥9) (4) — 4) --- 5 — Hig) (4) — pa) A) 3.41) 104 Crater 3: Interpolation so that Eq. (3.39) becomes Thy () 19 =i _. (3.42) Ga) Tg GD Hence Eq. (3.38) gives 2 Ba) _ 3.43 LO= > Go Ta" 6.83) which is called Lagrange’s interpolation formula, The coefficients /,(x), defined in Eq. (3.39), are called Lagrange interpolation coefficients. Interchanging x and y in Eq. (3.43), we obtain the formula n Tha (y) L(y) =, ——4 = x, (3.44) 7 2 (y-y) Mn which is useful for inverse interpolation. It is trivial to show that the Lagrange interpolating polynomial is unique. To prove this, we assume the contrary. Let L,(x) be a polynomial, distinct from L,(x), of degree not exceeding n and such that T,(=yp 10,1, 2.0 Then the polynomial defined by M(x), where M(x) = Ly (2) - E09) vanishes at the (n +1) points x;, i=0, 1, ...,2 Hence we have M, (x) which shows that L,(x) and L,(2) are identical. A major advantage of this formula is that the coefficients in Eq. (3.44) are easily determined. Further, it is more general in that it is applicable to either equal or unequal intervals and the abscissae x9, 4,.... X» need not be in order. Using this formula it is, however, inconvenient to pass from one interpolation polynomial to another of degree one greater. The following examples illustrate the use of Lagrange’s formula. Example 3.13 Certain corresponding values of x and logy) x are (300, 2.4771), (304, 2.4829), (305, 2.4843) and (307, 2.4871). Find logjo301. From formula given in Eq. (3.43), we obtain DD 8 477)» DH 8) oy 496 acc OD 3) 6) oc —————— (2.4843) + ———_—— (2.4871) Kane (88 ae@@ °s” = 1.2739 + 4.9658 — 4.4717 + 0.7106. = 2.4786. Jog) 301 SECTION 3.9: Interpolation with Unevenly Spaced Points 105 Example 3.14 \f y, = 4, ys = 12, ye = 19 and y, = 7, find x. Using Eq. (3.44), we have C12) CAD, (C5) pci” @eD °*VM” 1,27 4 a1,27_4 2 14 7 =1.86. The actual value is 2.0 since the above values were obtained from the polynomial y(x) = x? + 3. Example 3.15 Find the Lagrange interpolating polynomial of degree 2 approximating the function y = In x defined by the following table of values. Hence determine the value of In 2.7. x y=ln x 2 0.69315 25 0.91629 3.0 1.09861 We have h(a = 2229) 2-30) _ 92 says. 0.5) (10) Similarly, we find A(x) =-(4x* —20x+24) and h(x) =2x*-9x+10. Hence Ln (x) = (2x* -11x+15) (0.69315) — (4x7 — 20.x+ 24) (0.91629) + (2x" —9x+10) (1.09861) =~0.08164x" + 0.81366x- 0.60761, which is the required quadratic polynomial. Putting x = 2.7, in the above polynomial, we obtain In 2.7 = Lp (2.7) =—0.08164 (2.7) +0.81366 (2.7) - 0.60761 = 0.9941164. Actual value of In 2.7 =0.9932518, so that | Error |= 0.0008646. 106 CuapTer 3: Interpolation Example 3.16 The function y = sinx is tabulated below x y=sinx 0 0 al 0.70711 nl2 1.0 Using Lagrange’s interpolation formula, find the value of sin (7/6). We have in Z ~ 2/60) (6-7/2) (0.70711) + (z/6—0) (@/6—z/4) a 6 (a/4—0) (w/4—nI2) (@/2—0) (a/2— 7/4) -8 ot =, (0.70710 -5 __ 4.85688 9 = 0.51743. Example 3.17 Using Lagrange’s interpolation formula, find the form of the function y (x) from the following table x y 0 -12 1 0 3 12 4 24 Since y = 0 when x = 1, it follows that.x—1 is a factor. Let p(x) = (x—1) RQ). Then R(x) = yi(r—1). We now tabulate the values of x and R(x). x Rx) 0 12 3 6 4 8 Applying Lagrange’s formula to the above table, we find (x3) (x-4) (x=0) (x-4) (x0) (x-3) P= yey) * 6-9 6-9 © Gy a-9)® = (x-3) (x4) — 2x (x—4) +2x(x-3) =x —5x+12, SECTION 3.9: Interpolation with Unevenly Spaced Points 107 Hence the required polynomial approximation to y (x) is given by yx) =(x-D) (x? -5x+12). 3.9.2 Error in Lagrange’s Interpolation Formula Equation (3.7) can be used to estimate the error of the Lagrange interpolation formula for the class of functions which have continuous derivatives of order up to (n+1) on [a, 6]. We, therefore, have _ _ — Tn (oy yi) Tq) = Fo = ©, a<é ud; + Y, WV: (3.50) a i=0 i=0 where u(x) and v(x) are polynomials in x of degree (2n + 1). Using conditions (3.49), we obtain 1, if i= utsd={) if ia y;(x) =0, for all , J (3.51) 1, if i=j uj(2) =0, for all £ way={9 ray Since u(x) and v(x) are polynomials in x of degree (2n+1), we write y)=40) IOP and y= 80) LP, (3.52) where J,(x) are given by Eq. (3.42). It is easy to see that A(x) and B(x) are both linear functions in x. We therefore write u(x) =(ax+b) OVP and v(x) = (qx+ d) U9? (3.53) Section 3.9: Interpolation with Unevenly Spaced Points 109 Using conditions Eq. (3.51) in Eq. (3.53), we obtain aay thal (3.54a) Gx;+d;=0 and aj + 21;(x) =0 (3.54b) q=l. From Eq. (3.54), we deduce =-2hj(x), b= 1+ 2x) Ih ay =-25(x), by 4% 1h(%) G55) G d;=-%, Hence Eq. (3.53) become y(a) = [2x (xy) +14 2h OP = 1-2 (x x) HDI OP (3.56a) and v(a) = (x x) LO). (3.56b) Using the above expressions for w(x) and v(x) in Eq. (3.50), we obtain finally a 2 Feng (= Y= 24) HOD LOOP y+ Y - UOP YY, G.57) i=0 i=0 which is the required Hermite interpolation formula. The following examples demonstrate the application of Hermite’s formula. Example 3.20 Find the third-order Hermite polynomial passing through the points (x, yj. 7). 1 = 0, 1. Putting n=1 in Hermite’s formula (3.57), we obtain Hg (x) =[1-2(x— 9) 4 (%)] 1h 97? Jo +2 (x 4) KODA? + (x29) Lh (I? 6 + (2-4) LOOP Since H- Hh {-% A where /, = x; — Xo. Hence _X-m _R-K _Xo% _X-% ho= ZA ATS and gay B= 8, 1 ai b@=-p and iO=7- a 110 CuapTeR 3: Interpolation Then, Eq. (i) simplifies to 2 [ Maca) eos! H,(x) =|14 | 744404 |“ s(x) [1 h ie Jo+ |e iz HK (y= 9? _ 1 Jot (x4) Sy, Gi) + (x— 4%) ie 1 H which is the required Hermite formula. Example 3.21 Determine the Hermite polynomial of degree 5, which fits the following data and hence find an approximate value of In 2.7. x yeInx — y=tlx 20 0.69315 0.5 25 0.91629 0.4000 3.0 1.09861 0.33333, The polynomials /(x) have already been computed in Example 3.15. These are (2x 11x45, (x) =—-(4x*- 200x424), (x) = 2X" -9x+10. We therefore obtain A(x) = 4x-11, A (a) =-8x+ 20, (a) =4x-9. Hence 40%) Equations (3.56) give Up (4) = (6x—11) (2x” -11x+15)", Wo (4) = (x— 2) (27 - 11415)? uy (4) = (4x —20x+ 24), ¥ (a) = (x— 2.5) (4x — 20+ 24)", up (x) = (19-6) (2x" -9x+10)", ¥ (a) = (x—3) (2x” -9x+10)”, Substituting these expressions in Eq. (3.57), we obtain the required Hermite polynomial =-3 A()=0, b(m)=3 H, (x) = (6x—11) (2x7 -11x+15)? (0.69315) + (4x7 — 20.x+ 24)? (0.91629) + (19-64) (2x* —9.x+10)? (1.09861) + (x—2) (27 -11x+15)? (0.5) + (x= 2.5) (427 —20x+ 24)"(0.4) + (x-3) (2x" -9x+10)? (0.33333). SEcTION 3.10: Divided Differences and Their Properties 111 Putting x = 2.7 and simplifying, we obtain In (2.7) = H; (2.7) = 0.993252, which is correct to six decimal places. This is therefore a more accurate result than that obtained by using the Lagrange interpolation formula. 3.10 DIVIDED DIFFERENCES AND THEIR PROPERTIES ‘The Lagrange interpolation formula, derived in Section 3.9.1, has the disadvantage that if another interpolation point were added, then the interpolation coefficients 1x) will have to be recomputed. We therefore seek an interpolation polynomial which has the property that a polynomial of higher degree may be derived from it by simply adding new terms. Newton’s general interpolation formula is one such formula and it employs what are called divided differences. It is our principal purpose in this section to define such differences and discuss certain of their properties to obtain the basic formula due to Newton. Let (4%, Yo) (is W)s +++ ns Yn) be the given (n+1) points. Then the divided differences of order 1,2, ...,” are defined by the relations: [4 %1- Lo, 41] Ls He = (3.58) po Pe Rares And [oy Ais ooo Xa % Even if the arguments are equal, the divided differences may still have a meaning. We then set x, = x9 + € so that Li, A, = Xn La, 41] = lim [49.4% +e] 630 = lim 20042) — YO) 230 € =y¥(%). if y(x) is differentiable. Similarly, Lip nee Hp] = 22, (3.59) ——__ rl (r+1) arguments 112 Cuapter 3: Interpolation From Eq. (3.58), it is easy to see that + Jo bo. a= M4 H-H H-% Again, 1 (w-n_ H-Jo [9, 4, %21= = “te walt 4—% i a +] %—% | -¥ 2-H H-%) -% = Yo + Hi (9 — 4) (9 -%) (4-9) C4 - 9) + Se . (3.60) (x2 = %) (42 — 44) Similarly it can be shown that re Vas Fis tol = Ga Capa) * Gj aa) GH) * 7 Yn . G.61) (xq — %) ++ (Xn - Xn) Hence the divided differences are symmetrical in their arguments. Now let the arguments be equally spaced so that x, — % = % — 4 =""* = %)—%,1=h. Then we obtain a au (3.62) la. al Ly, 9]-bo. 4] _ [9.21 = and in general, [Xe ml=qa a" (3.64) Neve Ml =A Yo- If the tabulated function is a polynomial of nth degree, then A” yg would be a constant and hence the nth divided difference would also be a constant. For the set of values (x,y), 7 = 0, 1, 2, ..., n, divided differences can be generated by the following statements. Section 3.10: Divided Differences and Their Properties 113 Define y (xj) = yy = DD(0, j), 7= 0, 1, 2, wy) 2 Do i= 1(1)n Do j = 0(1) (n- i) _ DDG-1,5+1)-DDG-1,7) XG +9)-X@) 3.10.1 Newton’s General Interpolation Formula By definition, we have =~ Ly = a so that . Y= Yo + (& — xo)Lx, x0] (3.65) Again [x 4] = %)-[%, ¥i] x- which gives [x, xo] = [xo x1] + (& — x1) BY, Xo, 1] Substituting this value of [x, xo] in Eq. (3.65), we obtain Y= Yo + (x = xo)[Xo. x1] + & — Xo)@ — x)E Xo, 41] (3.66) But [x a. %,4] = 220A] = Lao, a, 2] ae Mio %a] and so [x Xo 1] = Bor x1» ¥2] + O& — x2)E, Xo X12] (3.67) Equation (3.66) now gives Y= Yo + & ~ xy) Xi] + (& = Xo)K — Bo 21%] + (& = Xo) (X= Ve — DDE Xo. FE 2] (3.68) Proceeding in this way, we obtain Y= Yo + & = Xo) [Xo 1] + OX = X0)(X - x10, 41, ¥2] F(X = Xo) = XOX = X2)LXo. X15 X23] + +(e = xo) = 21) = X2) + = AWD X00 Xe + Xn) (3-69) This formula is called Newton's general interpolation formula with divided differences, the last term being the remainder term after (m+ 1) terms. After generating the divided differences, interpolation can be carried out by the following statements. 114 Cnuapter 3: Interpolation Let y be required corresponding to the value x = xp. Then = 1.0 Do i = 0(1)(n-1) factor = factor * (x, - x;) Ve = Ye + factor * DD (i + 1, 0) Next i End Example 3.22 As our first example to illustrate the use of Newton’s divided difference formula, we consider the data of Example 3.13. The divided difference table is x logio x 300 24771 0.00145 304 2.4829 0.00001 0.00140 305 2.4843 0 0.00140 307 2.4871 Hence Eq. (3.69) gives Jogyg 301 = 2.4771 + 0.00145 + (-3) (0.00001) = 2.4786, as before. It is clear that the arithmetic in this method is much simpler when compared to that in Lagrange’s method. Example 3.23. Using the following table find f(x) as a polynomial in x. x f(x) -1 3 0 -6 3 39 6 822 7 1611 The divided difference table is x 1(x) “1 3 9 oO 6 6 15 5 3 39 4 1 261 13 6 822 132 789 7 1611 SEcTION 3.10: Divided Differences and Their Properties 115 Hence Eq. (3.69) gives f(x) =3+ (x41) (-9)+x(x+1) (6) + x(x+1) (x-3) (5) + x(x+1) (x-3) (x-6) A—3x 45x" -6. 3.10.2 Interpolation by Iteration Newton’s general interpolation formula may be considered as one of a class of methods which generate successively higher-order interpolation formulae. We now describe another method of this class, due to A.C. Aitken, which has the advantage of being very easily programmed for a digital computer. Given the (n + 1) points (xo, yo), G1. ¥1)s «+s Om Yn) Where the values of x need not necessarily be equally spaced, then to find the value of y corresponding to any given value of x we proceed iteratively as follows: obtain a first approximation to y by considering the first-two points only; then obtain its second approximation by considering the first-three points, and so on. We denote the different interpolation polynomials by A(x), with suitable subscripts, so that at the first stage of approximation, we have Jo %o- Aor (4) = Yo + (X- %) [9,4 = G.70) : Rm MO Similarly, we can form Ago (x), Ag3(4),-.- Next, we form Agi2 by considering the first-three points: 1 Ant) = a-x Agi2(X) = . G.71 oe %—%|Ag2(x) x ) Similarly, we obtain Agi3(4), Agi4 (4), etc. At the nth stage of approximation, we obtain 1 Aone. aA Xn-1— * oie... nf) = (3.72) fn — Xn Sore. aaa) % The computations may conveniently be arranged as in Table 3.8 below: Table 3.8 Aitken's Scheme x y xo yo oil) m4 v Agi2(x) ‘Soa(x) Aorza(*) *2 Y2 ora(*) Aorzaa(x) Ao3(*) Aoiza(*) x3 3 oral) Soa(x) x4 Ya 116 Crarter 3: Interpolation A modification of this scheme, due to Neville, is given in Table 3.9. Neville’s scheme is particularly suited for iterated inverse interpolation. Table 3.9 Neville's Scheme x y xo Yo Soil) x n ora(x) Aya(x) Ao123(*) 2 Ya At2a(x) Aoi 234(*) 4A23(X) Ayaaa(x) x3 J3 4234(x) 434(X) x4 va As an illustration of Aitken’s method, we consider, again, Example 3.22. Example 3.24 Aitken’s scheme is x logio x 300 2.4771 2.47855 304 2.4829 2.47858 2.47854 2.47860 305 2.4843 2.47857 2.47853 307 2.4871 Hence logy 301 = 2.4786, as before. An obvious advantage of Aitken’s method is that it gives a good idea of the accuracy of the result at any stage. 3.11 INVERSE INTERPOLATION Given a set of values of x and y, the process of finding the value of x for a certain value of y is called inverse interpolation. When the values of x are at unequal intervals, the most obvious way of performing this process is by interchanging x and y in Lagrange’s or Aitken’s methods. Use of Lagrange’s formula was already illustrated in Example 3.14. We will now solve the same example by means of Aitken’s and Neville’s schemes. Aitken’s scheme (see Table 3.8) is y x 4 1.750 12 3 1.857 1.600 19 = SEctION 3.11: Inverse Interpolation 117 whereas Neville’s scheme (see Table 3.9) gives y. x 4 1 1.750 12 3 1.857 2.286 19 4 Hence both the schemes lead to the same result ultimately. In practice, however, Neville’s scheme should be preferred for the simple reason that in this scheme those points which are nearest to x, are used for interpolation at x= x,. It is, of course, important to remember that inverse interpolation is, in general, meaningful only if the function is single-valued in the interval. When the values of x are equally spaced, the method of successive approximations, described below, should be used. Method of successive approximations We start with Newton’s forward difference formula [see Eq. (3.10), Section 3.6] written as uu Vy = Jo t UAYy + At NE ty a (3.73) From this, we obtain 1 u(u-1) 9 u(u-1) (u-2) 95 | a-t|,_, wU-D,2, wu DWH2 43, 01 3.74) u an J 2 Jo 6 Bi Neglecting the second and higher differences, we obtain the first approximation to u and this, we write, as follows 1 =—(Jy - Yo). (3.75) y re Su — Yo. Next, we obtain the second approximation to w by including the term containing. the second differences. Thus, 1 -1 = 2m tat (3.76) Yo 2 where we have used the value of 1; for w in the coefficient of Ayo. Similarly, we obtain n= [yen 2 EDat yn nen ,] (3.77) 118 Ciaprer 3: Interpolation and so on. This process should be continued till two successive approximations to w agree with each other to the required accuracy. The method is illustrated by means of the following example. Example 3.25 Tabulate y = x? for x = 2, 3, 4 and 5, and calculate the cube root of 10 correct to three decimal places. x yas 4 a2 ae 2 8 19 3 27 18 37 6 4 64 24 61 5 125 Here y,=10, yy =8, Ayg =19, A? yg =18 and A’ yy =6. The successive approximations to wu are, therefore, 1 =1@-01 4 79 1f, 0.1(0.1-1) | =—| 2-————— (18) }= 0.15 * al 2 08) yet [p 245 O15-D gg) 015 15-0 (15-2 @)) 94590 19 2 6 w= [2D (s)-2 1532 (0.1532 -1) (0.1532-2) (© |-o1sa 19 2 6 pahfe nusauasain (1g) —0-1541(0.1541—1 (0.1541~2) (9 -oase We, therefore, take u = 0.154 correct to three decimal places. Hence the value of x (which corresponds to y = 10), ie. the cube root of 10 is given by xo + uh = 2.154. This example demonstrates the relationship between the inverse interpolation and the solution of algebraic equations. 3.12 DOUBLE INTERPOLATION In the preceding sections we have derived interpolation formulae to approximate a function of a single variable. For a function of two or more variables, the formulae become complicated but a simpler procedure is to interpolate with respect to the first variable keeping the others constant, then interpolate with respect to the second variable, and so on, The method is illustrated below for a function of two variables. For a more efficient procedure for multivariate interpolation, see Section 5.3. EXERCISES 119 Example 3.26 The following table gives the values of z for different values of x and y. Find z whenx = 2.5 andy = 1.5. x y 0 1 2 3 4 0 0 1 4 9 16 1 2 3 6 " 18 2 6 10 15 22 3 12 13 16 2 28 4 18 19 22 27 34 We first interpolate with respect to x keeping y constant. For x = 2.5, we obtain the following table using linear interpolation. z 6.5 8.5 12.5 18.5 24.5 mono. Now, we interpolate with respect to » using linear interpolation once again. For y = 1/5, we obtain 8.54125 _ 2 10.5 so that 2(2.5, 1.5) = 10.5. Actually, the tabulated function is z = x? +7 + y and hence 2(2.5, 1.5) = 10.0, so that the computed value has an error of 5%. 31 3.2 3.3 EXERCISES Form a table of differences for the function P(x) = 8 + 5x -7 for x = -1, 0, 1, 2, 3, 4, 5. Continue the table to obtain £(6) and f(7). Evaluate (a) 223 (b) A%(cos x) (c) Ale + I + 2)] (d) A(tan'x) (e) [22]. Locate and correct the error in the following table: x 25 3.0 3.5 4.0 45 5.0 3.5 y 432 483 5.27 5.47 6.26 6.79 7.23 120 Carter 3: Interpolation 3.4 Locate and correct the error in the following table: x 1.00 1.05 1.10 1.15 1.20 1.25 1.30 e* 2.7183 2.8577 3.0042 3.1528 3.3201 3.4903 3.6693 3.5. Prove the following: (2) Ys = Yat + Aves + Ay 3 to FA + AV omy (0) A's = Vein = "C1 Vet + "Co¥sena #0 + CD's (©) yr Hyp Ho Hn = "Cry FC AY Hoe + AMY, 3.6 From the following table, find the number of students who obtained marks between 60 and 70: Marks obtained 0-40 40-60 60-80 80-100 100-120 No. of students 250-120-100 70 50 3.7 Find the polynomi x 3 4 5 6 7 8 9 v 13 21 31 43 57 2B 91 which approximates the following values: If the number 31 is the fifth term of the series, find the first and the tenth terms of the series. 3.8 Find (0.23) and (0.29) from the following table: x 0.20 0.22 0.24 0.26 © 0.28 0.30 JS(x) 1.6596 1.6698 1.6804 1.6912 1.7024 1.7139 3.9 Prove that 3a (a) A= wd + (b) AX. = V3y5 2 3.10 From the table of cubes given below, find (6.36)° and (6.61)°. x 6.1 62 63 64 65 66 67 2x? 226981 238.328 250.047 262.144 274.625 287.496 300.763 3.11 Define the operators A, V, 6, E and E"' and show that @ AAV Yer =5Y, 5 CO) AV yy = VAY, = 5" yy 2 2 () ws = atv (@ 1+ we = (+40) (©) = (1+ AS wo Sd aes Vk Si Ske EXercIsES 121 3.12 3.13 3.15 3.1 a 3.17 3.18 3.19 3.20 3.21 Show that 1 2 82 W/2 (2-28 po] Find the missing terms in the following: x 0 5 10 15 20 25 30 y 1 3 2 73 225 2 1153 Derive expressions for the errors in Newton’s formulae of forward and backward differences. Estimate the maximum error made in any value of sin x in Example 3.6 obtained by interpolation in the range 15° sx s 40°. Certain values of x and f(x) are given below. Find f(1.235). x 1.00 1.05 1.10 1.15 1.20 1.25 Sx) 0.682689 0.706282 0.728668 0.749856 0.769861 0.788700 Prove the following relations: (a) PE =X (b) EP =p é (©) V = bE"? (@A-V= 8 (© p= cosh 2. Using Gauss’s forward formula, find the value of £(32) given that F(25) = 0.2707, #(30) = 0.3027, f(35) = 0.3386 and #(40) = 0.3794. State Gauss’s backward formula and use it to find the value of ./12525, given that {2500 = 111.8034, i519 = 111.8481, Vi520 = 111.8928, 9539 = 111.9375 and d5ag = 111.9822. State Stirling’s formula for interpolation at the middle of a table of values and find e!°! from the following table: x 17 18 19 2.0 2.1 2.2 e* 5.4739 6.0496 6.6859 7.3891 8.1662 9.0250 Using Stirling’s formula, find cos(0.17), given that cos(0) = 1, cos(0.05) = 0.9988, cos(0.10) = 0.9950, cos(0.15) = 0.9888, cos(0.20) = 0.9801, cos(0.25) = 0.9689, and cos(0.30) = 0.9553. State Bessel’s formula for interpolation and mention its limitations. Use this formula to solve the problem in 3.20. 122 Cuapter 3: Interpolation 3.22 The complete elliptic integral of the second kind is defined as kay =|" — 1 __ ae im = (" —1 _ 0 fi-msin? 6 3.23 3.24 3.25 3.26 3.27 3.28 3.29 3.30 3.31 Find (0.25) given that A(0.20) = 1.6596, &(0.22) = 1.6698, (0.24) = 1.6804, A(0.26) = 1.6912, k(0.28) = 1.7024, k(0.30) = 1.7139. Using Bessel’s formula, find y (5) given that y (0) = 14.27, y(4) = 15.81, y(8) = 17.72, and y (12) = 19.96. From Bessel’s formula, derive the following formula for midway interpolation: + (Atv, +aty. =4 ~ 1a? y, +A?) +2 Jin = 30+ W764? 94 +490) + 55 Evaluate sin(0.20) given that sin(0.15) = 0.1494, sin(0.17) = 0.1692, sin(0.19) = 0.1889, sin(0.21) = 0.2085, sin(0.23) = 0.2280. Deduce Everett’s formula from Bessel’s formula and show that Everett’s formula truncated after second differences is equivalent to Bessel’s formula truncated after third differences. Use Everett’s formula to find cos(12.5°) given that cos(0°) = 1, cos(S°) = 0.9962, cos(10°) = 0.9848, cos(15°) = 0.9659, cos(20°) = 0.9397. Using Everett’s formula, evaluate £(25) from the set of values Ff (20) = 2854, (24) = 3162, f(28) = 3544, (32) = 3992. State Lagrange’s interpolation formula and find a bound for the error in linear interpolation. Write an algorithm for Lagrange’s formula. Find the polynomial which fits the following data (-l, 7), (1, 5) and (2, 15). Find y (2) from the following data using Lagrange’s formula x 0 1 3 4 5 y 0 1 81 256 625 Let the values of the function y = sin x be tabulated at the abscissae 0, 2/4 and 2/2. If the Lagrange polynomial L(x) is fitted to this data, find a bound for the error in the interpolated value. Find a cubic polynomial which fits the data (2, -12), Cl, -8), (2, 3) and (3, 5). EXERCISES 123 3.32 3.33, 3.34 3.3! a 3.36 3.37 3.38 Show that Tr) (x= x) Tp 49) where Tye) = (¢ — xo) — xe = 39) + = ap). In complex analysis, the residue theorem is used in the evaluation of contour integrals. If a function f(z) is analytic inside and on a closed contour C, and xp, x1, X2, ..-, ¥» are simple poles inside C, then J Fedde = 2mi (sum of the residues at x9, x, 2s 34) c [The residue of f(z) at z= a is defined as lim (z — a) f(2)] an If xp, x1, X25 «+s X, are simple poles of a function y (x) which is analytic inside and an a closed contour C, then show that _ HOM yy (4) dt lo htal= 35 | (Tp Lagrange’s formula can be used to express a rational function as a sum of partial fractions (see, Stanton [1967]). Express ¥+x-3 0 = yo 0 2x — x42 as a sum of partial fractions. Establish Newton’s divided-difference interpolation formula and give an estimate of the remainder term. Deduce Newton’s forward and backward difference interpolation formulae as particular cases. Given 1 f@M= =z x find the divided differences [a, 6] and [a, b,c]. Given the set of tabulated points (0, 2), (1, 3), (2, 12) and (15, 3587) satisfying the function y = f(x), compute (4) using Newton's divided difference formula. The nth divided difference [xo, x1, X2, ---) Xp] can be expressed as the quotient of two determinants. Show that a a! % x cA (0. 4 1 = 722 1 # 124 Crapter 3: Interpolation 3.39 3.40 3.41 3.42 3.44 3.4: a 3.46 3.47 3.48 Show that 1 Bo. a) = [¥ Go +4) dh. 0 where f) 2 0 and f + 4 = 1. Tabulate values of sinx for x = 0(0.01), 1.0 and find the maximum errors in linear and quadratic interpolations using Lagrange’s formula. if f(x) = 4, prove that x qa a ar Using Hermite’s interpolation formula, estimate the value of In 4.2 from the data (values of x, In x and 1); x (4.0, 1.38629, 0.25000), (4.5, 1.50408, 0.22222), (5.0, 1.60944, 0.20000). Find the Hermite polynomial of the third degree approximating the function y (x) such that yO) = 1, ¥(0) = vd) = 3, yd) = Values of x and ¥/x are given below (51, 3.708), (55, 3.803), (57, 3.848). Find x when 9x = 3.780. From the table of values of x and e*, viz. (1.4, 4.0552), (1.5, 4.4817), (1.6, 4.9530), (1.7, 5.4739), find x when e* = 4.7115, using the method of successive approximations. The second degree polynomial which satisfies the set of values (0, 1), (1, 2) and (2, 1) is (a) 1+2x—x? (b) 1 — 2x + x? (c) 1-2x—x? (d) 142x437 Find the correct alternative in the above. If Ay = 1 + 2x + 3x?, which one of the following is not true? (a) My = 6x +5 (b) Ay = 6 (©) AtYy=0 @ yarrxs Which of the following statements are true? (a) A(tan"'x) = tan! ma (b) A(cos 2x) = 2 sinx (x + A) (c) A°°) = 6x (d) 6= Vel? > v (©) a= (1 - ae () we= At 2 EXERCISES 125 3.1 3.2 3.3 3.4 3.7 3.10 3.14 3.17 3.19 3.21 3.23 3.25 3.28 3.30 3.34 3.37 3.42 3.44 3.46 3.48 3.50 1 a’ (g) Ax” = mx hy |= ¥=6x @ wet =e For the function z = f(x, y), the following values are given FO, 0 = 0, f(0,1)=2, f0, 2) = 6, f0,90=1, f= 3, fC, 2) = 7, f2,0=4, f2,1=6 fF, 2) = 10. Estimate the value of f(0.5, 0.5) by the method of linear interpolation and compare the result with the actual value obtained from zaxrtyty. Estimate the value of /(1.5, 1.5) in Problem 3.49 and compare the value with its actual value. Answers to Exercises 239, 371 (a) 6h + x), (b) cos (x + 21) — 2008 (% + h) + cos x (©) 2x +4 @ tat (o Loeengtsd = glee £0) ater D 80a) g(x+h) 5.74 3.1582 3.6 54 yl) = 3, 10) = 11 3.8 1.6751, 1.7082 257.259, 288.805 3.13 17,551 0.00000001 3.15 0.783172 0.3165 3.18 111.9152 6.7531 3.20 0.9856 0.9856 3.22 1.6858 16.25 3.24 0.1987 0.9763 3.26 3251 zoe —3x +7) 3.29 16 15 3 9, 241 39 0.0239 3.31 i” mn? ta * 0 1 1 1 (a+b) abt be+ca 2as Bap x2 OS PR PR 1454 3.40 | yQ@) — L2(x)| = 6.415 x 10° 1.435081 3.43 1+ x2 +33 54 3.45 1.55 ) 3.47 (d) @, @, ©, (h) 3.49 1.5 Proceed as in Problem 3.49. 6.1 INTRODUCTION In Chapter 3, we were concerned with the general problem of interpolation, viz., given the set of values (Xo, Yo)s (1, Vi)s «+1 Gm Yn) Of x and y, to find a polynomial ¢ (x) of the lowest degree such that y (x) and @ (x) agree at the set of tabulated points. In the present chapter, we shall be concerned with the problems of numerical differentiation and integration. That is to say, given the set of values of x and y, as above, we shall derive formulae to compute: 2 (i) yd J... for any value of x in [xo,x,], and dx’ de (ii) i ya % 6.2 NUMERICAL DIFFERENTIATION The general method for deriving the numerical differentiation formulae is to differentiate the interpolating polynomial. Hence, corresponding to each of the formulae derived in Chapter 3, we may derive a formula for the derivative. We illustrate the derivation with Newton’s forward difference formula only, the method of derivation being the same with regard to the other formulae. 207 208 Cuapter 6: Numerical Differentiation and Integration Consider Newton’s forward difference formula: Y= ot uAyy +e Pat yy Sy to, (6.1) where X= X%y + uh. (6.2) Then dy_dydu 1 2u-1 2, 3u*—6u+2 Fi _-\y A =. dx dude hl” 2 %* Gg ne] (6.3) This formula can be used for computing the value of dy/dx for non-tabular values of x. For tabular values of x, the formula takes a simpler form, for by setting x= xy we obtain u=0 from Eq. (6.2), and hence Eq. (6.3) gives dy YW) ay [2l.., io Differentiating Eq. (6.3) once again, we obtain 1 1 ate +580 Gatv0 +} (6.4) @y if 4 8-8 ns 12u* -36u+22 4 A —— d* yo + —————_A' +: |, 6.5 zs =a[2* 6 Yo 2 Jo (6.5) from which we obtain 2 DL aA atv atmrtoaty + 66) ae | 12 Formulae for computing higher derivatives may be obtained by successive differentiation. In a similar way, different formulae can be derived by starting with other interpolation formuale. Thus, (a) Newton’s backward difference formula gives dy 1 lop 1.3 = =—| Vy_t—V" Yq t=V° Vn + 6.7. [2] i il Jn 2 Yn 3 Sn (6.7) and a 1 “yy Vey + Vy te Svty, +8 Voy, 4° (6.8) de |, “| (b) Stirling’s formula gives [2] a1fAritay 1M yeratyy 1 Myatt ye.) Go) ax} em 2 6 2 30 2 Section 6.2: Numerical Differentiation 209 and dy] _1f.2 4 1 6 oy aty,-+a A®yg—- . [ | - on “3 JA~tp Jato J-3 (6.10) If a derivative is required near the end of a table, one of the following formulae may be used to obtain better accuracy +p (6.11) 30 —A° sagt ps (6.12) 137 7 363 Ry= 64.0 13 5 6 Ary Bo... Yo (* -A 24 Ae + *te04 30° 500° Yo (6.13) 1ty tgs 13 64 1 y7_ 29 48 =| A? -—at+—a +— Al -— Ab +... ( 32° *i2“ “igo” *i80° ~ 560 pr 6.14) Loe los loa los los loz los < hy, =| V+—V* +=V° +=V"4+—V° 4+-V9 4+ =V' 4 —VO te 6.15 Yn ( 2 3 4 5 6 7 8 mn (615) (95 FP Ba a 1 Var 6 i 2 30 4 (6.16) Uo4, Sys 1387 96, Ty7 , 363 Pyg=|V?+V8 44 425 4 v8 47 4 yey... 6.17 Nn ( 12° *6’ “180° “10° *560 yn 6.17) -(y2_tyt_1ys Bye Myr 29 iz” 12 igo’ 180" 560 For more details, the reader is referred to Interpolation and Allied Tables. The following examples illustrate the use of the formulae stated above. Jin (6.18) Example 6.1 From the following table of values of x and y, obtain dy/dx and d’y/dx? for x = 1.2: x y x J 1.0 2.7183 1.8 6.0496 12 3.3201 2.0 7.3891 14 4.0552 2.2 9.0250 1.6 4.9530 210 Cnapter 6: Numerical Differentiation and Integration The difference table is x y A a? a3 at ad ae 1.0 2.7183 0.6018 1.2 3.3201 0.1333 0.7351 0.0294 1.4 4.0552 0.1627 0.0067 0.8978 0.0364 0.0013 16 4.9530 0.1988 0.0080 0.0001 4.0866 0.0444 0.0014 1.8 6.0496 0.2429 0.0094 1.3395, 0.0535 2.0 7.3891 0.2964 1.6359 2.2 9.0250 Here % =1.2, yp =3.3201 and h=0.2, Hence Eq. (6.11) gives [2 al 7351-3 (0. 1627) +— ‘0. 0361) -0. 0080) + — ro. oor} dt} a2 02 = 3.3205. If we use formula (6.12), then we should use the differences diagonally downwards from 0.6018 and this gives [4] wl eo1s+4 qo 1333) -2.00. 0294) +50 9067) - (0. onis| de | 12 02 = 3.3205, as before. Similarly, formula (6.13) gives 2 ay a 0.1627 — 0.0361 yi (0.0080) 5 o.0014) =3.318. de | a2 a 8 Using formula (6.14), we obtain d’y 1 1 1 £Y) =| 0.1333-— (0.0067) + — (0.0013) }=3.32. | ‘| ol? 333—;, (0.0067) + (0.00 3| 3.3 Section 6.2: Numerical Differentiation 211 Example 6.2 Calculate the first and second derivatives of the function tabulated in the preceding example at the point x = 2.2 and also dy/dx at x = 2.0. We use the table of differences of Example 6.1. Here x, = 2.2, y, = 9.0250 and h = 0.2. Hence formula (6.15) gives dy 1 1 1 1 1 = =—| 1.6359 + — (0.2964) + — (0.0535) + — (0.0094) + — (0.0014) [Blas a 980+ (02300 + (0.0535 + (0.000 +5 (20010 = 9.0228. 2 LY) = 1 o.2964+0.0535 +14 0.0094) +2 (0.0014) |=8.992. de |p, 004 12 é To find dy/dx at x = 2.0, we can use either (6.15) or (6.16). Formula (6.15) gives A al 3395 +— *0. 2429) +— 70. 0441) +— +0. 0080) dx} v9.9 . 02 +4(0.0013) +4(0.000) 5 6 =7.3896. whereas from formula (6.16), we obtain [4] asl 6359-50. 2964) -400. 0535) — el o094)-* 00. oo | doo 02 = 7.3896. Example 6.3 Find dy/dx and d’y/dx? at x = 1.6 for the tabulated function of Example 6.1. Choosing xp = 1.6, formula (6.9) gives dy] __1 (0.8978 +1.0966 _ 1 0.0361+0.0441 , 1 0.0013+0.0014 dk] 16 aa 2 2 2 30 2 = 4.9530. Similarly, formula (6.10) yields 2 fY!) ~ 1 | q1988-+ (0.0080) ++ (0.0001) |= 4.9525. de |, ,, 0.04 12 90 212 Cuapter 6; Numerical Differentiation and Integration In the preceding examples, the tabulated function is e“ and hence it is easy to see that the error is considerably more in the case of the second derivatives. This is due to the reason that although the tabulated function and its approximating polynomial would agree at the set of data points, their slopes at these points may vary considerably. Numerical differentiation, is, therefore, an unsatisfactory process and should be used only in ‘rare cases.’ The next section will be devoted to a discussion of errors in the numerical differentiation formulae. 6.2.1. Errors in Numerical Differentiation The numerical computation of derivatives involves two types of errors, viz. truncation errors and rounding errors. These are discussed below. The truncation error is caused by replacing the tabulated function by means of an interpolating polynomial. This error can usually be estimated by formula (3.7). As noted earlier, this formula is of theoretical interest only, since, in practical computations, we usually do not have any information about the derivative y!"*"(é), However, the truncation error in any numerical differentiation formula can easily be estimated in the following manner. Suppose that the tabulated function is such that its differences of a certain order are small and that the tabulated function is well approximated by the polynomial. (This means that the tabulated function does not have any rapidly varying components.) We know that 2¢is the total absolute error in the values of Ay,, 4é in the values of A?y,, etc., where € is the absolute error in the values of y; Consider now, for example, Stirling's formula (6.9). This can be written in the form [| =A yp KY (6.19) dx}. 2h 2h where 7), the truncation error, is given by Py +A5y4 at A yet ya) 6.20) Gh 2 (620) Similarly, formula (6.10) can be written as 2 |A'y2|- (6.22, Oe [A°y-2] ) The rounding error, on the other hand, is inversely proportional to / in the case of first derivatives, inversely proportional to /° in the case of second Section 6.2: Numerical Differentiation 213 derivatives, and so on. Thus, rounding error increases as h decreases. Considering again Stirling’s formula in the form of Eq. (6.19), the rounding error does not exceed 2¢/2h = e/h, where € is the maximum error in the value of y; On the other hand, the formula [ #) Avat Ay Myo tAPyy dx} 2h 12h ¥en ~8¥-1+8Yi — Yo = ope 6.23 12h a has the maximum rounding error 18e _3e 12h 2h Finally, the formula [4] 7 PTH. (6.24) de | oy K has the maximum rounding error 4e/A?. It is clear that in the case of higher derivatives, the rounding error increases rather rapidly. Example 6.4 Assuming that the function values given in the table of Example 6.1 are correct to the accuracy given, estimate the errors in the values of dy/dx and @y/dx? at x= 1.6. Since the values are correct to 4D, it follows that ¢< 0.00005 = 0.5 x 104. Value of dy/dx at x = 1.6: Sy +A yo 2 from (6.20) , 1 Truncation error = th 1 0,0361+ 0.0441 ~ 602) 2 = 0.03342 and Rounding error ==. from (6.23) _ 3(0.5) 104 04 = 0.00038. 214 Cuaprer 6: Numerical Differentiation and Integration Hence, Total error = 0.03342 + 0.00038 = 0.0338. Using Stirling’s formula from Eq. (6.19), with the first differences, we obtain (2) _ Ayr +Ayo _ 0.8978-+1.0966 _ 1.9944 _ dx The exact value is 4.9530 so that the error in the above solution is (4.9860 — 4.9530), i.e., 0.0330, which agrees with the total error obtained above. Value of d’y/dx* at x = 1.6: Using Eq. (6.24), we obtain 2 2 Fa = AY _ 0.1988 _ 4 9799 x16 dv HP 0.04 so that the error= 4.9700 — 4.9530 = 0.0170. Also, Truncation error = = * 0.0080 = 0.01667 At oF [a'yal= a and 4 Rounding error =3€. = 4%05x107 _ 9 q950, F004 Hence . | dy Total error in|“*) — =0.0167+0.0050=0.0217. ae x16 6.2.2 Cubic Spline Method The cubic spline derived in Section 5.2 can conveniently be used to compute the first and second derivatives of a function. For a natural cubic spline, the recurrence formulae (5.31) or (5.32) may be used to compute the spline second derivatives depending upon the choice of the subdivisions. Then Eq. (5.29) gives the spline in the interval of interest, from which the first derivatives can be computed. For the first derivatives at the tabular points, it would, of course, be easier to use formulae (5.28) and (5.30) directly. If, on the other hand, end conditions involving the first derivatives are given, then recurrence formulae (5.34) or (5.36) may be used to compute the remaining first derivatives. The following examples illustrate the use of the spline formulae in numerical differentiation. Example 6.5 We consider the function y (x) = sin x in [0, 7]. Here My = My = 0. Let N = 2, ie., h = m/2. Then Yo=¥2=0, y= 1 and My = M, = 0. SEctION 6.2: Numerical Differentiation 215 Using formulae (5.32), we obtain Mg + 4M, + M, =e 0-231 +42) or 12 M =--5- Formula (5.29) now gives the spline in each interval. Thus, in 0 < x < 7/2, we obtain 2(-28 3x =-|—> +>} 0 oe } which gives @ Hence Exact value of s(/4) = cos 1/4=1/V2 = 0.70710681. The percentage error in the computed value of s’(z/4) is 1.28%. From (i), ” 24 s(x) =-x oe and hence 0.60792710. 4) 24 @ Since the exact value is -1/V2, the percentage error in this result is 14,03 %. We now consider values of y = sin x in intervals of 10° from x = 0 to z. To obtain the spline second derivatives we used a computer and the results are given in the following table (up to x =90°). 6(G)}-34-- ye) x(in degrees) Exact Cubic spline 10 .173 648 178 -0.174 089 426 20 342.020 143 0.342 889 233 30 500 000 000 -0.501 270524 40 —0.642 787 610 0.644 420 964 50 —0.766 044 443 0.767 990 999 60 .866 025 404 0.868 226 016 70 .939 692 621 -0.942 080 425 80 0.984 807 753 -0.987 310 197 90 ~1,000 000 000 1.002 541 048 It is seen that there is greater inaccuracy in the values of the spline second derivatives. 216 Cuapter 6: Numerical Differentiation and Integration Example 6.6 From the following data for y(x), find y’(1.0). x -2 -l 2 3 YO) -12 -8 385 The function from which the above data was calculated is given by yobs 3241, 3.9, Hence, the exact value of y/(1) is 3.51667. is* ~20* * eo To apply the cubic spline formula (5.31), we observe that hy = 1, J, = 3 and hy = 1. For i = 1,2, the recurrence relation gives: 8M, + 3M, = -2 and 3M, + 8M, = -10, 14 74 since My = M; = 0. We obtain M, = 55 and M, =-—.In-l sx we have 55 if @-»§ 14 ea is) = My 4 a | 6 55 6 8S -eaetp lon Differentiating the above and putting x = 1, we obtain 1{ 7 148 461 276 (1) = 95 (1.0) =—| -— -——-+— + — YM= 30.0) il 55° 55 (55 =| = 3.52727, on simplification. “w nv 6.2.3 Differentiation Formulae with Function Values In Section 6.2, we developed forward, backward and central difference approximations of derivatives in terms of finite differences. From the computational point of view, it would be convenient to express the numerical differentiation formulae in terms of function values. We list below some differentiation formulae for use in numerical computations. (i) Forward Differences Yq) = 2H, (x) = 22 +A 834 5 Q(t) Vi = 2Yinr + Vine "| Viva + Ang — Sint + 29h = ; (x) = + yx) F Vx e Section 6.3: Maximum and Minimum Values of a Tabulated Function 217 (ii) Backward Differences 3¥i ~4Yi-1 4 Yi-2, (x)= oh ‘ 2y-5yj-1 + 4¥i-2 — W-3 "(y) -rule and compare with A= 3 the result Balm 6.26 Using the method of undetermined coefficients, derive the formula h A P Jr@nde= 50% + WT 0-W) 0 6.27 The function y = e* satisfies the following data which is unequally spaced: (1.00, 2.7183), (1.05, 2.8577), (1.10, 3.0042), (1.15, 3.1582), (1.25, 3.4903), (1.30, 3.6693). Evaluate the integral as accurately as possible. 6.28 Evaluate is ox txt by Simpson’s forule with h = 0.25. Cuapter 6: Numerical Differentiation and Integration 6.33 Use Euler-Maclaurin formula to evaluate the integral 2 T= [ (cos x+In x—e") de 1 Use Euler—Maclaurin formula to sum the series S=P 43434-0408, Derive the Gauss integration formula when n = 2 and apply it to evaluate the integral 1 dx. +x Compare this result with that obtained by Simpson’s 4-rule with h = 0.125. 3 Let 2 J? (2) de= hy £0) +h £0) + hy £2). 0 If f(x) is approximated by a quadratic through the points x = 0, 1, and 2, then find the values of ko, ki and ky. Using the trapezoidal rule, show that Je*cos @xdx= f__sinhh _ (Einarsson) 0 2 cosh h—cos wh Einarsson [1972] derived the formula Jer*cos oxdx= 0 Asinh h cosh 2h—cos2@h (q cosh h+ & cos wh), where G=2 1+ cos” oh sin2oh ‘ ait an EXERCISES 253 6.36 6.37 6.38 6.39 6.40 61 6.2 6.3 6.4 6.5 6.6 6.7 6.8 4 6 [ae | ani 2 = oP oF use this formula to show that J er*cos x ae= 0.500001391 0 If ald I= J cos? x dx, 0 compute o,~), 1/0, | and 7] =, 4 8 84 Verify the error estimate given in Eq. (6.67) for Problem 6.36. Test the error estimate given in Eq. (6.67) in the evaluation of the integral nl I= J cos x dx 0 Use the trapezoidal rule to evaluate the double integral (2 - xy+ *) de dy. bor oe Use Simpson’s pore to evaluate the double integral in Problem 6.39 and compare the results with the exact value. Answers to Exercises —0.0505 3.975 2.6444 0.55 (a) 0.3931 — (b) 0.3341 — (c) 0.2706 ~—(d) -0.0256. 3.73 rad/s; 4.48 rad/s* 5.5; 5.0. 0 254 Cuapter 6: Numerical Differentiation and Integration 6.9 6.10 6.11 6.12 6.13 6.15 6.16 6.17 6.18 6.19 6.20 6.21 6.22 6.23 6.24 6.25 6.27 6.28 6.29 6.31 6.32 6.33 6.36 6.37 6.38 6.39 6.40 17; 6 (a) -0.2831 (b) -0.1735 (c) -0.0639. 29 se) = 2@ - 18 +32 —x) + Hx— 1), 15x82. 1.0 (a) nm, (b) -1.0794 66.5 0.475 (a) 1.1000, (b) 1.0987 1.1873 177.4816 0.2947 0.7855 Tr = 0.9871, I, = 1.0002 1.570858 0.69319; 0.69317 0.9513 0.815 4.21667 1.5 0.693122 ky =-= 0.269583 See Example 6.16. Error = 0.00014 112 106.6667 8.1 INTRODUCTION Many problems in science and engineering can be reduced to the problem of solving differential equations satisfying certain given conditions. The analytical methods of solution, with which the reader is assumed to be familiar, can be applied to solve only a selected class of differential equations. Those equations which govern physical systems do not possess, in general closed- form solutions, and hence recourse must be made to numerical methods for solving such differential equations. To describe various numerical methods for the solution of ordinary differential equations, we consider the general first order differential equation dy =f (x . de («yy (8.1a) with the initial condition, YG) =% (8.1b) and illustrate the theory with respect to this equation. The methods so developed can, in general, be applied to the solution of systems of first-order equations, and will yield the solution in one of the two forms: (i) A series for y in terms of powers of x, from which the value of y can be obtained by direct substitution. (ii) A set of tabulated values of x and y. The methods of Taylor and Picard belong to class (i), whereas those of Euler, Runge-Kutta, Adams—Bashforth, etc., belong to class (ii). These latter 302 Section 8.2: Solution by Taylor’s Series 303 methods are called step-by-step methods or marching methods because the values of y are computed by short steps ahead for equal intervals h of the independent variable. In the methods of Euler and Runge-Kutta, the interval length h should be kept small and hence these methods can be applied for tabulating y over a limited range only. If, however, the function values are desired over a wider range, the methods due to Adams—Bashforth, Adams— Moulton, Milne, etc., may be used. These methods use finite-differences and require ‘starting values’ which are usually obtained by Taylor’s series or Runge-Kutta methods. It is well-known that a differential equation of the nth order will have n arbitrary constants in its general solution. In order to compute the numerical solution of such an equation, we therefore need n conditions. Problems in which all the initial conditions are specified at the initial point only are called initial value problems. For example, the problem defined by Eqs. (8.1) is an initial value problem. On the other hand, in problems involving second-and higher-order differential equations, we may prescribe the conditions at two or more points, Such problems are called boundary value problems. We shall first describe methods for solving initial value problems of the type (8.1), and at the end of the chapter we will outline methods for solving boundary value problems for second-order differential equations. 8.2 SOLUTION BY TAYLOR'S SERIES We consider the differential equation Y=FKy) (8.1a) with the initial condition ¥(%) = %- (8.1b) Ify (x) is the exact solution of Eq. (8.1), then the Taylor’s series for y (x) around x = xo is given by i 2 I= oO 29) H+ EL ye (8.2) If the values of y6, ys... are known, then Eq. (8.2) gives a power series fory. Using the formula for total derivatives, we can write Y= f= ft Vly= bet thy where the suffixes denote partial derivatives with respect to the variable concerned. Similarly, we obtain Y= f= fot by lt fbr fy ft fylfet 5A = 2 2 = fat 2fhy + f hy + fyb + ff and other higher derivatives of y. The method can easily be extended to simultaneous and higher-order differential equations. 304 — Cnapter 8: Numerical Solution of Ordinary Differential Equations Example 8.1 From the Taylor series for y (x), find y (0.1) correct to four decimal places if y (x) satisfies yeox-y and y)=1. The Taylor series for y (x) is given by 2 Bm Bw ® YD=1 I+ THA EH GIO Piag VOR etc. are obtained thus: The derivatives yg, yg VX=x-¥ YH =1-2yy I") =-2yy"—2? 8 P()=-2yy"— By" yy =34 y" (x) =-2yy" —Byy"-6y” Yo = 186 Using these values, the Taylor series becomes yaetvede 4a ity Sey. 2 3 12 20 To obtain the value of y (0.1) correct to four decimal places, it is found that the terms up to x‘ should be considered, and we have y(0.1) =0.9138. Suppose that we wish to find the range of values of x for which the above series, truncated after the term containing x*, can be used to compute the values of y correct to four decimal places. We need only to write ad <0,00005 or x< 0.126, Example 8.2 Given the differential equation Y~x-y=0 with the conditions (0) = 1 and y’(0) = 0, use Taylor’s series method to determine the value of y (0.1). We have y(x) = 1 and y(x) = 0 when x = 0. The given differential equation is Ya) = 49 (0) + y() @ Hence y(0) = y(0) = 1. Successive differentiation of (i) gives Y= A") + (0) + (9) = 19") +2), 0) IY (a) = 19H) + "() +2") = 3") 43"), (iii) ¥ (a) = a" (4) + (2) +89") = ay" (2) +4"), iv) YY (a) = ay (4) + (2) + (a) = ay" (2) +5"), () SECTION 8,3: Picard’s Method of Successive Approximations 305 and similarly for higher derivatives. Putting x=0 in (ii) to (v), we obtain ¥'O)=2¥(0)=0, y¥O)=3y'=3, y()=0, yO=5. By Taylor’s series, we have A HD = YO) + 4/0) + “ YO rs coro Pov, x vi F297 Ot am—9F OF Hence 74 0.0? 4 py, ODS (a y(0.1) = 5 7A (+ 720 (5) + =1+0.005+0.0000125, neglecting the last term =1,0050125, correct to seven decimal places. 8.3. PICARD’S METHOD OF SUCCESSIVE APPROXIMATIONS Integrating the differential equation given in Eq. (8.1), we obtain x y=mt J fede (8.3) 0 Equation (8.3), in which the unknown function y appears under the integral sign, is called an integral equation, Such an equation can be solved by the method of successive approximations in which the first approximation to y is obtained by putting y) for y on right side of Eq. (8.3), and we write x Y= y+ J 10% 90) de 0 The integral on the right can now be solved and the resulting y“”) is substituted for y in the integrand of Eq. (8.3) to obtain the second approximation y: x PP =m f fay) de » Proceeding in this way, we obtain y®), ¥,..., y) and y, where PP = y+ f fay) de — with y = yy (8.4) % 306 = Cuapter 8: Numerical Solution of Ordinary Differential Equations Hence this method yields a sequence of approximations y"), y®),..., y! and it can be proved (see, for example, the book by Levy and Baggot) that if the function f(x, y) is bounded in some region about the point (49, yg) and if f(x, y) satisfies the Lipschitz condition, viz., | fx W- F(x PIS Kl y-7| -K being a constant (8.5) then the sequence y, P00 converges to the solution of Eq. (8.1). Example 8.3 Solve the equation y=xty, subject to the condition y=1 when x=0. We start with y =1 and obtain x y =1+f (x+D deatexs ht. 0 Then the second approximation is x 1>5¥ y =14 J x+[1+x+ix% | |de 0 2 etext 3 ey ely ys 2 3 4 20 It is obvious that the integrations might become more and more difficult as we proceed to higher approximations. Example 8.4 Given the differential equation with the initial condition y=0 when x=0, use Picard’s method to obtain y for x= 0.25, 0.5 and 1.0 correct to three decimal places. We have f_¥# xf yu Setting y =0, we obtain x y=) Parle 3 0 and yp # -an (ls) le, yf “lee (B83 a? Section 8.4: Euler’s Method 307 so that y\) and y°) agree to the first term, viz., (1/3)x°. To find the range of values of x so that the series with the term (1/3)x° alone will give the result correct to three decimal places, we put 19 < 0.0005 81 which yields x<0.7 Hence (0.25) = 30.25)" = 0.005 (0s) =3(05)* =0.082 11 1.0) => -— = 0,321 y(.0) 3 a 8.4 EULER'S METHOD We have so far discussed the methods which yield the solution of a differential equation in the form of a power series. We will now describe the methods which give the solution in the form of a set of tabulated values. Suppose that we wish to solve the Eqs. (8.1) for values of y at x =x, = x9 + rh(r = 1, 2, ...). Integrating Eq. (8.1), we obtain 4 Kast J f(x yy de (8.6) 0 Assuming that f(x, y) = f (4, Yo) in x9 Cnt = Cn + AL £(X%p Yn) — £(%n Yn) ] + Loa By mean value theorem, we write of Ain Jn) ~ Fp HOM) = [Yn ~ YR] 55 nEnds Hin) SES ir Hence, we have Cnet = nL 1+ bby (qn) | + Let (8.12) Since eg = 0, we obtain successively: gah e=[1+ h(x. Q]4+ bi 0 = [1+ fy (2,82) |[1+ by (%5.&) | (Ly + Ly) + Lyi ete. See the book by Isaacson and Keller [1966] for more details. Example 8.6 We consider, again, the differential equation ¥ =—y with the condition y(0)=1, which we have solved by Euler’s method in Example 8.5. Choosing 4=0.01, we have 1+ hfy(%p, G,) =1+ 0.01 (-1) = 0.99. and ley Lua = gy (Pn) =—0.00005 y(p,). In this problem, y(p,) < y(x,), since y is negative. Hence we successively obtain [4,| <0.00005 = 510°, [Z| < (0.00005) (0.99) <5x10-, |Ls| < (0.00005) (0.9801) <5 x10", and so on. For computing the total solution error, we need an estimate of the rounding error. If we neglect the rounding error, i.e., if we set Fy = 0, then using the above bounds, we obtain from Eq. (8.12) the estimates & =0, lal<5x10% Je.|<0.99q +5x10 <104 |e,|<0.99e, +5x10 <10-4 +5x10> |ey|<0.99e, +5x10-> <104 +104 = 2x10 = 0.0002 310 = Cuarter 8: Numerical Solution of Ordinary Differential Equations It can be verified that the estimate for e, agrees with the actual error in the value of (0.04) obtained in Example 8.5. 8.4.2 Modified Euler’s Method Instead of approximating f(x, y) by f(4%, yo) in Eq. (8.6), we now approximate the integral given in Eq. (8.6) by means of trapezoidal rule to obtain h H= Yor yl, Yo) + Fi WI (8.13) We thus obtain the iteration formula “_ =Jo+ 7 If, Jot £4. YA), -n=0,1,.2.... (8.14) where yo is the nth approximation to y,. The iteration formula (8.14) can be started ‘i choosing yk from Euler’s formula: Y= yy HE (%, Yo) Example 8.7 Determine the value of y when x=0.1 given that yO)=1 and yoarty We take h=0.05. With %)=0 and yg=1.0, we have f(x, yo)=1.0. Hence Euler’s formula gives y =1+0.05() =1.05 Further, 4 =0.05 and F(x, y\) =1.0525. The average of f(4, yo) and t(%, y) is 1.0262. The value of yf can therefore be computed by using Eq. (8.14) and we obtain y() =1.0513. Repeating the procedure, we obtain y?) =1.0513. Hence we take y, =1.0513, which is correct to four decimal places. Next, with x =0.05, y, =1.0513 and h=0.05, we continue the procedure to obtain yp, i.e., the value of y when x=0.1. The results are yf) =1.1040, y$? =1.1055, ys? =1.1055. Hence we conclude that the value of y when x=0.1 is 1.1055. EXERCISES 8.1. Given # 1 (0) = =l+yy, =1, obtain the Taylor series for (x) and compute (0.1), correct to four decimal places. 8.2 Show that the differential equation d’y t —>=- xy, y(0)=1 and y(0)=0, ne xy, Vi Jy has the series solution a1 Fy PA _DeAXT 9 ya el 9 336 Cuarter 8: Numerical Solution of Ordinary Differential Equations 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.1 5 8.13 If eee with y (4) = 4, compute the values of y (4.1) and y (4.2) by Taylor’s series method. Use Picard’s method to obtain a series solution of the problem given in Problem 8.1 above. Use Picard’s method to obtain y (0.1) and y (0.2) of the problem defined by ewe yA, 0) = 3. Using Euler’s method, solve the following problems: dy _3 _ Hy 0) =0 @ FarHyWO=1 0) Gay 10 Compute the values of » (1.1) and y (1.2) using Taylor’s series method for the solution of the problem ¥+ty¥ye=x, yl)=1 and yl) =1. Find, by Taylor’s series method, the value of y (0.1) given that Y’- xf — y=0, (0) =1 and y(0) =0. Using Picard’s method, find y (0.1), given that Y_y-x - ae” yex and y(0)=1. Using Taylor’s series, find y (0.1), y (0.2) and y (0.3) given that yy Sexes, yO)=1. Err WO Given the differential equation dy_ Dogs de y with y(0) = 1, compute y (0.02) using Euler’s modified method. Solve, by Euler’s modified method, the problem dy S=x+y, y(0)=0. de Jr HO) Choose h = 0.2 and compute y (0.2) and y (0.4). Given the problem wy = de = 1% Nand Y(%) = Jor EXERCISES 337 8.14 8.15 8.16 8.17 8.18 8.19 an approximate solution at x = x9 + h is given by the third order Runge— Kutta formula yx + h) = yo + Fai + 4k + ks) + Ry where 1 1 ky = if (os Yo), ka = Wf Ko + Oh, Yo + ZA) and ky = hf + hy Yo + 2ky — hy). Show that Ry is of order ht. Write an algorithm to implement Runge-Kutta fourth order formula for solving an initial value problem. Find y (0,1), » (0.2) and 7 3) given that Yale ZBp 10) =0 Use Runge-Kutta fourth onde, formula to find y (0.2) and y (0.4) given that (0) =1. are Solve the initial value problem defined by dy _3x+y YeTY ayai dx x+2y wa) and find y (1.2) and y (1.4) by the Runge-Kutta fourth order formula. State Adam’s predictor-corrector formulae for the solution of the equation Y =F Ys ¥ Co) = Yor Given the problem yi ty =0, 0) = 1, find y (0.1), y (0.2), and y (0.3) by Runge-Kutta fourth order formula and hence obtain y(0.4) by Adam’s formulae. Given the initial value problem defined by Boys se, y(0) =1 find the values of y for x = 0.2, 0.4, 0.6, 0.8 and 1.0 using the Euler, the modified Euler and the fourth order Runge-Kutta methods. Compare the computed values with the exact values. State Milne’s predictor-corrector formulae for the solution of the problem ¥ =F Ys VC) = Yor Given the initial value problem defined by Yay tay, yO) = 1, find, by Taylor’s series, the values of y (0.1), y (0.2) and y (0.3). Use these values to compute y (0.4) by Milne’s formulae. 338 © Cuapter 8: Numerical Solution of Ordinary Differential Equations 8.20 Using Milne’s formulae, find y (0.8) given that YP, yO)=0, y(0.2) =0.02, dx y (0.4) = 0.0795 and (0.6) = 0.1762. 8.21 Explain what is meant by a fourth order formula. Discuss this with reference to the solution of the problem dy y =3xt+=, y(0)=1 dx 2 tt by Runge-Kutta fourth order formula. 8.22 Use Taylor’s series method to solve the system of differential equations dx dy S=y-t, S=xtt ay" at with x = 1, y = 1 when / = 0, taking Ax = Ar = 0.1. 8.23 Using fourth order Runge-Kutta method, compute the value of y (0.2) given that d’y —++y=0 ae with y(0) = 1 and y“(0) = 0. 8.24 Given that y-xy + 4y=0, yO) = 3, YO) = 0, compute the value of y (0.2) using Runge-Kutta fourth order formla. 8.25 Solve the boundary value problem defined by y’-y=0, yO)=0, yC)=1, by finite difference and cubic spline methods. Compare the solutions obtained at y(0.5) with the exact value. In each case, take h = 0.5 and A=0.25. 8.26 Shooting method This is a popular method for the solution of two-point boundary value problems. If the problem is defined by ¥=f(X), y Go) =O and y (x) = A, then it is first transformed into the initial value problem Y@)=2, @)=fe), with y (xo) = 0 and 2(xp) = tg, where mo is a guess for the value of y’ (Xo). Let the solution corresponding to x = x; be Yo. If ¥; is the value obtained by another guess m, for y’(xo), then Y) and Y, are related linearly. Thus, linear interpolation can be carried out between the values (imo, Yo) and (m;, y1)- Obviously, the process can be repeated till we obtain a value for y(x;) which is close to A. EXERCISES 339 8.27 8.28 8.30 8.1 8.2 8.3 Apply the shooting method to solve the boundary value problem ¥” = y(x), (0) = 0 and y(1) = 1. Fyfe [1969] discussed the solution of the boundary value problem defined by y+ 4x 14x Solve this problem by cubic spline method first with = 1 and then with h = 1/2 to determine the value of y (1). Compare your results with the exact values of y (1) obtained from the analytical solution y = 1/(1 +x). Method of Linear Interpolation Let the boundary value problem be defined by eave tia) ‘y(0) =1 and y(2)=0.2. y+ fody’ + g@y = p@), V@&o)=VYo and yn) =Yy- Set up the finite difference approximation of the differential equation and solve the algebraic equations using the initial value yp and assuming a value, say Yo, for y (x)). Again, we assume another value for y(x)), say Yj and then compute the values of y, y3, ..., Jy-1 and y,. We, thus, have two sets of values of y (x;) and y (x,). Now we use linear interpolation formula to compute the value of y (x,) for which y (x,) = y,,. The process is repeated until we obtain the value of y(x,) close to the given boundary condition (see Problem 8.26). Solve the boundary value problem defined by y” + xy’ — 2y = 0, y(0) = 1 and y(1) = 2 using the method of Linear interpolation. Using Galerkin’s method, compute the value of y (0.5) given that y+y=x, O, y. = 0.485714 0.542373 (bs) A=1, 0 yy 1 h= QF 0.5228 8.28 y, = 1.0828, y2 = 1.2918, 3 = 1.6282, yy = 1.99997 8.29 (0.5) = -0.041665 (Exact value = -0.04592) 8.30 u(x, y) = Fe - Dy - 1)

You might also like