TL;DR
A derivative is a limit of differences: the slope at a point is the change in the function over a tiny step, divided by that step. The finite difference method stops short of the limit. It picks a small but finite step , replaces each derivative in an equation with a difference over that step, and solves the resulting algebraic equations on a grid of points. The cost is a controlled error that shrinks as shrinks, and a stability condition that limits how large a time step can be.
Where you'll see it: in weather and climate models, heat conduction and fluid simulations, option pricing, and any code that solves a differential equation numerically without a closed-form answer.
Intuition
Suppose you know a car's position at two moments one second apart, and you want its speed. The average speed over that second is the change in position divided by one second. That number is not the instantaneous speed, but if the car is not accelerating wildly, it is close. Shrink the interval to a tenth of a second and the estimate tightens. The finite difference method is that same idea applied to any function and any derivative.
The reason it is needed is practical. Most differential equations describing real systems, such as the flow of heat through a metal plate or air over a wing, have no formula for the answer. A computer cannot store a function at every point of a continuum. It can store the function at a finite set of points, a grid, and compute with those values. Replace every derivative with a difference between neighbouring grid values, and the differential equation becomes a large system of algebraic equations.
The plot below shows the central idea in one picture. The true slope of at is the slope of the tangent line. A difference over a finite step uses a secant line through two nearby points, which is close to the tangent when the step is small.
- sin x
- tangent at x = 1
- secant over h = 0.1
The math
The basic formulas
Let be a smooth function, and let be a step. Three standard approximations to the first derivative are
Here is the function evaluated one step to the right of , and one step to the left. A second derivative can be approximated by
The forward and backward differences look at only one side of . The central difference uses both sides, and that symmetry is what gives it a better accuracy.
Where the error comes from
Expand around with the Taylor series:
Substitute this into the forward difference and divide by :
The difference from the true derivative is . This is a truncation error that is proportional to , so the forward difference is said to be first-order accurate. Halving halves the error.
Now expand both and and subtract. The even-power terms cancel, leaving
The error is proportional to , so the central difference is second-order accurate. Halving cuts the error by about a factor of four. The cancellation of the even terms is the entire reason the central difference is better, and it is worth remembering: symmetric stencils cancel error terms that one-sided stencils keep.
The same method gives the second-derivative formula. Its error is also of order .
Solving a differential equation on a grid
Take the one-dimensional heat equation with diffusivity ,
where is the temperature. Place grid points and time levels , and write for the approximate temperature at . Use a forward difference in time and the central second difference in space:
Solve for the new value:
This is an explicit scheme. Every value at the new time level is computed from values at the old level, so each step is a simple update.
Stability
The explicit scheme has a limit. The update amplifies high-frequency wiggles in the solution, and if is too large the errors grow without bound. For this scheme the condition is
This comes from von Neumann stability analysis. It is the diffusion counterpart of the Courant–Friedrichs–Lewy condition, which says for wave-like equations that a numerical method cannot propagate information faster than the grid allows. Refining the grid in space forces a smaller time step, so explicit schemes become expensive as resolution increases. Implicit schemes, which solve a linear system for the new level, avoid this limit at the price of more work per step.
Worked examples
Estimate for . The exact value is to six decimals.
- Use step . Evaluate , , .
- Forward difference: . Error .
- Central difference: . Error .
- Compare with the predicted errors. The forward error should be about , which differs from the measured error only by the next Taylor term, about . The central error should be about , which agrees with the measured .
Interpretation: at the same step size, the central difference is about 50 times more accurate here. Its error scales as , and the forward error as .
Take , a grid with three interior points, zero temperature at both ends, and an initial profile . Use , which satisfies the stability condition.
- Point 1: .
- Point 2: .
- Point 3: by symmetry .
- The new profile is . Its total is , the same as before.
Interpretation: the peak spread out into its neighbours, as heat should. The total heat in the interior stayed the same here, because the zero-temperature boundaries were not reached yet.
Now repeat the same step with , which violates the condition. Point 2 becomes . A negative temperature appears from a profile that started nonnegative, which is unphysical. Repeating the step with this makes the oscillations grow, and the solution blows up.
Let , so . Find with the central second difference and .
- Evaluate: , , .
- Numerator: .
- Divide by : .
- The exact value is .
Interpretation: the error term of the second difference involves the fourth derivative, , and for a cubic that is zero. The method is exact for polynomials up to degree three. This is a useful sanity check when implementing a scheme.
Tradeoffs and failure modes
The method is simple, fast and flexible, but three problems show up in practice.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Step made very small to get accuracy | Round-off error grows: subtracting nearly equal numbers loses digits, so the error rises again as shrinks | Choose near the balance point, about (roughly ) for a forward difference in double precision, and nearer for a central one, or use a higher-order stencil |
| Explicit time stepping on a fine grid | The Courant or stability limit forces tiny time steps, and the run becomes very slow | Implicit schemes such as Crank–Nicolson or backward Euler, which trade extra work per step for a looser limit |
| Irregular geometry or complex boundaries | Grid points fit a rectangle, not a curved shape, and the stencils become messy | Finite element or finite volume methods, which build the discretisation on arbitrary meshes |
| Solution with sharp fronts, such as shocks | A fixed grid smears or oscillates near the front, and the stencil loses accuracy | Adaptive mesh refinement or upwind schemes that respect the direction of information flow |
| Unexpected oscillations or blow-up | Often a stability violation, not a coding bug | Check the stability condition for the scheme before debugging the code |
A further trap is to trust the output because it looks smooth. A finite difference solution is an approximation of an exact solution, and its accuracy must be checked. The standard approach is to refine the grid and see whether the answer converges at the expected rate, or to test on a problem with a known answer.
History
The idea of replacing derivatives with differences is as old as calculus. Leonhard Euler's 1768 method for solving ordinary differential equations, which steps forward using the slope at the current point, is a finite difference scheme in its simplest form.
The method became a practical tool for partial differential equations in the early twentieth century. In 1910, Lewis Fry Richardson attempted a numerical weather forecast by hand, using finite differences on a grid of cells over Europe, and published the approach in 1922 in his book on numerical weather prediction. His forecast failed, largely because of errors in the initial data, but the method was sound.
The stability question was settled in 1928, when Richard Courant, Kurt Friedrichs and Hans Lewy showed that explicit difference schemes for hyperbolic equations must satisfy a condition linking the time step, the grid spacing and the wave speed. The condition is named after them. The arrival of electronic computers after the Second World War made finite difference methods routine, and they remain central to computational physics and engineering.
Check yourself
QuestionFor at (where ), a forward difference with gives roughly . What is the error, and what would you expect from ?Show answer
The error is . The forward error is about , which matches. Since the forward error is first order, halving to should roughly halve the error to about . Round-off error is negligible at this step size, so the prediction holds.
QuestionCompute the central difference approximation to for with . Why is the answer exact?Show answer
Evaluate and . Then . The exact derivative is . The answer is exact because the error term of the central difference is proportional to , and for a quadratic is zero. The symmetric stencil cancels all the even-power terms of the Taylor expansion, leaving only the odd terms, and the first odd term beyond vanishes here.
QuestionAn explicit heat solver uses , , and . Is it stable? If not, what is the largest stable time step?Show answer
Compute . Since , the scheme is unstable. The largest stable step satisfies , which gives . Halving the grid spacing would cut the stable step by a factor of four.
QuestionA colleague says that making the step as small as possible in a central difference will always give the most accurate derivative. Explain what is wrong with this claim.Show answer
Truncation error falls as , but round-off error rises as shrinks, because the difference subtracts two nearly equal numbers and loses significant digits. Past a certain point, making smaller makes the total error worse. The most accurate step is a balance between the two, and it depends on the precision of the arithmetic and the size of the derivatives involved. The claim assumes exact arithmetic, which a computer does not provide.