You are on page 1of 118
Chapter 2 Primer on Differentiation After reading this chapter, you should be able to: 1. understand the basics of differentiation, 2. relate the slopes of the secant line and tangent line to the derivative of a function, 3. find derivatives of polynomial, trigonometric and transcendental functions, 4. use rules of differentiation to differentiate functions, 5. find maxima and minima of a function, and 6. apply concepts of differentiation to real world problems. In this primer, we will review the concepts of differentiation you learned in calculus. Mostly those concepts are reviewed that are applicable in learning about numerical methods. These include the concepts of the secant line to learn about numerical differentiation of functions, the slope of a tangent line as a background to solving nonlinear equations using the NewtonRaphson method, finding maxima and minima of functions as a means of optimization, the use of the Taylor series to approximate functions, etc. Introduction The derivative of a function represents the rate of change of a variable with respect to another variable. For example, the velocity of a body is defined as the rate of change of the location of the body with respect to time. The location is the dependent variable while time is the independent variable. Now if we measure the rate of change of velocity with respect to time, we get the acceleration of the body. In this case, the velocity is the dependent variable while time is the independent variable. Two concepts of the secant line and tangent line. f(x) secant line Q tangent line P x Figure 1 Function curve with tangent and secant lines. Let P and Q be two points on the curve as shown in Figure 1. The secant line is the straight line drawn through P and Q. f (x) Q P a Figure 2 Calculation of the secant line. a+h x The slope of the secant line (Figure 2) is then given as f ( a  h)  f ( a ) mPQ,secant  ( a  h)  a f ( a  h)  f ( a ) h As Q moves closer and closer to P , the limiting portion is called the tangent line. The slope of the tangent line mPQ ,tangent then is the limiting value of mPQ ,secant as h  0 .  m PQ , tangent  lim h 0 f ( a  h)  f ( a ) h Example 1 Find the slope of the secant line of the curve y  4x 2 between points (3,36) and (5,100). 250 200 f(x) 150 100 (5,100) (3,36) 50 0 -2 -1 0 1 2 3 4 5 6 7 x Figure 3 Calculation of the secant line for the function y  4x 2 . 8 Solution The slope of the secant line between (3,36) and (5,100) is f (5)  f (3) m 53 100  36  53  32 Example 2 Find the slope of the tangent line of the curve y  4x 2 at point (3,36). Solution The slope of the tangent line at (3,36) is m  lim h 0 f (3  h)  f (3) h 4(3  h) 2  4(3) 2  lim h 0 h 4(9  h 2  6h)  36  lim h 0 h 36  4h 2  24h  36  lim h 0 h h(4h  24)  lim h 0 h  lim (4h  24) h 0  24 70 60 50 f(x) 40 30 20 10 0 -2 -1 0 1 2 3 4 x Figure 4 Calculation of the tangent line in the function y  4x 2 . 5 The slope of the tangent line is f (3  h)  f (3) h 0 h 4(3  h) 2  4(3) 2  lim h 0 h 36  24h  4h 2  36  lim h 0 h h(24  4h)  lim h 0 h  lim (24  4h) m  lim h 0  24 Derivative of a Function Recall from calculus, the derivative of a function f (x) at x  a is defined as f ( a  h)  f ( a ) f (a)  lim h 0 h Example 3 Find f (3) if f ( x)  4 x 2 . Solution f (3  h)  f (3) f (3)  lim h 0 h 4(3  h) 2  4(3) 2  lim h 0 h 4(9  h 2  6h)  36  lim h 0 h 36  4h 2  24h  36  lim h 0 h h(4h  24)  lim h 0 h  lim (4h  24) h 0  24 Example 4   Find f   if f ( x)  sin(2 x) 4 Solution   f   h  4     f    lim  h  4  h0   f  4        sin 2  h    sin 2   4   4     lim h0 h     sin  2h   sin  2  2  lim  h 0 h       sin cos(2h)  cos  sin(2h)  sin  2 2 2     lim h 0 h cos(2h)  0  1  lim h 0 h cos(2h)  1  lim h 0 h 0 from knowing that 1  cos(h) lim 0 h 0 h Second Definition of Derivatives There is another form of the definition of the derivative of a function. The derivative of the function f (x) at x  a is defined as f ( x)  f (a )  f (a)  lim xa xa As x  a , the definition is nothing but the slope of the tangent line at P . f (x) ( x, f ( x)) P f ( x)  f (a ) (a, f (a)) xa Q a x x Figure 5 Graph showing the second definition of the derivative. Example 5 Find f (3) if f ( x)  4 x 2 by using the form f ( x)  f (a ) Solution f (a)  lim xa xa f ( x)  f (3)  f (3)  lim of the definition of a derivative. x 3 x3 4 x 2  4(3) 2  lim x 3 x3 4 x 2  36  lim x 3 x3 4( x 2  9)  lim x 3 x3 4( x  3)( x  3)  lim x 3 x3  lim 4( x  3) x 3  4(3  3)  24 Finding equations of a tangent line One of the numerical methods used to solve a nonlinear equation is called the Newton-Raphson method. This method is based on the knowledge of finding the tangent line to a curve at a point. Let us look at an example to illustrate finding the equation of the tangent line to a curve. Example 6 Find the equation of the line tangent to the function f ( x)  x 3  0.165x  3.993 104 at x  0.05 . Solution The line tangent is a straight line of the form y  mx  c To find the equation of the tangent line, let us first find the slope m of the straight line. f ( x)  3x 2  0.165 f (0.05)  3(0.05) 2  0.165  0.1575 m  0.1575 To find the value of the y -intercept c of the straight line, we first find the value of the function at x  0.05 . f (0.05)  (0.05) 3  0.165(0.05)  3.993 104  0.0077257 0.04 0.03 0.02 f(x) 0.01 0 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 -0.01 -0.02 -0.03 x Figure 6 Graph of function f(x) and the tangent line at x = 0.05. Hence, y  mx  c  0.1575x  0.0001493 is the equation of the tangent line. 0.5 Other Notations of Derivatives Derivates can be denoted in several ways. For the first derivative, the notations are d dy f ( x), f ( x), y, and dx dx For the second derivative, the notations are d2 d2y f ( x), f ( x), y, and 2 dx dx2 th For the n derivative, the notations are n n d (n) (n) d y f ( x ), n f ( x ), y , dx dxn Theorems of Differentiation Several theorems of differentiation are given to show how one can find the derivative of different functions. Theorem 1 The derivative of a constant is zero. If f ( x)  k , where k is a constant, f ( x)  0 . Example 7 Find the derivative of f ( x)  6 . Solution f ( x)  6 f ( x)  0 Theorem 2 The derivative of f ( x)  x n , where n  0 is f ( x)  nx n1 . Example 8 Find the derivative of f ( x)  x 6 . Solution f ( x)  x 6 f ( x)  6 x 61  6x 5 Example 9 Find the derivative of f ( x)  x 6 . Solution f ( x)  x 6 f ( x )  6 x 61  6 x 7 6  7 x Theorem 3 The derivative of f ( x)  kg ( x) , where k is a constant is f ( x)  kg ( x) . Example 10 Find the derivative of f ( x)  10x 6 . Solution f ( x)  10x 6 d f ( x)  (10 x 6 ) dx d 6  10 x dx  10(6 x 5 )  60x 5 Theorem 4 The derivative of f ( x)  u ( x)  v( x) is f ( x)  u ( x)  v ( x) . Example 11 Find the derivative of f ( x)  3x 3  8 . Solution f ( x)  3 x 3  8 d f ( x)  (3x 3  8) dx d d  (3x 3 )  (8) dx dx d  3 (x3 )  0 dx  3(3x 2 )  9x 2 Theorem 5 The derivative of f ( x )  u ( x )v ( x ) is d d f ( x)  u ( x) v( x)  v( x) u ( x) . (Product Rule) dx dx Example 12 Find the derivative of f ( x)  (2 x 2  6)(3x 3  8) Solution Using the product rule as given by Theorem 5 where, f ( x )  u ( x )v ( x ) d d f ( x)  u ( x) v( x)  v( x) u ( x) dx dx 2 3 f ( x)  (2 x  6)(3x  8) 2 u ( x)  2 x  6 v( x )  3 x 3  8 Taking the derivative of u (x) , du d  (2 x 2  6) dx dx d d 2  (2 x )  (6) dx dx Taking the derivative of v (x ) , d 2  2 (x )  0 dv d dx  (3x 3  8)  2( 2 x ) dx dx d d  4x 3  (3x )  (8) dx dx d 3  3 (x )  0 dx  3(3x 2 )  9x 2 Using the formula for the product rule d d f ( x)  u ( x) v( x)  v( x) u ( x) dx dx 2 2 3  (2 x  6)(9 x )  (3x  8)(4 x)  18 x  54 x  12 x  32 x 4 2 4  30 x  54 x  32 x 4 2 Theorem 6 The derivative of u ( x) f ( x)  v( x) is d d v( x) u ( x)  u ( x) v( x) dx dx  f ( x)  (Quotient Rule) 2 (v( x)) Example 13 (2 x 2  6) Find the derivative of f ( x)  . 3 (3x  8) Solution Use the quotient rule of Theorem 6, if u ( x) f ( x)  v( x) then d d v( x) u ( x)  u ( x) v( x) dx dx f ( x)  2 (v( x)) From Taking the derivative of v (x ) , (2 x 2  6) dv d 3 f ( x)   ( 3 x  8) (3x 3  8) dx dx we have d d 3  (3x )  (8) u ( x)  2 x 2  6 dx dx 3 v( x)  3 x  8 d 3  3 (x )  0 Taking the derivative of u (x) , dx du d  3(3x 2 )  (2 x 2  6) dx dx 2  9x d d 2  (2 x )  dx dx d 2  2 (x )  0 dx  2(2 x)  4x (6) Using the formula for the quotient rule, (3x 3  8)(4 x)  (2 x 2  6)(9 x 2 ) f ( x)  3 2 (3x  8) 12x 4  32x  18x 4  54x 2  9 x 6  48x 3  64 4 2  6 x  54x  32x  9 x 6  48x 3  64 Table of Derivatives f (x) f (x) xn , n  0 nx n 1 kx n , n  0 knx n 1 sin(x) cos(x) cos(x)  sin(x) tan(x) sec 2 ( x) sinh(x) cosh(x) cosh(x) sinh(x) tanh (x) 1  tanh2 ( x) 1 sin ( x) cos 1 ( x) tan1 ( x) csc(x) 1 1 x2 1 1 x2 1 1 x2  csc( x)cot ( x) sec(x) sec( x)tan( x) cot (x)  csc2 ( x) csch(x)  coth( x)csch( x) sech(x)  tanh ( x) sech( x) coth(x) 1  coth2 ( x) csc1 ( x)  sec1 ( x) cot 1 ( x) |x| x2 x2 1 |x| x2 x2 1 1 1 x2 ax ln(a)a x ln(x) 1 x loga (x) 1 xln(a) ex ex Chain Rule of Differentiation Sometimes functions that need to be differentiated Do not fall in the form of simple functions or the Forms described previously. Such functions can be differentiated using the chain rule if they are of the form f ( g ( x)) . The chain rule states d ( f ( g ( x))  f ( g ( x)) g ( x) dx For example, to find f (x) of f ( x)  (3x 2  2 x) 4 , one could use the chain rule. 2 g ( x)  (3x  2 x) g ( x)  6 x  2 3  f ( g ( x))  4( g ( x)) d 2 4 2 3 ((3x  2 x) )  4(3x  2 x) (6 x  2) dx Implicit Differentiation Sometimes, the function to be differentiated Is not given explicitly as an expression of the independent variable. In such cases, how do we find the derivatives? We will discuss this via examples. Example 14 dy 2 2 Find if x  y  2 xy dx Solution x  y  2 xy d 2 d 2 ( x  y )  (2 xy) dx dx d 2 d 2 d (x )  ( y )  (2 xy) dx dx dx dy dy 2x  2 y  2x  2 y dx dx 2 2 dy dy 2 y  2x  2 y  2x dx dx dy (2 y  2 x)  2 y  2x dx dy 2 y  2 x  dx 2 y  2 x dy 1 dx Example 15 If x 2  xy  y 2  5 , find the value of y  . Solution x 2  xy  y 2  5 d 2 d 2 ( x  xy  y )  (5) dx dx d 2 d d 2 ( x )  ( xy)  ( y )  0 dx dx dx dy dy 2x  x  y  2 y 0 dx dx dy ( x  2 y )  2 x  y dx dy y  2 x  dx 2 y  x y  2x y  2y  x Higher order derivatives So far, we have limited our discussion to calculating first derivative, f (x) of a function f (x) . What if we are asked to calculate higher order derivatives of f (x) . A simple example of this is finding acceleration of a body from a function that gives the location of the body as a function of time. The derivative of the location with respect to time is the velocity of the body, followed by the derivative of velocity with respect to time being the acceleration. Hence, the second derivative of the location function gives the acceleration function of the body. Example 16 Given f ( x)  3x 3  2 x  7 , find the second derivative, f (x) and the third derivative, f (x) . Solution Given f ( x)  3 x 3  2 x  7 we have f ( x)  3(3x 2 )  2 2  9x  2 d f ( x)  ( f ( x)) dx d 2  (9 x  2) dx  9(2 x)  18 x d f ( x)  ( f ( x)) dx d  (18 x) dx  18 Example 17 If x 2  xy  y 2  5 , find the value of y  . Solution From Example 15 we obtain y  2x , y  2y  x (2 y  x) y   y  2 x d d ((2 y  x) y)  ( y  2 x) dx dx d d d d (2 y  x) ( y)  y (2 y  x)  ( y )  (2 x) dx dx dx dx y(2 y  x)  y(2 y  1)  y  2 2 2 y  2  2 y y  2y  x After substitution of y  ,  y  2x  y  2x  2  2  2 2y  x 2y  x   y   2y  x 6( y  xy  x )  3 (2 y  x) 2 2 2 THE END Differentiation-Continuous Functions EE 48C 7/30/2016 1 Forward Difference Approximation lim f x  Δx   f x  f x   Δx  0 Δx For a finite ' Δx' f x  x   f  x  f x   x 2 Graphical Representation Of Forward Difference Approximation f(x) x x+Δx Figure 1 Graphical Representation of forward difference approximation of first derivative. 3 Example 1 The velocity of a rocket is given by   14  104  t   2000ln   9.8t ,0  t  30 4 14  10  2100 t   where 'ν' is given in m/s and 't ' is given in seconds. a) Use forward difference approximation of the first derivative of ν t  to calculate the acceleration at t  16s . Use a step size of Δt  2s . b) Find the exact value of the acceleration of the rocket. c) Calculate the absolute relative true error for part (b). 4 Example 1 Cont. Solution ati    ti 1   ti  t ti  16 Δt  2 ti 1  ti  t  16  2  18 a16   5  18  16 2 Example 1 Cont.   14  104  18  2000ln  9.818  4 14  10  210018  453.02m/s   14 104  16  2000ln  9.816  4 14 10  210016  392.07m/s Hence a16   6  18  16 2 Example 1 Cont.  453.02  392.07 2  30.474m/s 2 b) The exact value of a 16  can be calculated by differentiating   14 104  t   2000ln   9.8t 4 14 10  2100t  as d at   νt  dt 7 Example 1 Cont. Knowing that d ln t   1 dt t and d 1 1   dt  t  t2  14  104  2100t  d   14  104   a t   2000 4  dt  14  104  2100t   9.8 14  10     4   14  10 4  2100t  14  10  1  2000 4  14 10 4  2100t 14 10      8  4040  29.4t  200  3t   2100   9.8 2    Example 1 Cont.  4040  29.416   a 16   200  316  29.674m/s 2 The absolute relative true error is t   True Value - Approximat e Value x100 True Value 29.674  30.474 x100 29.674  2.6967% 9 Backward Difference Approximation of the First Derivative We know lim f x  Δx   f x  f x   Δx  0 Δx For a finite ' Δx' , f x   f x  x   f  x  x If ' Δx' is chosen as a negative number, f x    10 f x  x   f x   x f x   f x  Δx  Δx Backward Difference Approximation of the First Derivative Cont. This is a backward difference approximation as you are taking a point backward from x. To find the value of f x  at x  xi, we may choose another point ' Δx' behind as x  x . This gives f xi   f xi   f xi 1  x  f xi   f xi 1  xi  xi 1 where Δx  xi  xi 1 11 i 1 Backward Difference Approximation of the First Derivative Cont. f(x) x x-Δx x Figure 2 Graphical Representation of backward difference approximation of first derivative 12 Example 2 The velocity of a rocket is given by   14  104  t   2000ln   9.8t ,0  t  30 4 14  10  2100 t   where 'ν' is given in m/s and 't ' is given in seconds. a) Use backward difference approximation of the first derivative of ν t  to calculate the acceleration at t  16 s . Use a step size of Δt  2s . b) Find the absolute relative true error for part (a). 13 Example 2 Cont. Solution at    ti   ti 1  t ti  16 Δt  2 ti 1  ti  t  16  2  14 a16   14  16  14 2 Example 2 Cont.   14  104  16  2000ln  9.816  4 14  10  210016  392.07m/s   14  104  14  2000ln  9.814  4 14  10  210014  334.24m/s a16     16  14 2 392.07  334.24 2  28.915m/s 2 15 Example 2 Cont. The exact value of the acceleration at t  16 s from Example 1 is a16  29.674m/s2 The absolute relative true error is t  29.674  28.915 x100 29.674  2.5584% 16 Derive the forward difference approximation from Taylor series Taylor’s theorem says that if you know the value of a function ' f ' at a point xi and all its derivatives at that point, provided the derivatives are continuous between xi and xi 1 , then f xi  xi 1  xi 2   f xi 1   f xi   f xi xi 1  xi   2! Substituting for convenience Δx  xi 1  xi f xi  Δx 2   2! f xi 1   f xi  f xi  x    f xi    x 2! f xi 1   f xi   f xi Δx  f xi   17 f xi 1   f xi   0x  x Derive the forward difference approximation from Taylor series Cont. The 0x  term shows that the error in the approximation is of the order of Δx  . Can you now derive from Taylor series, the formula for backward divided difference approximation of the first derivative? As shown above, both forward and backward divided difference approximation of the first derivative are accurate on the order of 0x  . Derive the forward difference approximation from Taylor series Cont. Can we get better approximations? Yes, another method to approximate the first derivative is called the Central difference approximation of the first derivative. Derive the forward difference approximation from Taylor series Cont. From Taylor series f xi  f xi  2 x   x 3   f xi 1   f xi   f xi x  2! 3! f xi 1   f xi   f xi Δx  f xi  f  xi  2 Δx   Δx 3   2! 3! Subtracting equation (2) from equation (1) 2 f xi  Δx 3   f xi 1   f xi 1   f xi 2Δx   3! f xi 1   f xi 1  f  xi  x 2   f  xi    2x 3! f xi   20 f xi 1   f xi 1  2  0x  2x Central Divided Difference Hence showing that we have obtained a more accurate formula as the error is of the order of 0Δx 2 f(x) x x-Δx x x+Δx Figure 3 Graphical Representation of central difference approximation of first derivative 21 Example 3 The velocity of a rocket is given by   14  104  t   2000ln   9.8t ,0  t  30 4 14  10  2100 t   where 'ν' is given in m/s and 't ' is given in seconds. (a) Use central divided difference approximation of the first derivative of ν t  to calculate the acceleration at t  16s . Use a step size of Δt  2s. (b) Find the absolute relative true error for part (a). 22 Example 3 cont. Solution: ati    ti 1   ti 1  ti  16 t  2 a16   23 2t  18  14 22  18  14  4 ti 1  ti  t  16  2  18 ti 1  ti  t  16  2  14 Example 3 cont.   14  104  18  2000ln  9.818  4 14  10  210018  453.02m/s   14  104  14  2000ln  9.814  4 14  10  210014  334.24m/s a16    18  14 4 453.02  334.24  29.694m/s 2  4 24 Example 3 cont. The exact value of the acceleration at t  16 s from Example 1 is a16  29.674m/s2 The absolute relative true error is 29.674  29.694 t  100 29.674  0.069157% 25 Comparision of FDD, BDD, CDD The results from the three difference approximations are given in Table 1. Table 1 Summary of a (16) using different divided difference approximations Type of Difference Approximation Forward Backward Central 26 a16  m / s  t % 30.475 28.915 29.695 2.6967 2.5584 0.069157 2 Finding the value of the derivative within a prespecified tolerance In real life, one would not know the exact value of the derivative – so how would one know how accurately they have found the value of the derivative. A simple way would be to start with a step size and keep on halving the step size and keep on halving the step size until the absolute relative approximate error is within a pre-specified tolerance. 27 Take the example of finding v t  for   14  104  t   2000ln  9.8t  4 14  10  2100t  at t  16 using the backward divided difference scheme. Finding the value of the derivative within a prespecified tolerance Cont. Given in Table 2 are the values obtained using the backward difference approximation method and the corresponding absolute relative approximate errors. Table 2 First derivative approximations and relative errors for different Δt values of backward difference scheme t 2 1 0.5 0.25 0.125 29 v t  28.915 29.289 29.480 29.577 29.625 a % 1.2792 0.64787 0.32604 0.16355 Finding the value of the derivative within a prespecified tolerance Cont. From the above table, one can see that the absolute relative approximate error decreases as the step size is reduced. At t  0.125 the absolute relative approximate error is 0.16355 %, meaning that at least 2 significant digits are correct in the answer. 30 Finite Difference Approximation of Higher Derivatives One can use Taylor series to approximate a higher order derivative. For example, to approximate f  x  , the Taylor series for f xi  f xi  2 2Δx   2Δx 3   f xi  2   f xi   f xi 2Δx   2! 3! where xi  2  xi  2Δx (Eq 3) f  xi  f xi  2 x   x 3  f xi 1   f xi   f xi x   2! 3! 31 (Eq 4) Finite Difference Approximation of Higher Derivatives Cont. Subtracting 2 times equation (4) from equation (3) gives f xi  2   2 f xi 1    f xi   f xi Δx   f xi Δx   2 f xi   f xi   32 f xi  2   2 f xi 1   f xi  Δx  2  f xi Δx    f xi  2   2 f xi 1   f xi  Δx  2 3  0Δx  (Eq 5) Example 4 The velocity of a rocket is given by   14  104  t   2000ln  9.8t ,0  t  30  4 14  10  2100t  Use forward difference approximation of the second derivative of ν t  to calculate the jerk at t  16s. Use a step size of Δt  2s . 33 Example 4 Cont. Solution: j ti   ti  16  ti  2   2 ti 1   ti  t 2 t  2 ti 1  ti  t  16  2  18  20  2 18  16   j 16  22 34 ti  2  ti  2t   16  22  20 Example 4 Cont.   14  104  20  2000ln  9.820  4 14  10  210020  517.35m/s   14  104  18  2000ln  9.818  4 14  10  210018  453.02m / s   14  104  16  2000ln  9.816  4 14  10  210016  392.07m/s 35 Example 4 Cont. j 16   517.35  2453.02   392.07 4  0.84515m/s 3 The exact value of j 16  can be calculated by differentiating   14  104  t   2000ln   9.8t 4 14  10  2100 t   twice as d νt  at   dt 36 and j t   d at  dt Example 4 Cont. Knowing that d ln t   1 dt t and d 1 1   dt  t  t2  14  104  2100t  d   14  104   a t   2000 4  dt  14  104  2100t   9.8 14  10     4    14  10 4  2100t  14  10   2100   9.8  1  2000 2  4 4  14  10    14  10  2100t    4040  29.4t   200  3t 37 Example 4 Cont. Similarly it can be shown that d at  dt 18000  (200  3t ) 2 j t   j 16  18000 [200  3(16)]2  0.77909m/s3 The absolute relative true error is t  0.77909  0.84515 100 0.77909  8.4797 % 38 Higher order accuracy of higher order derivatives The formula given by equation (5) is a forward difference approximation of the second derivative and has the error of the order of Δx  . Can we get a formula that has a better accuracy? We can get the central difference approximation of the second derivative. 39 The Taylor series for f xi 1   f xi   f xi x    f xi  x 2  f xi  x 3  f xi  x 4  2! 3! 4! (Eq 6) where xi 1  xi  Δx f xi 1   f xi   f xi x  where xi 1  xi  Δx   f xi  x 2  f xi  x 3  f xi  x 4  2! 3! 4! (Eq 7) Higher order accuracy of higher order derivatives Cont. Adding equations (6) and (7), gives 4    x 2 f xi 1   f xi 1   2 f xi   f xi x   f xi  12 f  xi   f xi   41 f  xi 1   2 f  xi   f  xi 1  Δx 2 f  xi Δx   12 f xi 1   2 f xi   f xi 1  Δx 2  0Δx  2 2 Example 5 The velocity of a rocket is given by   14  104  t   2000ln  9.8t ,0  t  30  4 14  10  2100t  Use central difference approximation of second derivative of ν t  to calculate the jerk at t  16s . Use a step size of Δt  2s. 42 Example 5 Cont. Solution: ati   t i  16 j 16  43  ti 1   2 ti   ti 1  t 2 ti 1  ti  t  16  2  18 t  2  18  2 16  14 2 2 ti 1  ti  t  16  2  14 Example 5 Cont.   14  104  18  2000ln  9.818  4 14  10  210018  453.02m/s   14  104  16  2000ln   9.816 4   14  10  2100 16    392.07m/s   14  104  14  2000ln  9.814  4 14  10  210014  334.24m/s 44 Example 5 Cont. j 16    18  2 16  14 22 453.02  2392.07   334.24 4  0.77969 m/s 3 The absolute relative true error is t  0.77908  0.78  100 0.77908  0.077992% 45 THE END Differentiation - Discrete Functions EE 48C – Numerical Methods with Computer Applications 7/30/2016 1 Recall: Forward Difference Approximation lim f x  Δx   f x  f x   Δx  0 Δx For a finite ' Δx' f x  x   f  x  f x   x 2 Graphical Representation Of Forward Difference Approximation f(x) x x+Δx Figure 1 Graphical Representation of forward difference approximation of first derivative. 3 Example 1 The upward velocity of a rocket is given as a function of time in Table 1. Table 1 Velocity as a function of time t s 0 10 15 v(t) m/s 0 227.04 362.78 20 517.35 22.5 602.97 30 901.67 Using forward divided difference, find the acceleration of the rocket at t  16 s . 4 Example 1 Cont. Solution To find the acceleration at t  16s , we need to choose the two values closest to t  16s, that also bracket t  16s to evaluate it. The two points are t  15s and t  20s .  ti 1   ti  ati   t 5 ti  15 ti 1  20 t  ti 1  ti  20  15 5 Example 1 Cont.  20  15 a16   5 517.35  362.78  5  30.914 m/s 2 6 Direct Fit Polynomials In this method, given ' n  1' data points x0 , y0 , x1 , y1 , x2 , y2 ,, xn , yn  one can fit a n th order polynomial given by Pn x   a0  a1 x    an1 x n1  an x n To find the first derivative, dPn ( x ) Pnx    a1  2a 2 x    n  1a n 1 x n 2  na n x n 1 dx Similarly other derivatives can be found. 7 Example 2-Direct Fit Polynomials The upward velocity of a rocket is given as a function of time in Table 2. Table 2 Velocity as a function of time t v(t) s m/s 0 0 10 227.04 15 362.78 20 517.35 22.5 602.97 30 901.67 Using the third order polynomial interpolant for velocity, find the acceleration of the rocket at t  16 s . 8 Example 2-Direct Fit Polynomials cont. Solution For the third order polynomial (also called cubic interpolation), we choose the velocity given by vt   a0  a1t  a2t 2  a3t 3 9 Since we want to find the velocity at t=16s, and we are using third order polynomial, we need to choose the four points closest to t=16s and that also bracket t=16s to evaluate it. The four points are to  10, t1  15, t2  20, and t3  22.5. to  10, vto   227.04 t1  15, vt1   362.78 t 2  20, vt 2   517.35 t3  22.5, vt3   602.97 10 such that v10  227.04  a0  a1 10  a2 10  a3 10 2 3 v15  362.78  a0  a1 15  a2 15  a3 15 2 3 v20  517.35  a0  a1 20  a2 20  a3 20 2 3 v22.5  602.97  a0  a1 22.5  a2 22.5  a3 22.5 2 Writing the four equations in matrix form, we have 100 1000  a0  227.04 1 10 1 15   a  362.78 225 3375   1     1 20 400 8000  a2  517.35      1 22.5 506.25 11391  a3  602.97  11 3 Solving the above four equations gives a0  4.3810 a1  21.289 a2  0.13065 a3  0.0054606 Hence vt   a0  a1t  a2t 2  a3t 3  4.3810  21.289t  0.13065t 2  0.0054606t 3 , 10  t  22.5 12 Example 2-Direct Fit Polynomials cont. Figure 1 Graph of upward velocity of the rocket vs. time. 13 , Example 2-Direct Fit Polynomials cont. The acceleration at t=16 is given by d a16   vt  t 16 dt 14 Given that  t   4.3810  21.289t  0.13065t 2  0.0054606t 3 ,10  t  22.5 at  d  vt  dt   d  4.3810  21.289t  0.13065t 2  0.0054606t 3 dt   21.289  0.26130t  0.016382t 2 , 10  t  22.5 a16  21.289  0.2613016  0.01638216 2  29.664m/s 2 15 Lagrange Polynomial In this method, given x1 , y1 ,, xn , yn  , one can fit a n  1th order Lagrangian polynomial given by f n ( x)  where ‘ n ’ in n  L ( x) f ( x ) i 0 i i f n (x) stands for the n th order polynomial that approximates the function y  f (x) given at (n  1) data points as x0 , y0 , x1 , y1 ,......,xn1 , yn1 , xn , yn  , and n Li ( x)   j 0 j i x  xj xi  x j Li (x) a weighting function that includes a product of (n  1) terms with terms of j i 16 omitted. Lagrange Polynomial Cont. Then to find the first derivative, one can differentiate f n x  once, and so on for other derivatives. For example, the second order Lagrange polynomial passing through x0 , y0 , x1, y1 , x2 , y2  f 2 x   is x  x1 x  x2  f x   x  x0 x  x2  f x   x  x0 x  x1  f x  x0  x1 x0  x2  0 x1  x0 x1  x2  1 x2  x0 x2  x1  2 Differentiating equation (2) gives 17 Lagrange Polynomial Cont. 2 x  x0  x2  2 x  x0  x1  2 x  x1  x2   f 2 x   f x0   f x1   f x  x0  x1 x0  x2  x1  x0 x1  x2  x2  x0 x2  x1  2 Differentiating again would give the second derivative as f 2x   18 2 x0  x1 x0  x2  f x0   2 x1  x0 x1  x2  f x1   2 x2  x0 x2  x1  f x2  Example 3 The upward velocity of a rocket is given as a function of time in Table 3. Table 3 Velocity as a function of time t s v(t) m/s 0 10 15 0 227.04 362.78 20 517.35 22.5 602.97 30 901.67 Determine the value of the acceleration at t  16 s using the second order Lagrangian polynomial interpolation for velocity. 19 Example 3 Cont. Solution  t  t1  t  t 2   t  t 0  t  t 2   t  t 0  t  t1   v(t 0 )     v(t1 )   v(t 2 ) v(t )    t 0  t1  t 0  t 2   t1  t 0  t1  t 2   t 2  t 0  t 2  t1  at   2t  t1  t 2  2t  t 0  t 2   t 0    t1   2t  t0  t1  νt2  t 0  t1 t 0  t 2  t1  t 0 t1  t 2  t2  t0 t2  t1  216  15  20 216  10  20 362.78  216  10  15 517.35  227.04 a16  20  1020  15 15  1015  20 10  1510  20  0.06227.04   0.08362.78  0.14517.35  29.784m/s 2 20 THE END