Finite Difference Generator
Compute finite difference coefficients with exact rational arithmetic and error terms for any derivative order and stencil.
Finite Difference Approximations
Finite differences approximate derivatives of a function \(f(x)\) using values at discrete grid points \(x + jh\), where \(h\) is the step size and \(j\) is an integer offset. They are fundamental to numerical differentiation, solving ODEs and PDEs, and analysing experimental data.
Taylor's Theorem with Remainder
For a sufficiently smooth function \(f\), Taylor expansion about \(x\) gives:
where \(\xi_j\) lies between \(x\) and \(x+jh\). A finite difference formula combines several such expansions so that all Taylor terms cancel except the target derivative and a leading error term.
Common Formulas
- Forward difference: \(f'(x) \approx \dfrac{f(x+h) - f(x)}{h} + O(h)\)
- Backward difference: \(f'(x) \approx \dfrac{f(x) - f(x-h)}{h} + O(h)\)
- Central difference: \(f'(x) \approx \dfrac{f(x+h) - f(x-h)}{2h} + O(h^2)\) — higher accuracy from symmetry
- Second derivative: \(f''(x) \approx \dfrac{f(x+h) - 2f(x) + f(x-h)}{h^2} + O(h^2)\)
This Tool
Enter any set of integer stencil points (e.g., \(-2, -1, 0, 1, 2\)) and a derivative order. The tool solves the Vandermonde system using exact rational (BigInt) arithmetic — no floating-point rounding — and returns:
- The finite difference formula with exact rational coefficients
- The leading error term \(C \cdot h^p \cdot f^{(q)}(\xi)\) with exact constant \(C\)
- A log-log convergence plot demonstrating the computed order of accuracy \(O(h^p)\) using \(f(x) = e^x\)
For an \(n\)-th derivative you need at least \(n+1\) stencil points. Symmetric stencils (e.g., \(-2,\!-1,\!0,\!1,\!2\)) typically yield higher-order accuracy due to cancellation of odd error terms.