A Numerical Second Derivative from Three Points

Three Unevenly-Spaced PointsWhat is the second derivative of three unevenly spaced points?  Is there a formula for the numerical second derivative?

In practice, these points could represent measured data that we want to analyze like weather patterns or financial data. We will see that the second derivative is a linear combination of the three points.

First Derivatives Occur Between the PointsWe have three points, so we can find two first derivatives using those points.

Label the x and y coordinates for the three points and use the finite difference formula to calculate the first derivatives.

These derivatives are not at the points; they occur between pairs of points.  For example, the derivative labeled x=1.5 is the derivative somewhere between x1 and x2. The number 1.5 suggests that it is precisely halfway between them, which is what we are assuming.

First Derivatives and Distance in xThe red dots represent the first derivatives at x=1.5 and x=2.5. We can call these D1 and D2.

We use another finite difference formula to calculate the second derivative. The second derivative is the change in the first derivative divided by the distance between the points where they were evaluated. This is the same as “rise over run,” except that we replace the difference in y coordinates (the “rise”) with the difference in the first derivatives. In this example the difference between the first derivatives is D2 – D1. The distance between those derivatives (the “run”) is half of the distance between x1 and x3.

Equation D2-D1

Equation Second Derivative Initial Answer

Now we plug in what we know about the first derivatives.  This is the answer, but let’s take it a step further.

One thing we can do is to write the second derivative as a linear combination of the y coordinates for the three points.  From this point forward we are doing algebra…

Equation Remove the Denominator

Equation Common DenominatorEquation Expand the ProductsEquation Group the Coefficients
Equation Linear Combination of y Values

Now it is easy to see that the second derivative can be expressed as a linear combination of the y values.

Numerical Second Derivative Equation in Matrix Notation

Here is the Numerical Second Derivative Equation in Matrix Notation

Now for some examples

Example 1 – Evenly Spaced Points

Let’s see how it works with evenly spaced points.  The second derivative of y = x2 is always 2, so this function is a good example.  It turns out that the coefficients [1, -2, 1] work for any three points separated by 1 unit in x.

Second Derivative Example 1

Example 2 – Unevenly Spaced Points

This is similar to the previous example, but the points are no longer evenly spaced.  The third point is further away, and we see that the coefficients [2/3, -1, 1/3] place the smallest emphasis on the third point.  That point is further away and for that reason its value could be very different from the values of the other two points. (In this case 25 is much larger than 4 or 9.)  The small magnitude of the third coefficient helps to balance this out.

Second Derivative Example 2

Example 3 – Nonquadratic Function

Now let’s try something different.  What if we use y = x3 instead of y = x2 to generate the points?

Second Derivative Example 3

From calculus we know that the second derivative for y = x3 is 6*x.  At x = 3 this is 18… but the answer we got was 20.  What happened???

The answer is: This is all being done numerically, not analytically. The numerical process does not have a priori knowledge about the function represented in those three points, so it uses the only model it knows how to use with three data points – a quadratic model.

Here’s another way to look at it.  This calculation process is automatically fitting a quadratic function through the three points and reporting the second derivative for that quadratic function.

If we had four points, we could derive a formula that works for four points.  That formula would do the same thing, except that it would fit a cubic function instead of a quadratic function.  We could do this for any number of points, but then the equations get complicated.

Plot y vs x Cubic and Quadratic Functions

If we look at the cubic function and the fitted quadratic function, it is clear that the quadratic function is just an approximation in the neighborhood of x= 2, 3, and 5.  However, it is a fairly good approximation in that neighborhood, so it makes sense that its first and second derivatives are also reasonably good approximations in that neighborhood.  We can see from the x2 coefficient (which is 10) that the quadratic function has a second derivative of 20.  This agrees with the answer we got from the numerical model.


  1. Interesting, thanks!
    How could we prove rigorously that the finite difference method gives the exact result for a quadratic function?

    • Hi Lorfus. Thanks for the question. You would have to fit a quadratic polynomial ax^2 + bx+ c to the three points and show that the second derivative from these equations equals 2*a from your fitted model. That would be sufficient to prove it.

      On Monday, October 3, 2016, Math for Mere Mortals < comment-reply@wordpress.com > wrote:


  2. How could we prove
    rigorously that the finite
    difference method gives
    the exact result for a
    quadratic function?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s