Finite Difference Derivatives

Numerical f′(x) from sampled values — forward, backward, and central stencils

Parameters

ⓘ
ⓘ
ⓘ
Show Trail

Controls

xⓘ

Calculated Values

Central:
0.54;0.54;
Forward:
0.50;0.50;
Exact f′(x0):
0.54;0.54;
Central error:
0.00;0.00;

Examples

sin′(1) = cos(1)

Central diff at x₀ = 1.

  • Central: 0.540.54

Visualization

Derivatives on a Grid

Experimental data and simulation output are discrete. Finite differences approximate derivatives from nearby function values — essential for velocity from position, fields from potentials, and Jacobian entries in Newton solvers.

Forward difference: f′(x) ≈ [f(x+h) − f(x)]/h with truncation error O(h). Backward difference swaps the points. Central difference: [f(x+h) − f(x−h)]/(2h) cancels leading error and achieves O(h²).

Choosing h balances truncation error (smaller h is better) against round-off error (very small h amplifies noise). A rule of thumb is h ≈ √(ε_machine) × |x| for double precision.

In time-dependent physics, v(t) ≈ [x(t+h) − x(t)]/h links to ODE solvers that advance state. Spatial derivatives on grids underpin wave equation simulations.

For noisy lab data, smooth or fit first, then differentiate — raw finite differences magnify noise.

Key Concepts

  • Forward/backward: O(h) error
  • Central: O(h²) error
  • h too large → poor slope; h too small → noise
  • Stencil = pattern of sample points
  • Used inside Newton-Raphson as f′(x)

Real-World Applications

  • Velocity from position-time data
  • Electric field from potential grid E = −∇V
  • Sensitivity analysis in models
  • Jacobian entries for nonlinear solvers

Explore Further

More computational physics tools

  • Gradient Descent

    Iteratively minimize f(x) by following the negative gradient with animated path visualization.

  • 1D Heat Equation

    Finite-difference FTCS solution to the diffusion equation with animated temperature profiles.

  • 1D Wave Equation

    Leapfrog finite-difference solution to the wave equation with animated wave propagation.

  • Numerical Integration

    Trapezoidal and Simpson rules to approximate definite integrals with error vs exact solutions.

  • ODE Solver

    Euler and Runge-Kutta 4 methods for first-order ODEs with comparison to analytic solutions.

  • Monte Carlo Intro

    Estimate π and integrals by random sampling — introduction to stochastic computational physics.

Physics Equations

Forward:
f′(x)≈f(x+h)−f(x)hf'(x) \approx \frac{f(x+h)-f(x)}{h}
Central:
f′(x)≈f(x+h)−f(x−h)2hf'(x) \approx \frac{f(x+h)-f(x-h)}{2h}

Step-by-Step Solution

See how the main results are calculated.

1

Step 1: Function and evaluation point

Approximate f′(1) for f(x) = sin(x).

Equation:

f(x)=sin⁡(x)f(x) = \sin(x)

Result:

Stepsizeh=0.1Step size h = 0.1
2

Step 2: Forward difference

Equation:

f′(x)≈f(x+h)−f(x)hf'(x) \approx \frac{f(x+h) - f(x)}{h}

Calculation:

0.891207−0.8414710.1=0.497364\frac{0.891207 - 0.841471}{0.1} = 0.497364

Result:

Forward ≈ 0.497364
3

Step 3: Central difference (recommended)

Equation:

f′(x)≈f(x+h)−f(x−h)2hf'(x) \approx \frac{f(x+h) - f(x-h)}{2h}

Calculation:

0.891207−0.7833270.2=0.539402\frac{0.891207 - 0.783327}{0.2} = 0.539402

Result:

Central ≈ 0.539402

Explanation:

Error is O(h²) vs O(h) for forward/backward.

4

Step 4: Analytic derivative

Calculation:

f′(1)=0.540302f'(1) = 0.540302

Result:

Central error: 9.001e-4, Forward: 4.294e-2

Frequently Asked Questions (FAQ)

Why is central usually best?

Symmetric stencil cancels odd-order error terms.

Can I use this on noisy data?

Only with caution — reduce noise or increase h slightly, but not too much.

Practice MCQs

  1. Central difference truncation error is O(h²) because:
  2. Halving h improves central error roughly by:
  3. Forward difference at x uses:
  4. Derivative of position gives:
  5. Very tiny h on noisy data: