Central Difference Explained with Worked Examples

Numerical derivatives: and . Both have error of order .

Write 2x or 2*x to multiply, ^ for powers, and ; between simultaneous equations. You can also type factor, expand, derivative of, integrate … from a to b, limit … as x->0 or 15% of 80.

Try an example

Before you start

This page is easier if you are comfortable with:

What Central difference means

For at , : against the exact (error ). The second derivative: against the exact . For at 2 with : vs the exact 12; the error is .

The error term comes from Taylor expansions of (Taylor series): the odd powers of cancel in the central difference, so the error is , better than the one-sided with error (derivative from first principles). Too small causes rounding errors from subtracting nearly equal numbers.

These formulas are used in difference schemes for differential equations: the second difference is the building block of the five-point stencil and the schemes of explicit heat schemes and the CFL condition. The derivatives approximated are those of sine and powers.

What is it used for?

Central differences approximate derivatives from values on either side of a point, with error of order h squared.

How to use central difference

  1. Choose a step .
  2. Evaluate at , , .
  3. Apply the first or second difference formula.
  4. Halve to check that the error falls by about 4.

Graph

Central difference error for f = sin x at x = 1 against the step hh = 0.1: 0.00090.050.10.150.20.250.30.350.40.450.500.0020.0040.0060.0080.01Central difference error for f = sin x at x = 1 against the step hherror|error|Graph with x from 0.01 to 0.5 and y from 0 to 0.011. Shows the curve |error|; point h = 0.1: 0.0009 at (0.1, 0.0009).

The error grows like h², so halving h cuts it by four.

Worked examples

These examples are worked by hand, step by step, so you can compare your own working.

Example 1: derivative of sin at 1

Estimate for with .

Worked example
Answer
0.53940.5394
  1. Formula

Example 2: second derivative of sin at 1

Estimate with .

Worked example
Answer
−0.8408-0.8408
  1. Formula

Example 3: cubic

Estimate for with .

Worked example
Answer
12.2512.25
  1. Formula

Special cases

A few situations come up again and again. Knowing them saves time and helps you spot answers that cannot be right.

f = x² at 3, h = 0.1

(f(3.1) − f(2.9))/0.2 = 6

Exact for quadratics.

f = sin x at 0, h = 0.1

(sin 0.1 − sin(−0.1))/0.2 ≈ 0.99833

True value 1.

f = eˣ at 0, h = 0.1

≈ 1.00167

True value 1.

Error

O(h²): error ≈ h² f‴/6

sin: 0.00167.

Word problems

The central difference f′(x) ≈ (f(x + h) − f(x − h))/(2h) has error about h² f‴(x)/6, so halving h cuts the error by about four.

x² at 3

Estimate d/dx x² at x = 3 with h = 0.1.

  1. f(3.1)9.61
  2. f(2.9)8.41
  3. Difference ÷ 0.26
  4. Check: exact ✓6.

sin x

Estimate d/dx sin x at 0 with h = 0.1 to 5 decimal places.

  1. (sin 0.1 + sin 0.1)/0.2
  2. Check: 0.99833 ✓0.99833.

Error Higher

Find the error for sin x at 0, h = 0.1.

  1. 1 − 0.99833
  2. Check: 0.00167 ≈ h²/6 ✓0.00167.

Halving h Higher

Estimate with h = 0.05 and compare.

  1. (sin 0.05 − sin(−0.05))/0.1
  2. Check: error ≈ 0.00042, a quarter ✓0.99958.

Common mistakes

Dividing by h

(f(x + h) − f(x − h))/h ✗

divide by 2h ✓

The step is 2h wide.

Too small h

h = 10⁻¹⁶ ✗

rounding error dominates ✓

Use h ≈ 10⁻⁵.

Forward instead of central

(f(x + h) − f(x))/h ✗

error O(h) not O(h²) ✓

Central is more accurate.

Degrees

sin in degrees ✗

radians ✓

Use radians.

Exam tips

  1. Divide by 2h.
  2. Error ∝ h².
  3. Not too small h.
  4. Exact for quadratics.
  5. Radians.

Practice questions

Try each one on paper, then open the answer. Use the solver above to see the full working.

1. x² at 2, h = 0.5 Foundation

4

2. x³ at 1, h = 0.1 to 4 d.p. Foundation

3.01

3. eˣ at 0, h = 0.1 to 5 d.p. Foundation

1.00167

4. cos x at 0, h = 0.1 Higher

0

5. sin x at 0, h = 0.01 to 6 d.p. Higher

0.999983

6. ln x at 1, h = 0.1 to 4 d.p. Higher

1.0034

Practice generator

Unlimited fresh questions with instant marking. Choose a level, work it out on paper, then type your answer.

Solve: …

Key terms

Central difference
(f(x + h) − f(x − h))/2h.
Truncation error
From dropping Taylor terms.
Step size (h)
The spacing.
Rounding error
From finite precision.
Second-order accurate
Error O(h²).
Finite difference
Derivative approximated by values.

Frequently asked questions

What is the central difference?

(f(x + h) − f(x − h))/(2h).

What is its error?

About h² f‴/6.

Is it better than forward difference?

Yes, O(h²) versus O(h).

Which function is exact?

Quadratics.

Which page covers the trapezium rule?

trapezium rule error.

Which page covers the Laplacian stencil?

five-point Laplacian stencil.

More in Numerical methods and optimisation and the formula sheets.