1. Numerical differentiation Tis Section deals wit ways of numerically approximating derivatives of functions. One reason for dealing wit tis now is tat we will use it briefly in te next Section. But as we sall see in tese next few pages, te tecnique is useful in itself. 2. First derivatives Our aim is to approximate te slope of a curve f at a particular point x = a in terms of f(a) and te value of f at a nearby point were x = a +. Te sorter broken line Figure 11 may be tougt of as giving a reasonable approximation to te required slope (sown by te longer broken line), if is small enoug. f Tis slope approximates f (a) Slope of line is f (a) a a+ x Figure 11 So we migt approximate f (a) slope of sort broken line = difference in te y-values difference in te x-values = f(a + ) f(a). Tis is called a one-sided difference or forward difference approximation to te derivative of f. A second version of tis arises on considering a point to te left of a, rater tan to te rigt as we did above. In tis case we obtain te approximation f (a) f(a) f(a ) Tis is anoter one-sided difference, called a backward difference, approximation to f (a). A tird metod for approximating te first derivative of f can be seen in Figure 12. HELM (2008): Section 31.3: Numerical Differentiation 59
f Tis slope approximates f (a) Slope of line is f (a) a a a+ x Figure 12 Here we approximate as follows f (a) slope of sort broken line = difference in te y-values difference in te x-values Tis is called a central difference approximation to f (a). = f(x + ) f(x ) 2 Tree approximations to te derivative f (a) are Key Point 11 First Derivative Approximations 1. te one-sided (forward) difference 2. te one-sided (backward) difference 3. te central difference f(a + ) f(a) f(a) f(a ) f(a + ) f(a ) 2 In practice, te central difference formula is te most accurate. Tese first, rater artificial, examples will elp fix our ideas before we move on to more realistic applications. 60 HELM (2008): Workbook 31: Numerical Metods of Approximation
Example 18 Use a forward difference, and te values of sown, to approximate te derivative of cos(x) at x = π/3. (a) = 0.1 (b) = 0.01 (c) = 0.001 (d) = 0.0001 Work to 8 decimal places trougout. Solution (a) f cos(a + ) cos(a) 0.41104381 0.5 (a) = = 0.88956192 0.1 (b) f cos(a + ) cos(a) 0.49131489 0.5 (a) = = 0.86851095 0.01 (c) f cos(a + ) cos(a) 0.49913372 0.5 (a) = = 0.86627526 0.001 (d) f cos(a + ) cos(a) 0.49991339 0.5 (a) = = 0.86605040 0.0001 One advantage of doing a simple example first is tat we can compare tese approximations wit te exact value wic is 3 f (a) = sin(π/3) = = 0.86602540 to 8 d.p. 2 Note tat te accuracy levels of te four approximations in Example 15 are: (a) 1 d.p. (b) 2 d.p. (c) 3 d.p. (d) 3 d.p. (almost 4 d.p.) Te errors to 6 d.p. are: (a) 0.023537 (b) 0.002486 (c) 0.000250 (d) 0.000025 Notice tat te errors reduce by about a factor of 10 eac time. Example 19 Use a central difference, and te value of sown, to approximate te derivative of cos(x) at x = π/3. (a) = 0.1 (b) = 0.01 (c) = 0.001 (d) = 0.0001 Work to 8 decimal places trougout. HELM (2008): Section 31.3: Numerical Differentiation 61
Solution (a) f cos(a + ) cos(a ) 0.41104381 0.58396036 (a) = = 0.86458275 2 0.2 (b) f cos(a + ) cos(a ) 0.49131489 0.50863511 (a) = = 0.86601097 2 0.02 (c) f cos(a + ) cos(a ) 0.49913372 0.50086578 (a) = = 0.86602526 2 0.002 (d) f cos(a + ) cos(a ) 0.49991339 0.50008660 (a) = = 0.86602540 2 0.0002 Tis time successive approximations generally ave two extra accurate decimal places indicating a superior formula. Tis is illustrated again in te following Task. Task Let f(x) = ln(x) and a = 3. Using bot a forward difference and a central difference, and working to 8 decimal places, approximate f (a) using = 0.1 and = 0.01. (Note tat tis is anoter example were we can work out te exact answer, wic in tis case is 1.) 3 Your solution 62 HELM (2008): Workbook 31: Numerical Metods of Approximation
Answer Using te forward difference we find, for = 0.1 f ln(a + ) ln(a) 1.13140211 1.09861229 (a) = = 0.32789823 0.1 and for = 0.01 we obtain f ln(a + ) ln(a) 1.10194008 1.09861229 (a) = = 0.33277901 0.01 Using central differences te two approximations to f (a) are f (a) ln(a + ) ln(a ) 2 = 1.13140211 1.06471074 0.2 = 0.33345687 and f ln(a + ) ln(a ) 1.10194008 1.09527339 (a) = = 0.33333457 2 0.02 Te accurate answer is, of course, 0.33333333 Tere is clearly little point in studying tis tecnique if all we ever do is approximate quantities we could find exactly in anoter way. Te following example is one in wic tis so-called differencing metod is te best approac. Example 20 Te distance x of a runner from a fixed point is measured (in metres) at intervals of alf a second. Te data obtained are t 0.0 0.5 1.0 1.5 2.0 x 0.00 3.65 6.80 9.90 12.15 Use central differences to approximate te runner s velocity at times t = 0.5 s and t = 1.25 s. Solution Our aim ere is to approximate x (t). Te coice of is dictated by te available data given in te table. Using data wit t = 0.5 s at its centre we obtain x (0.5) x(1.0) x(0.0) 2 0.5 = 6.80 m s 1. Data centred at t = 1.25 s gives us te approximation x (1.25) x(1.5) x(1.0) 2 0.25 Note te value of used. = 6.20 m s 1. HELM (2008): Section 31.3: Numerical Differentiation 63
Task Te velocity v (in m s 1 ) of a rocket measured at alf second intervals is t 0.0 0.5 1.0 1.5 2.0 v 0.000 11.860 26.335 41.075 59.051 Use central differences to approximate te acceleration of te rocket at times t = 1.0 s and t = 1.75 s. Your solution Answer Using data wit t = 1.0 s at its centre we obtain v v(1.5) v(0.5) (1.0) = 29.215 m s 2. 1.0 Data centred at t = 1.75 s gives us te approximation v (1.75) v(2.0) v(1.5) 0.5 = 35.952 m s 2. 3. Second derivatives An approac wic as been found to work well for second derivatives involves applying te notion of a central difference tree times. We begin wit f (a) f (a + 1) f (a 1) 2 2. Next we approximate te two derivatives in te numerator of tis expression using central differences as follows: f (a + 1 f(a + ) f(a) ) 2 and f (a 1 2 f(a) f(a ) ). 64 HELM (2008): Workbook 31: Numerical Metods of Approximation
Combining tese tree results gives f (a) f (a + 1) f (a 1) 2 2 1 {( ) ( )} f(a + ) f(a) f(a) f(a ) = f(a + ) 2f(a) + f(a ) 2 Key Point 12 Second Derivative Approximation A central difference approximation to te second derivative f (a) is f (a) f(a + ) 2f(a) + f(a ) 2 Example 21 Te distance x of a runner from a fixed point is measured (in metres) at intervals of alf a second. Te data obtained are t 0.0 0.5 1.0 1.5 2.0 x 0.00 3.65 6.80 9.90 12.15 Use a central difference to approximate te runner s acceleration at t = 1.5 s. Solution Our aim ere is to approximate x (t). Using data wit t = 1.5 s at its centre we obtain x (1.5) x(2.0) 2x(1.5) + x(1.0) 0.5 2 = 3.40 m s 2, from wic we see tat te runner is slowing down. HELM (2008): Section 31.3: Numerical Differentiation 65
Exercises 1. Let f(x) = cos(x) and a = 2. Let = 0.01 and approximate f (a) using forward, backward and central differences. Work to 8 decimal places and compare your answers wit te exact result, wic is sin(2). 2. Te distance x, measured in metres, of a downill skier from a fixed point is measured at intervals of 0.25 s. Te data gatered are Answers t 0 0.25 0.5 0.75 1 1.25 1.5 x 0 4.3 10.2 17.2 26.2 33.1 39.1 Use a central difference to approximate te skier s velocity and acceleration at te times t =0.25 s, 0.75 s and 1.25 s. Give your answers to 1 decimal place. 1. Forward: f cos(a + ) cos(a) 3.79865301 3.76219569 (a) = = 3.64573199 0.01 Backward: f cos(a) cos(a ) 3.76219569 3.72611459 (a) = = 3.60810972 0.01 Central: f cos(a + ) cos(a ) 3.79865301 3.72611459 (a) = = 3.62692086 2 0.02 Te accurate result is sin(2) = 3.62686041. 2. Velocities at te given times approximated by a central difference are: 20.4 m s 1, 32.0 m s 1 and 25.8 m s 1. Accelerations at tese times approximated by a central difference are: 25.6 m s 2, 32.0 m s 2 and 14.4 m s 2. 66 HELM (2008): Workbook 31: Numerical Metods of Approximation