Boundary Value Problem Methods
Compare discretizations for the elliptic two-point problem \(-\,p\,u'' + b\,u' + c\,u = f(x)\) on \([a,b]\) - finite differences, finite elements, Chebyshev spectral collocation, discontinuous Galerkin, spline (B‑spline) FEM, and shooting. Slide the mesh \(h\) live, switch Dirichlet/Neumann/mixed boundary conditions, tune the DG penalty, inspect the discretization matrix, and measure convergence order. A time‑dependent mode extends the same spatial stencils to the heat and wave equations by the method of lines.
The boundary value problem
A two-point boundary value problem (BVP) asks for \(u(x)\) satisfying a differential equation on an interval together with a condition at each end:
with \(p>0\) (diffusion), \(b\) (advection) and \(c\ge 0\) (reaction). The condition \(p>0\) is exactly the ellipticity of the operator; the sliders keep \(p\) strictly positive so the problem stays elliptic and well-posed. Unlike an initial value problem, information propagates from both ends, so the methods here solve a coupled algebraic system rather than marching forward.
Boundary conditions
- Dirichlet prescribes the value \(u(a)=\alpha\). It is an essential condition - imposed directly on the unknowns (strongly in FD/FEM, weakly by Nitsche in DG).
- Neumann prescribes the flux \(u'(a)=\alpha\). It is a natural condition - it appears through the boundary term of the weak form and needs no constraint on the trial space.
- Mixed uses a different type at each end (e.g. Neumann on the left, Dirichlet on the right). Pure Neumann–Neumann with \(c=0\) is singular (the solution is determined only up to a constant and requires a compatibility condition on \(f\)); the tool pins one value in that case.
Every built-in problem is a manufactured solution: a smooth \(u(x)\) is chosen, and \(f\), \(\alpha\), \(\beta\) are computed from it. The exact solution is therefore known for any coefficients and boundary types, so the error and convergence panels are measured against truth - boundary data is always compatible by construction.
Weak form and the Galerkin idea
Multiplying by a test function \(v\) and integrating by parts turns the strong form into the weak form: find \(u\) with
for all admissible \(v\). The boundary term is where Neumann data enters. Finite elements, spline FEM, and discontinuous Galerkin all approximate this identity on a finite-dimensional space; finite differences and spectral collocation instead enforce the strong equation at grid points.
Order of accuracy
A method has order \(p\) if its error scales like \(O(h^{p})\) as the mesh is refined; halving \(h\) then cuts the error by \(2^{p}\). On the log–log Convergence panel this is the slope of a straight line. The polynomial methods here have fixed orders (FD and P\(_1\) FEM are second order; FEM of degree \(k\), DG and spline of degree \(k\) are order \(k+1\), so P\(_2\) FEM is third order; shooting inherits the fourth order of its RK4 integrator). Spectral collocation is different: for a smooth solution its error falls faster than any power of \(h\) - spectral (exponential) accuracy - so it appears as a steep, curving line rather than a fixed slope.
The discretization matrix
Each method produces a linear system \(A\mathbf{u}=\mathbf{f}\), and the structure of \(A\) is the fingerprint of the method. The Discretization panel draws the sparsity pattern with its row/column indices and states the stencil or element matrix explicitly: FD and P\(_1\) FEM are tridiagonal (P\(_2\) FEM is pentadiagonal); spline FEM of degree \(k\) is banded with bandwidth \(2k+1\); DG is block tridiagonal (dense blocks per element, coupled only to neighbours through the numerical flux); spectral collocation is dense.
Time-dependent mode (method of lines)
Switching to Heat or Wave keeps the same spatial finite-difference stencil but leaves time continuous, giving a system of ODEs \(\mathbf{u}'(t) = -A\mathbf{u} + \mathbf{f}\) (the method of lines). The heat equation \(u_t = p\,u_{xx}\) is advanced with the unconditionally stable \(\theta\)-method (backward Euler or Crank–Nicolson); the wave equation \(u_{tt}=p\,u_{xx}\) uses the explicit leapfrog scheme, stable under the CFL condition. The result is drawn as a space–time field with a movable time slice.
Using this tool
- Tick any number of methods to overlay their approximations on the solution plot.
- Pick a built-in problem or set the coefficients \(p,b,c\) with the sliders (ellipticity is preserved automatically). The equation, exact solution, and derived boundary data are shown above the plot.
- Drag the mesh slider with Live update on to watch accuracy change as \(h\) shrinks.
- For DG, set the interior-penalty \(\sigma\) and the polynomial degree; too small a penalty loses coercivity (especially at higher degree).
- The plots support scroll-zoom, drag-to-pan, and box-zoom; the graph height is adjustable.
Finite Differences (FD) - 2nd order
On a uniform grid \(x_i=a+ih\), \(h=(b-a)/N\), replace derivatives by centred differences:
This is the three-point stencil \(\big[\,{-}\dfrac{p}{h^2}-\dfrac{b}{2h},\ \dfrac{2p}{h^2}+c,\ {-}\dfrac{p}{h^2}+\dfrac{b}{2h}\,\big]\) at indices \(i{-}1,i,i{+}1\), giving a tridiagonal system solved by the Thomas algorithm. Dirichlet values are substituted directly; Neumann uses a second-order ghost node so the whole scheme stays \(O(h^2)\).
Postprocessing. The centred scheme has a regular error expansion in even powers of \(h\), so Richardson extrapolation across a grid sequence (\(h,\ h/2,\dots\)) cancels the leading \(h^2\) term and lifts the order to \(O(h^4)\) and beyond - the same idea as Romberg. Deferred correction gives a comparable gain on a single grid.
Finite Elements (P\(_1\)/P\(_2\) FEM) - order \(k+1\)
Continuous piecewise-polynomial Lagrange elements of degree \(k\) (selectable P\(_1\) linear or P\(_2\) quadratic). On a grid \(x_i=a+ih\) the nodal basis functions are defined piecewise, element by element.
P\(_1\) (linear). The nodal basis is the hat function
P\(_2\) (quadratic). Each element \([x_i,x_{i+1}]\) carries three shape functions in the local coordinate \(\xi=\dfrac{x-x_i}{h}\in[0,1]\) - two vertex functions and one interior "bubble" at the midpoint \(x_{i+1/2}\):
Glued across the shared node, the global quadratic vertex basis \(\varphi_i\) and midpoint basis \(\varphi_{i+1/2}\) are
Each element \([x_i,x_{i+1}]\) contributes a local \((k{+}1)\times(k{+}1)\) matrix - for P\(_1\),
assembled into the global stiffness matrix via the local-to-global index map; the load \(\int f\varphi_i\) and all element integrals are evaluated by Gauss quadrature. Neumann data enters naturally through the boundary term; Dirichlet is imposed by elimination. Increasing the degree raises the order to \(O(h^{k+1})\): P\(_1\) is second order, P\(_2\) third order. For pure diffusion the P\(_1\) nodal values are exact - a classical Galerkin superconvergence result.
Postprocessing. FEM is the classical setting for superconvergence recovery. The nodal values are superconvergent (exact here for pure diffusion), and the derivative \(u_h'\) is superconvergent at the element Gauss points: averaging/recovering it there - gradient recovery, Zienkiewicz–Zhu / superconvergent patch recovery - yields a flux one order more accurate than the raw \(u_h'\). Functional outputs \(J(u)\) can be postprocessed to roughly double order through an adjoint (Babuška–Miller).
Spectral collocation (Chebyshev) - exponential
Sample \(u\) at the Chebyshev–Gauss–Lobatto nodes \(x_j=\cos\!\big(\dfrac{j\pi}{N}\big),\ j=0,\dots,N\), and enforce the strong equation there using the Chebyshev differentiation matrix \(D\), whose entries are
with \(c_0=c_N=2\) and \(c_1=\dots=c_{N-1}=1\). It is a dense \((N{+}1)\times(N{+}1)\) matrix
for example at \(N=2\) (nodes \(x_0=1,\ x_1=0,\ x_2=-1\)),
The strong equation is collocated as
a dense system. Boundary rows are overwritten to enforce the conditions (an identity row for Dirichlet, a row of \(D\) for Neumann). For smooth solutions the error decays faster than any power of \(h\) - a handful of points reaches machine precision.
Postprocessing. On the smooth solutions here there is little to recover - the method is already spectrally accurate. Postprocessing matters for non-smooth data, where spectral filtering or Gegenbauer reprojection restores high-order accuracy away from a discontinuity and tames the Gibbs oscillations that otherwise pollute the whole domain. The spectral coefficients also give an accurate derivative directly, by applying \(D\) to the computed \(\mathbf{u}\).
Discontinuous Galerkin (SIPG) - order \(k+1\)
Piecewise polynomials of degree \(k\), discontinuous across element interfaces. The symmetric interior-penalty (SIPG) bilinear form couples neighbours through averages \(\{\cdot\}\), jumps \([\cdot]\), and a penalty \(\sigma\):
The penalty must be large enough for coercivity; too small and the method loses stability (more so at higher \(k\)), too large and it is over-stiff. The matrix is block tridiagonal. Dirichlet is imposed weakly (Nitsche).
Postprocessing. DG is the poster child for postprocessing. A SIAC filter (smoothness-increasing accuracy-conserving) convolves the degree-\(k\) solution against a B-spline kernel and lifts the order from \(k+1\) to \(2k+1\) (linear problems), cashing in DG's superconvergence in the negative-order norm - and also smooths the inter-element jumps. It uses the same B-spline machinery as the spline method above.
Spline FEM (clamped B-splines) - order \(d+1\)
A Galerkin method whose trial space is the degree-\(d\) spline space \(S_d^{\,d-1}\) on a clamped uniform knot vector - globally \(C^{d-1}\), and interpolatory at the endpoints so Dirichlet data pins the first and last coefficients directly. On each knot span (element) \(I=[x_\ell,x_{\ell+1}]\) the polynomial pieces are written in Bernstein–Bézier form (Lai & Schumaker, Spline Functions on Triangulations). Using the barycentric coordinates of \(I\),
the degree-\(d\) Bernstein basis polynomials and the B-form of a piece \(s|_I\) are
with B-coefficients (Bézier ordinates) \(c_{ij}\) carried at the domain points \(\xi_{ij}=\dfrac{i\,x_\ell+j\,x_{\ell+1}}{d}\). Global \(C^{d-1}\) smoothness is enforced through the Lai–Schumaker smoothness conditions tying the \(c_{ij}\) of adjacent spans, which reduces the per-span B-form to the clamped B-spline basis. The weak form is assembled by Gauss quadrature over each span, giving a banded matrix of bandwidth \(2d+1\); the extra smoothness delivers order \(d+1\) with far fewer degrees of freedom than P\(_1\) - the isogeometric idea behind spline finite elements.
Postprocessing. The globally \(C^{d-1}\) basis makes the derivatives \(s',s'',\dots\) directly available and continuous - no gradient recovery needed - and they are read off cheaply from the B-coefficients by de Boor's derivative formula. Isogeometric superconvergence and k-refinement give further accuracy from the same spline space.
Shooting method - 4th order (RK4)
Recast the BVP as a first-order system \(y_1=u,\ y_2=u'\),
and integrate it as an initial value problem with RK4, treating the unknown boundary datum \(s\) (the missing \(u'(a)\) or \(u(a)\)) as a parameter. The residual \(F(s)=u(b;s)-\beta\) is driven to zero by the secant method. Because the ODE is linear, \(F\) is affine in \(s\) and two shots locate the root exactly. Accuracy is that of the integrator, \(O(h^4)\).
Postprocessing. Two handles come from the integrator. A continuous (dense-output) extension of RK4 gives a smooth \(u(x)\) between steps - values and derivatives anywhere, not just at the grid nodes. And because RK4 has a regular \(h^4\) error expansion, Richardson extrapolation over halved step sizes raises the global order further.
Problem
Each problem is a manufactured solution: \(f\) and the boundary data are derived from a known \(u(x)\), so the error is measured against truth for any coefficients.
Mode
Advection is discretized with an upwind flux (DG) / streamline term; large \(|b|\) relative to \(p\) makes the problem advection-dominated.
Mesh - number of elements \(N\)
Graph height
About this plot
The black curve is the exact (manufactured) solution. Coloured curves are the selected methods sampled on their nodes; discontinuous Galerkin is drawn element by element so its jumps at interfaces are visible. In Heat/Wave mode the plot animates the finite-difference solution profile \(u(x,t)\) over time - press Play or scrub the time slider; the dotted grey curve is the initial condition and the full space–time field is shown in the panel below.About this plot
Absolute error against the exact solution on a logarithmic axis. Lower is better; higher-order methods sit further down. For DG and spline the error is sampled inside each element, not only at nodes. When a Postprocess mode is chosen in the Convergence panel, the postprocessed pointwise error is overlaid in the same colour (Richardson dotted, Bramble–Schatz dash-dot) - the Bramble–Schatz curve is drawn only on the interior where its symmetric kernel is fully supported, and drops well below the raw error there.About this plot
The sparsity pattern of the assembled matrix \(A\) in \(A\mathbf{u}=\mathbf{f}\), with row index \(i\) (top to bottom) and column index \(j\). Colour shows the sign of each entry. The formula below states the stencil or element matrix with its indices. A small mesh is used here so the pattern stays legible.About this plot
Error versus resolution as the mesh is refined. In log–log the error is plotted against \(h=(b-a)/N\); the fitted slope is the empirical order \(p\) (a straight line of slope \(p\) confirms \(O(h^p)\)), and the dashed slate guide marks that reference order. Spectral collocation beats every fixed power (exponential accuracy for smooth solutions), so it curves steeply instead of following a slope; switch to semi–log y (error vs \(N\), linear axis) to see that exponential decay \(e^{-\alpha N}\) straighten into a line, the guide showing the fitted \(Ce^{-\alpha N}\) rate. Levels at machine precision are dropped from the fit.The Postprocess selector overlays a cheaply-improved error curve for each method:
• Richardson extrapolation (dotted diamonds) combines two consecutive meshes to cancel the leading error term,
• Bramble–Schatz (dash-dot stars) is the genuine averaging post-processor of Bramble & Schatz (1977) - the SIAC filter. It convolves a Galerkin solution against a kernel \(K\) made of \(2k{+}1\) B-splines of order \(k{+}1\) whose coefficients reproduce polynomials up to degree \(2k\),
Cite this tool
Kapita, S. (2026). Boundary Value Problem Methods: A Computational Laboratory. Math Tools. https://doi.org/10.5281/zenodo.20981245
Kapita, Shelvean. "Boundary Value Problem Methods: A Computational Laboratory." Math Tools, 2026, doi.org/10.5281/zenodo.20981245.
@online{kapita2026bvp,
author = {Shelvean Kapita},
title = {{Boundary Value Problem Methods: A Computational Laboratory}},
year = {2026},
organization = {Math Tools},
doi = {10.5281/zenodo.20981245},
url = {https://doi.org/10.5281/zenodo.20981245}
}