Skip to main content

Numerical check of difference schemes

Short answer

Exact cos(1)=0.5403. With h=0.1: forward 0.4974, backward 0.5814, central 0.5394. With h=0.05: forward 0.5190, backward 0.5611, central 0.5401. Central error reduces by ~4 (second order), forward/backward by ~2 (first order).

For the function f(x)=sin⁡xf(x)=\sin x (x in radians), evaluate f′(x)f'(x) at x=1.0x=1.0 using forward, backward and central differences with h=0.1h=0.1 and then h=0.05h=0.05. Compare with the exact value, find the percentage errors and verify the order of accuracy of each scheme.

Exact: f′(1)=cos⁡1=0.54030f'(1)=\cos 1=0.54030.

Values needed: sin⁡0.9=0.783327\sin0.9=0.783327, sin⁡0.95=0.813416\sin0.95=0.813416, sin⁡1.0=0.841471\sin1.0=0.841471, sin⁡1.05=0.867423\sin1.05=0.867423, sin⁡1.1=0.891207\sin1.1=0.891207.

h = 0.1

  • Forward: sin⁡1.1−sin⁡1.00.1=0.891207−0.8414710.1=0.49736\dfrac{\sin1.1-\sin1.0}{0.1}=\dfrac{0.891207-0.841471}{0.1}=0.49736
  • Backward: 0.841471−0.7833270.1=0.58144\dfrac{0.841471-0.783327}{0.1}=0.58144
  • Central: 0.891207−0.7833270.2=0.53940\dfrac{0.891207-0.783327}{0.2}=0.53940

h = 0.05

  • Forward: 0.867423−0.8414710.05=0.51904\dfrac{0.867423-0.841471}{0.05}=0.51904
  • Backward: 0.841471−0.8134160.05=0.56111\dfrac{0.841471-0.813416}{0.05}=0.56111
  • Central: 0.867423−0.8134160.1=0.54008\dfrac{0.867423-0.813416}{0.1}=0.54008

Errors

SchemehhValueError% error
Forward0.10.49736-0.042947.95
Forward0.050.51904-0.021263.93
Backward0.10.58144+0.041147.61
Backward0.050.56111+0.020813.85
Central0.10.53940-0.000900.17
Central0.050.54008-0.000230.04

Order of accuracy

Ratio of errors when hh is halved:

  • Forward: 0.04294/0.02126=2.02≈210.04294/0.02126=2.02\approx2^1, so first order.
  • Backward: 0.04114/0.02081=1.98≈210.04114/0.02081=1.98\approx2^1, so first order.
  • Central: 0.00090/0.000225=4.0=220.00090/0.000225=4.0=2^2, so second order.

Here error means (numerical −- exact). The signs agree with theory: the forward formula equals f′+h2f′′f'+\tfrac h2f'', and since f′′=−sin⁡x<0f''=-\sin x<0 its error is negative; the backward error has the opposite sign; the central error is far smaller.

Answer: Central difference is best (0.5394 and 0.5401 against exact 0.5403); forward and backward are O(h)O(h) and central is O(h2)O(h^2).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Applied Computational Fluid Dynamics chapter 3 questions →