Skip to content

Numerical Differentiation, Integration, FDM and FEM

CSIR NET geophysics: finite-difference derivatives, trapezoid, Simpson and Gauss quadrature, FDM stability (CFL) and 1-D finite elements, with practice.

  • 20 min read
  • Updated
On this page · 13 sections
  1. Prerequisites
  2. The Hook: A Gravity Profile Is Just a List of Numbers
  3. Numerical Differentiation
  4. Numerical Integration (Quadrature)
  5. The Finite-Difference Method (FDM)
  6. The Finite-Element Method (FEM)
  7. Memory Tricks
  8. Don’t Confuse
  9. Common Mistakes
  10. Practice
  11. Quick Revision Table
  12. Key Takeaways
  13. What’s Next

Prerequisites

The Hook: A Gravity Profile Is Just a List of Numbers

Numerical Differentiation

Let \( f_i = f(x_i) \) on an evenly spaced grid \( x_i = x_0 + ih \). Expand \( f(x \pm h) \) by Taylor’s theorem:

$$f(x \pm h) = f(x) \pm h f'(x) + \frac{h^2}{2} f''(x) \pm \frac{h^3}{6} f'''(x) + \frac{h^4}{24} f^{(4)}(x) \pm \cdots$$

Rearranging, adding and subtracting gives the standard formulas.

FormulaExpressionLeading errorOrder
Forward difference\( \frac{f_{i+1} - f_i}{h} \)\( -\frac{h}{2} f'' \)\( O(h) \)
Backward difference\( \frac{f_i - f_{i-1}}{h} \)\( +\frac{h}{2} f'' \)\( O(h) \)
Central difference, \( f' \)\( \frac{f_{i+1} - f_{i-1}}{2h} \)\( -\frac{h^2}{6} f''' \)\( O(h^2) \)
Central difference, \( f'' \)\( \frac{f_{i+1} - 2f_i + f_{i-1}}{h^2} \)\( -\frac{h^2}{12} f^{(4)} \)\( O(h^2) \)

(The sign convention: “leading error” is exact value minus formula, to first order.)

Richardson extrapolation

If a formula \( D(h) \) has error \( c h^p + O(h^{p+1}) \), combine two step sizes to cancel the leading term:

$$\boxed{D_{\text{better}} = \frac{2^p D(h) - D(2h)}{2^p - 1}}$$

For the central difference \( p = 2 \), so \( D_{\text{better}} = \frac{4D(h) - D(2h)}{3} \). With the numbers above, \( D(0.2) = \frac{e^{0.2} - e^{-0.2}}{0.4} = 1.006680 \), and \( \frac{4(1.0016675) - 1.006680}{3} = 0.999997 \): error \( 3 \times 10^{-6} \) from two cheap estimates.

Round-off: why smaller h is not always better

Truncation error falls as \( h^p \), but the difference \( f_{i+1} - f_{i-1} \) of two nearly equal numbers loses significant digits, and that round-off error grows like \( \frac{\varepsilon}{h} \) (\( \varepsilon \) = data or machine error). The total error has a minimum at an optimum \( h \). With field data the “\( \varepsilon \)” is the measurement noise, which is far larger than machine precision. That is why differentiating noisy gravity or magnetic profiles amplifies noise, and why vertical-derivative maps look rough: differentiation is a high-pass operation. (The signal-processing view of the same fact: the derivative multiplies the spectrum by \( i2\pi f \).)

Numerical Integration (Quadrature)

Quadrature means approximating \( \int_a^b f(x)\,dx \approx \sum_k w_k f(x_k) \) with nodes \( x_k \) and weights \( w_k \). Two families matter.

Newton–Cotes rules (equally spaced nodes)

Fit a polynomial through equally spaced samples and integrate it exactly.

RuleSingle panelComposite error (\( n \) panels of width \( h \), \( b - a = nh \))Degree of precision
Trapezoidal\( \frac{h}{2}(f_0 + f_1) \)\( -\frac{(b-a)h^2}{12} f''(\xi) \)1
Simpson’s 1/3\( \frac{h}{3}(f_0 + 4f_1 + f_2) \)\( -\frac{(b-a)h^4}{180} f^{(4)}(\xi) \)3
Simpson’s 3/8\( \frac{3h}{8}(f_0 + 3f_1 + 3f_2 + f_3) \)\( -\frac{(b-a)h^4}{80} f^{(4)}(\xi) \)3

Degree of precision = the highest degree of polynomial the rule integrates exactly. Simpson’s rule is built on a parabola but is exact for cubics too: the cubic term’s error integrates to zero by symmetry. Simpson’s 1/3 rule needs an even number of panels (odd number of points).

Composite forms you should be able to write without thinking:

$$T = h\left[\tfrac{1}{2}f_0 + f_1 + f_2 + \cdots + f_{n-1} + \tfrac{1}{2}f_n\right]$$$$S = \frac{h}{3}\left[f_0 + 4(f_1 + f_3 + \cdots) + 2(f_2 + f_4 + \cdots) + f_n\right]$$

Halving h: the composite trapezoidal error falls by 4, Simpson’s by 16. Romberg integration is Richardson extrapolation applied to the trapezoidal rule: \( \frac{4T(h/2) - T(h)}{3} \) equals Simpson’s rule, and repeating the trick gives higher orders.

Gaussian quadrature (optimal nodes)

Let the nodes move too. With \( n \) nodes and \( n \) weights (\( 2n \) free numbers), you can integrate polynomials up to degree \( 2n - 1 \) exactly. For \( \int_{-1}^{1} \), the nodes are the zeros of the Legendre polynomial \( P_n \) (Gauss–Legendre).

\( n \)NodesWeightsExact up to degree
1021
2\( \pm\frac{1}{\sqrt{3}} \)1, 13
3\( 0,\ \pm\sqrt{\frac{3}{5}} \)\( \frac{8}{9},\ \frac{5}{9},\ \frac{5}{9} \)5

For a general interval, map \( x = \frac{b - a}{2}t + \frac{b + a}{2} \) and multiply the sum by \( \frac{b - a}{2} \).

Gauss rules need the function at irrational points, so they suit functions you can evaluate anywhere (element integrals in FEM, kernels in forward modelling). Field data at fixed stations use Newton–Cotes rules.

The Finite-Difference Method (FDM)

FDM replaces every derivative in a PDE by a difference quotient on a grid, turning the PDE into algebraic equations.

graph LR
    A["PDE + initial and boundary conditions"] --> B["Grid: spacing Δx, Δt"]
    B --> C["Replace derivatives by differences (stencil)"]
    C --> D{"Explicit or implicit?"}
    D -->|Explicit| E["March forward point by point"]
    D -->|Implicit| F["Solve a banded linear system each step"]
    E --> G["Check consistency + stability"]
    F --> G

Heat (diffusion) equation

\( u_t = \kappa u_{xx} \) models conductive cooling of a dyke or lithosphere. Write \( u_i^n \approx u(i\Delta x, n\Delta t) \) and the mesh ratio

$$r = \frac{\kappa\,\Delta t}{\Delta x^2}.$$
SchemeUpdateAccuracyStability
Explicit FTCS (forward time, centred space)\( u_i^{n+1} = u_i^n + r(u_{i+1}^n - 2u_i^n + u_{i-1}^n) \)\( O(\Delta t, \Delta x^2) \)only if \( r \le \frac{1}{2} \)
Implicit BTCS (backward Euler)\( -r u_{i-1}^{n+1} + (1 + 2r)u_i^{n+1} - r u_{i+1}^{n+1} = u_i^n \)\( O(\Delta t, \Delta x^2) \)unconditional
Crank–Nicolson (average of the two)tridiagonal system each step\( O(\Delta t^2, \Delta x^2) \)unconditional (can oscillate for large \( r \))

Von Neumann (Fourier) stability analysis. Substitute \( u_i^n = G^n e^{\mathrm{i}k i\Delta x} \). For FTCS the amplification factor is

$$G = 1 - 4r\sin^2\!\left(\frac{k\Delta x}{2}\right),$$

and \( \lvert G \rvert \le 1 \) for every \( k \) requires \( 1 - 4r \ge -1 \), that is \( \boxed{r \le \tfrac{1}{2}} \).

Wave equation and the CFL condition

\( u_{tt} = v^2 u_{xx} \) is the core of seismic forward modelling. The explicit centred scheme

$$u_i^{n+1} = 2u_i^n - u_i^{n-1} + C^2\left(u_{i+1}^n - 2u_i^n + u_{i-1}^n\right), \qquad C = \frac{v\,\Delta t}{\Delta x}$$

is stable only if the Courant number satisfies the Courant–Friedrichs–Lewy (CFL) condition:

$$\boxed{C = \frac{v_{\max}\,\Delta t}{\Delta x} \le 1 \quad \text{(1-D)}}$$

Physically: in one step the wave must not travel further than one grid cell, or the scheme’s domain of dependence misses the true one. For the standard second-order scheme on a square 2-D grid the limit tightens to \( C \le \frac{1}{\sqrt{2}} \). Use the fastest velocity in the model.

A second, separate grid limit is numerical dispersion: a wavelength sampled by too few grid points travels at the wrong speed, so a sharp pulse develops a ringing tail. Stability is about blow-up; dispersion is about accuracy. A stable scheme can still be badly dispersive.

Laplace and Poisson equations

The 5-point stencil for \( \nabla^2 u = 0 \) on a square grid says each interior value is the average of its four neighbours:

$$u_{i,j} = \frac{1}{4}\left(u_{i+1,j} + u_{i-1,j} + u_{i,j+1} + u_{i,j-1}\right).$$

For Poisson’s equation \( \nabla^2 u = f \), subtract \( \frac{h^2}{4}f_{i,j} \). The resulting large sparse system is solved by Jacobi, Gauss–Seidel or SOR iteration (see Gauss Elimination and Gauss-Seidel in Mathematical Sciences). Potential-field problems (gravity, magnetics, steady heat flow, DC resistivity) are all of this type.

Consistency, stability, convergence

The Finite-Element Method (FEM)

FEM splits the domain into elements (intervals in 1-D, triangles or quadrilaterals in 2-D, tetrahedra or bricks in 3-D), approximates the solution inside each by simple shape functions, and enforces the PDE in an integral (weak) sense.

The recipe, on a 1-D model problem

Solve \( -u'' = f \) on \( 0 < x < 1 \), \( u(0) = u(1) = 0 \).

  1. Weak form. Multiply by a test function \( v \) with \( v(0) = v(1) = 0 \) and integrate by parts: $$\int_0^1 u'v'\,dx = \int_0^1 f v\,dx \quad \text{for all admissible } v.$$ Only first derivatives remain, so piecewise-linear functions are allowed.
  2. Discretise. Nodes \( x_j = jh \). Write \( u \approx \sum_j u_j \phi_j(x) \), where \( \phi_j \) is the “hat” function equal to 1 at node \( j \) and 0 at all other nodes.
  3. Galerkin choice. Take the test functions equal to the basis functions, \( v = \phi_i \). This gives \( K\mathbf{u} = \mathbf{F} \) with $$K_{ij} = \int \phi_i'\phi_j'\,dx, \qquad F_i = \int f\phi_i\,dx.$$
  4. Element matrices and assembly. On one linear element of length \( h \), the element stiffness matrix is \( \frac{1}{h}\begin{pmatrix} 1 & -1 \\ -1 & 1 \end{pmatrix} \). Adding the overlapping contributions gives, for interior nodes, the tridiagonal matrix \( \frac{1}{h}\,\mathrm{tridiag}(-1, 2, -1) \).
  5. Boundary conditions, solve, post-process.

Notice that this \( K \) is the same tridiagonal matrix the central-difference FDM gives for \( -u'' \), scaled by \( h \). On uniform 1-D grids the two methods often coincide; they part company on irregular meshes and complicated boundaries.

Properties worth remembering

  • \( K \) is sparse (each node couples only to neighbours), symmetric and positive definite for self-adjoint problems such as this one.
  • Element integrals are evaluated by Gaussian quadrature in practice, which ties this section back to the quadrature table above.
  • Neumann (flux) conditions are “natural”: they enter through the boundary term of the integration by parts. Dirichlet (value) conditions are “essential” and are imposed on the unknowns directly.
  • Accuracy improves by refining elements (h-refinement) or raising the polynomial degree (p-refinement).
  • Variational view (Rayleigh–Ritz): for self-adjoint problems the Galerkin solution minimises the energy functional over the trial space.

FDM versus FEM

FDMFEM
Starting pointPDE in strong (differential) formWeak (integral, variational) form
DiscretisationGrid of points; derivatives by differencesMesh of elements; shape functions
GeometryBest on rectangular grids; topography and curved interfaces are “staircased”Irregular meshes follow topography, faults and interfaces
Boundary conditionsFlux conditions need ghost points or one-sided differencesFlux (Neumann) conditions are natural
Coding effortSimple, fast, explicit time stepping is easyMore bookkeeping (mesh, assembly)
Typical geophysical useSeismic wave propagation on regular grids, simple heat-flow modelsEM and resistivity modelling with topography, crustal deformation, groundwater and heat flow in complex geometry

Memory Tricks

Don’t Confuse

ThisvsThat
Truncation error: falls as \( h \) shrinksRound-off / noise error: grows as \( h \) shrinks
Order of a formula (how error scales with \( h \))Degree of precision (highest polynomial integrated exactly)
Newton–Cotes: fixed equally spaced nodesGauss: optimal nodes, degree \( 2n-1 \) with \( n \) points
Stability (no blow-up; CFL, \( r \le \frac{1}{2} \))Numerical dispersion (wrong phase speed on a coarse grid)
Explicit scheme: cheap per step, conditionally stableImplicit scheme: a linear solve per step, unconditionally stable
FDM: strong form on a gridFEM: weak form on a mesh
Essential (Dirichlet) BC: imposed on the unknownsNatural (Neumann) BC: enters through the weak form

Common Mistakes

Practice

All questions below are original practice questions written for this page. They are not from any CSIR NET paper.

Level 1: Foundation

  1. What is the order of the truncation error of the central-difference formula for \( f'(x) \)?
  2. What is the degree of precision of Simpson’s 1/3 rule?
  3. What is the stability condition on \( r = \kappa\Delta t/\Delta x^2 \) for the explicit FTCS scheme for the heat equation?
Answers
  1. \( O(h^2) \). The leading error is \( -\frac{h^2}{6}f''' \).
  2. 3. Exact for all cubics, though built on a parabola.
  3. \( r \le \frac{1}{2} \). From the amplification factor \( G = 1 - 4r\sin^2(k\Delta x/2) \).

Level 2: Part B Style

Practice Q1. A Bouguer anomaly profile sampled every 100 m reads 2.0, 3.5, 4.0, 3.5, 2.0 mGal. The integral of the anomaly along the profile by composite Simpson’s 1/3 rule is about:

(a) 1200 mGal·m (b) 1300 mGal·m (c) 1333 mGal·m (d) 1500 mGal·m

Answer: (c) about 1333 mGal·m

Four intervals, so Simpson’s 1/3 rule applies:

\( \frac{100}{3}[2.0 + 4(3.5) + 2(4.0) + 4(3.5) + 2.0] = \frac{100}{3}(40) = 1333.3 \) mGal·m.

The trapezoidal rule gives \( 100[1.0 + 3.5 + 4.0 + 3.5 + 1.0] = 1300 \), option (b).

Practice Q2. A 1-D explicit finite-difference seismic model has a maximum P-wave velocity of 3000 m/s and grid spacing 15 m. The largest time step allowed by the CFL condition is:

(a) 2.5 ms (b) 5 ms (c) 10 ms (d) 50 ms

Answer: (b) 5 ms

\( \Delta t \le \frac{\Delta x}{v_{\max}} = \frac{15}{3000} = 0.005 \) s = 5 ms.

Practice Q3. The two-point Gauss–Legendre rule applied to \( \int_{-1}^{1} x^4\,dx \) gives:

(a) \( \frac{2}{9} \) (b) \( \frac{2}{5} \) (c) \( \frac{2}{3} \) (d) 2

Answer: (a) 2/9

Nodes \( \pm\frac{1}{\sqrt 3} \), weights 1: \( 2 \times \frac{1}{9} = \frac{2}{9} \). The exact value \( \frac{2}{5} \) (option b) is not reached because the rule is exact only up to degree 3.

Practice Q4. In a finite-difference solution of Laplace’s equation for steady temperature on a square grid, an interior node has neighbours at 12, 16, 20 and 24 °C. At convergence of the 5-point scheme its value is:

(a) 16 °C (b) 18 °C (c) 20 °C (d) 72 °C

Answer: (b) 18 °C

The 5-point stencil makes each interior value the mean of its four neighbours: \( \frac{12 + 16 + 20 + 24}{4} = 18 \) °C.

Level 3: Part C Style

Practice Q5. A rod is modelled with the explicit FTCS scheme for \( u_t = \kappa u_{xx} \). The initial values at nodes 0 to 4 are 0, 0, 100, 0, 0, with nodes 0 and 4 held at 0. With \( r = 0.25 \), the value at node 2 after two time steps is:

(a) 25 (b) 37.5 (c) 50 (d) 62.5

Answer: (b) 37.5

Step 1 (\( u_i \leftarrow u_i + 0.25(u_{i+1} - 2u_i + u_{i-1}) \)):

  • Node 1: \( 0 + 0.25(100 - 0 + 0) = 25 \)
  • Node 2: \( 100 + 0.25(0 - 200 + 0) = 50 \)
  • Node 3: 25 by symmetry.

Step 2:

  • Node 2: \( 50 + 0.25(25 - 100 + 25) = 50 - 12.5 = 37.5 \).

Check of the stability idea: with \( r = 0.75 \), node 2 after one step would be \( 100 + 0.75(-200) = -50 \), a negative temperature from a non-negative start. That is the explicit scheme breaking down for \( r > \frac{1}{2} \).

Practice Q6. Consider these statements about numerical PDE methods:

  1. The Crank–Nicolson scheme for the heat equation is second-order accurate in time and unconditionally stable.
  2. In FEM, Dirichlet boundary conditions arise naturally from the weak form, while Neumann conditions must be imposed on the unknowns.
  3. A stable explicit wave-equation scheme can still show numerical dispersion if the grid is too coarse.
  4. For a well-posed linear IVP, a consistent and stable finite-difference scheme converges.

Which are correct?

(a) 1 and 2 only (b) 1, 3 and 4 only (c) 2, 3 and 4 only (d) 1, 2, 3 and 4

Answer: (b) 1, 3 and 4 only
  1. True. Crank–Nicolson is the trapezoidal rule in time: \( O(\Delta t^2) \), unconditionally stable (though it can oscillate for large \( r \)).
  2. False, reversed. Neumann (flux) conditions are natural; Dirichlet conditions are essential.
  3. True. Stability and dispersion are separate; too few points per wavelength gives phase errors without blow-up.
  4. True. This is the Lax equivalence theorem.

Practice Q7. The trapezoidal rule for \( \int_0^1 x^2\,dx \) gives \( T(1) = 0.5 \) with one panel and \( T(0.5) = 0.375 \) with two. One step of Romberg (Richardson) extrapolation gives:

(a) 0.3125 (b) \( \frac{1}{3} \) (c) 0.35 (d) 0.4375

Answer: (b) 1/3

The trapezoidal error is \( O(h^2) \), so \( R = \frac{4T(h/2) - T(h)}{3} = \frac{4(0.375) - 0.5}{3} = \frac{1.0}{3} = \frac{1}{3} \), the exact value.

Check \( T(0.5) \): \( 0.5\left[\frac{0}{2} + 0.25 + \frac{1}{2}\right] = 0.375 \). The extrapolated value equals Simpson’s rule on the same three points, which is exact for \( x^2 \).

Quick Revision Table

IdeaFormula or fact
Forward / backward difference\( O(h) \), error \( \mp\frac{h}{2}f'' \)
Central difference \( f' \)\( \frac{f_{i+1} - f_{i-1}}{2h} \), error \( -\frac{h^2}{6}f''' \)
Central difference \( f'' \)\( \frac{f_{i+1} - 2f_i + f_{i-1}}{h^2} \), error \( -\frac{h^2}{12}f^{(4)} \)
Richardson\( \frac{2^pD(h) - D(2h)}{2^p - 1} \)
Trapezoid (composite)error \( -\frac{(b-a)h^2}{12}f'' \), precision 1
Simpson 1/3 (composite)error \( -\frac{(b-a)h^4}{180}f^{(4)} \), precision 3, even panels
Gauss–Legendre, \( n \) pointsprecision \( 2n - 1 \); 2-point nodes \( \pm 1/\sqrt{3} \)
FTCS heat\( r = \kappa\Delta t/\Delta x^2 \le \frac{1}{2} \)
CFL (1-D wave)\( v_{\max}\Delta t/\Delta x \le 1 \); 2-D square grid \( \le 1/\sqrt 2 \)
Laplace 5-pointnode = mean of 4 neighbours
Lax theoremconsistency + stability ⇔ convergence
1-D linear element stiffness\( \frac{1}{h}\begin{pmatrix}1 & -1\\ -1 & 1\end{pmatrix} \)

Key Takeaways

What’s Next