Numerical Methods Lecture 14 Differentiation-Continuous Functions Dr. S. M. Lutful Kabir Visiting Professor, BRAC University & Professor (On-leave), BUET
Forward Difference Approximation For a finite
Forward Difference Approximation Figure 1 Graphical Representation of forward difference approximation of first derivative.
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 Substituting for convenience
Derive the forward difference approximation from Taylor series (cont.) The term shows that the error in the approximation is of the order of Can you now derive from Taylor series the formula for backward divided difference approximation of the first derivative? It can be shown that both forward and backward divided difference approximation of the first derivative are accurate on the order of Can we get better approximation? Yes, another method to approximate the first derivative is called the Central difference approximation of the first derivative.
Backward Difference Approximation of the First Derivative We know For a finite If is chosen as a negative number,
Backward Difference Approximation of the First Derivative (continued) This is a backward difference approximation as you are taking a point backward from x. To find the value of at we may choose another point behind as This gives where,
Backward Difference Approximation of the First Derivative (continued) x-Δx f(x) Figure 2 Graphical Representation of backward difference approximation of first derivative
Derive the backward 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 Substituting for convenience
Derive the Central difference approximation from Taylor series (cont.) Subtracting equation (2) from the first (1),
Central Divided Difference Hence showing that we have obtained a more accurate formula as the error is of the order of . x f(x) x-Δx x x+Δx Figure 3 Graphical Representation of central difference approximation of first derivative
Example 1 The velocity of a rocket is given by where is given in m/s and is given in seconds. Use forward, backward and central divided difference approximation of the first derivative of to calculate the acceleration at . Use a step size of . Find the absolute relative true error for part (a).
Comparison 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 30.475 28.915 29.695 2.6967 2.5584 0.069157
Effect of step size on the accuracy %Error 2 1 0.5 0.25 0.125 28.915 29.289 29.480 29.577 29.625 1.2792 0.64787 0.32604 0.16355
Finite Difference Approximation of Higher Derivatives One can use Taylor series to approximate a higher order derivative. For example, to approximate , the Taylor series for (3) where (4) where
Finite Difference Approximation of Higher Derivatives (cont.) Subtracting 2 times equation (4) from equation (3) gives (5)
Higher order accuracy of higher order derivatives The formula given by equation (5) is a forward difference approximation of 2nd derivative and has error of the order of Can we get a formula that has a better accuracy? We can get the Central difference approximation of the second derivative. The Taylor series for (6) where
Higher order accuracy of higher order derivatives (cont.) (7) where Adding equations (6) and (7), gives
Example 2 The velocity of a rocket is given by Use central difference approximation of second derivative of at . Use a step size of .
Program clear all; clc; f=@(t)(10*exp(-t)-3); f1=@(t)(-10*exp(-t)); f2=@(t)(10*exp(-t)); t=1; delta=0.2; decrement=0.04; disp(' First Derivative') disp(' ------------------') disp( ' Delta Actual Forw Back Central %Err_F %Err_B %Err_C') disp( ' ----------------------------------------------------------------------------------')
Program (continued) for i=1:5 F1F=(f(t+delta)-f(t))/delta; F1B=(f(t)-f(t-delta))/delta; F1C=(f(t+delta)-f(t-delta))/(2*delta); F1A=f1(t); Y(1)=delta; Y(2)=F1A; Y(3)=F1F; Y(4)=F1B; Y(5)=F1C; Y(6)=abs((F1F-F1A)*100/F1A); Y(7)=abs((F1B-F1A)*100/F1A); Y(8)=abs((F1C-F1A)*100/F1A); disp(Y); delta=delta-decrement; end
Program (continued) delta=0.2; disp(' ‘); disp(' Second Derivative') disp( ' Delta Actual Forw Back Central %Err_F %Err_B %Err_C') disp( ' -----------------------------------------------------------------------------------')
Program (continued) for i=1:5 F2F=(f(t)-2*f(t+delta)+f(t+2*delta))/(delta^2); F2B=(f(t-2*delta)-2*f(t-delta)+f(t))/(delta^2); F2C=(f(t+delta)-2*f(t)+f(t-delta))/(delta^2); F2A=f2(t); Y(1)=delta; Y(2)=F2A; Y(3)=F2F; Y(4)=F2B; Y(5)=F2C; Y(6)=abs((F2F-F2A)*100/F2A); Y(7)=abs((F2B-F2A)*100/F2A); Y(8)=abs((F2C-F2A)*100/F2A); disp(Y); delta=delta-decrement; end
Thanks