Numerical Differentiation               

 

In calculus we learn that the derivative of a function is defined as the limit


We then proceed in evaluating a few of these limits as examples and then we learn some rules which produce the derivative of the function in a shortcut.  These shortcuts are different for different classes of functions.  For example we all know that


 

In calculus, we also learn that the value of the derivative for some value of the independent variable, say t = t0, gives the slope of the line which is tangent to the curve represented by the function itself at the point t = t0 .

This is geometrically shown in the graph below.  Notice that the process of the limit is also shown with Dt representing the horizontal distance between the two points of the secant line.

 


     

 


The light blue line is a secant of the curve with a large Dt, the darker blue line is another secant with smaller Dt and the red line is the tangent ( a secant with Dt equal to zero).

 

There are many instances when the analytic calculation of the derivative of a given function is not possible.  This may occur when the function under consideration is not one of the standard functions for which the shortcuts have been established and documented.  Rather than going through a very laborious (and probably impossible) task of calculating the limits needed for the analytic calculation, we can try to evaluate the derivative by mimicking the process of  the limit numerically.  We use a secant to represent the tangent (and its slope produces the value of the derivative).  We take progressively closer points (smaller Dt) until the value of the slope stops changing significantly.

 

Now let's look at the secant again:

 


We can see that as the two intersection points get closer, the secant will look more like a tangent.  But there is a basic question here. How are we supposed to move the points so that they get close together?  Depending on the answer to this question we have three different formulas for the numerical calculation of derivative.

If we fix the point A and we keep bringing the point B closer to the left, then we obtain the forward derivative at point A  .  If we fix B and we keep moving A closer then we obtain the backward derivative at point B.  If we fix the middle point of the interval between A and B and we keep bringing both A and B closer to the center then we obtain the central derivative at the midpoint between A and B.

 

These three formulas are summarized here for easy reference:

 


 


All three formulas give approximations to the derivative at the point  t.  It can be shown that the third formula is more accurate than the others. 

Consider the table given below which lists the values of a function G(x) for various values of x ranging from x = -1.0 to x = +2.0 at uniform increments of 0.25.  This table is all we know about the function G(x).

 

x

G(x)

-1.00

-0.841

-0.75

-0.682

-0.50

-0.479

-0.25

-0.247

+0.00

0.0

+0.25

0.247

+0.50

0.479

+0.75

0.682

+1.00

0.841

+1.25

0.949

+1.50

0.997

+1.75

0.984

+2.00

0.909

   

Using the above formulas we can generate three different approximations to the derivative of the function at the values of x shown.  For example we have:

 

The forward difference approximation at the point x = 0.5 is  G'(x) = (0.682 - 0.479) / 0.25 = 0.812.

The backward difference approximation at the point x = 0.5 is G'(x) = (0.479 - 0.247) / 0.25 = 0.928.

The central difference approximation at the point x = 0.5 is G'(x) = (0.682 - 0.247) / 0.50 = 0.870.

 

Notice that all three are different. Also, the central difference is the average of the other two.  This is NOT a coincidence.  You can actually show that this must be the case. Also notice that at the points x = -1.0 and x = +2.0 ( the end points of our interval) we cannot calculate more than a single approximation.

 

If we want the calculation of the derivative at all points of the table, then a spreadsheet is very appropriate for this type of problem.  We enter the table to a sheet and then we can use the formulas to generate three more columns, which will contain the approximations to the derivative. This spreadsheet is shown below and we can see one of the formulas inserted in cell C7