Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Boundary value problems

ProblemSolve on when the conditions are split between the two ends:
Devised byShooting: in use since the early days of ballistics computation, analysed by Keller (1968). Collocation: de Boor and Swartz (1973), Ascher, Christiansen and Russell (COLSYS, 1979); the Hermite-Simpson scheme with residual control: Kierzenka and Shampine (2001)
AccuracyShooting: as accurate as the initial value solver, while the problem is well conditioned. Collocation: fourth order, with the mesh refined until the defect of the solution meets the tolerance
CostShooting: initial value solves per Newton iteration. Collocation: one linear system over the whole mesh per Newton iteration
Read firstRunge-Kutta methods, Nonlinear systems: Newton’s and Broyden’s methods
APIsolve_bvp_shooting, solve_bvp_collocation, BvpOptions, BvpSolution

Overview

An initial value problem gives all the information at one point and marches forward. Many physical problems are not like that. A cable is fixed at both ends; a beam is clamped at one end and loaded at the other; the temperature in a rod is held at given values at both ends; an orbit must return to where it started. These are boundary value problems (BVPs): the differential equation holds on an interval, and the conditions are shared between its two ends.

There are two classical approaches. Shooting guesses the missing initial values, integrates the initial value problem across the interval, sees how far it misses the far boundary condition, and corrects the guess by Newton’s method, like adjusting a cannon until the shell lands on target. Collocation treats the whole solution at once: it represents it by piecewise polynomials on a mesh, requires the differential equation to hold at chosen points, and solves the resulting large system of equations, refining the mesh where the approximation is poor. Shooting is simple and very accurate when it works; collocation is the robust method for difficult problems.

Where it is used

Many engineering problems fix conditions at both ends of an interval, not at the start.

  • Structures and heat flow. The deflection of a loaded beam, the temperature along a fin or a pipe wall, and the shape of a hanging cable are boundary value problems.
  • Fluid mechanics. Boundary-layer profiles (the Blasius equation) and flow in channels are solved by shooting or collocation.
  • Quantum mechanics. The allowed energies of a particle in a potential well are eigenvalues of a two-point problem.
  • Optimal control. The necessary conditions for the best trajectory of a rocket or robot form a two-point boundary value problem.

History

Shooting is as old as numerical ballistics, which is the origin of its name: firing tables were computed by adjusting the elevation of a gun until the trajectory hit the target. Herbert Keller’s Numerical Methods for Two-Point Boundary-Value Problems (1968) analysed shooting, multiple shooting and finite differences, and showed why shooting fails when the initial value problem is unstable.

Collocation was developed in the 1970s. Carl de Boor and Blair Swartz (1973) proved that collocation at Gauss points gives high-order accuracy, and Uri Ascher, J. Christiansen and Robert Russell turned the theory into COLSYS (1979), with adaptive mesh selection. Jacek Kierzenka and Lawrence Shampine (2001) designed MATLAB’s bvp4c around the fourth-order Hermite-Simpson (Lobatto IIIA) collocation scheme, controlling the residual of the continuous solution rather than an estimate of the error. SciPy’s solve_bvp and this library follow their approach.

The idea

Shooting

Suppose the state has components. Choose a guess for the unknown initial state , integrate the initial value problem from to , and evaluate the boundary residual

The BVP is now a system of nonlinear equations in unknowns. Newton’s method solves it: form the Jacobian by perturbing each component of and integrating again, solve for a correction, and repeat. The library damps each Newton step, halving it until the residual decreases, which widens the range of guesses that converge. Each initial value solve uses the adaptive Dormand-Prince method at a tight tolerance.

        // Finite-difference Jacobian of the boundary residual with respect to y(a).
        let mut jac = vec![vec![0.0; n]; n];
        for k in 0..n {
            let step = 1e-7 * s[k].abs().max(1.0);
            let mut sk = s.clone();
            sk[k] += step;
            let (gk, _) = residual(&sk)?;
            for i in 0..n {
                jac[i][k] = (gk[i] - g[i]) / step;
            }
        }
        let delta = Lu::new(jac)?.solve(&g);
        // Damped update: halve until the residual decreases.
        let norm = inf_norm(&g);
        let mut lambda = 1.0;
        loop {
            let trial: Vec<f64> = s.iter().zip(&delta).map(|(v, d)| v - lambda * d).collect();
            if let Ok((gt, tt)) = residual(&trial)
                && (inf_norm(&gt) < norm || lambda < 1e-3)
            {
                s = trial;
                g = gt;
                trajectory = tt;
                break;
            }
            lambda *= 0.5;
            if lambda < 1e-4 {
                return Err(ErrorsJSL::RuntimeError("Shooting failed: the boundary residual could not be reduced."));
            }
        }
        converged = inf_norm(&g) <= options.tolerance;

Why shooting fails

Shooting inherits the conditioning of the initial value problem. Consider with . Its solution is perfectly tame, but the initial value problem has solutions growing like . A change in the initial slope changes by about , so the boundary residual is that much more sensitive than the solution itself. Once approaches , no initial slope in floating point reproduces the boundary condition:

Table 2.25. Shooting against collocation as the problem becomes unstable.

growth shooting: error at collocation: error at collocation nodes
51.5e22.3e-102.9e-12617
153.3e62.8e-136.9e-131529
257.2e10not converged (residual 2e-7)7.3e-131345
351.6e15not converged (residual 2e-1)5.3e-131175
453.5e19not converged (residual 2e3)3.7e-131259

Shooting converges for small but fails from on, while collocation, which never integrates across the whole interval, is unaffected. Multiple shooting, which shoots from several points and matches the pieces, is a classical remedy; collocation is the more general one.

Hermite-Simpson collocation

On a mesh , collocation seeks the values . Between two nodes the solution is approximated by the cubic that matches the values and the slopes , (Hermite interpolation). Its value at the midpoint is

and requiring the differential equation to hold there as well gives, after integrating, the Hermite-Simpson equations

one block of equations per interval: Simpson’s rule applied to the integral form of the ODE. Together with the boundary conditions they form equations for the unknowns, which Newton’s method solves. The scheme is fourth order accurate, and the cubic interpolant is a continuous approximate solution between the nodes.

/// Hermite-Simpson collocation residual `y₁ − y₀ − h/6 (f₀ + 4 f_m + f₁)` of one interval.
fn interval_residual<F: Fn(f64, &[f64]) -> Vec<f64>>(f: &F, x0: f64, h: f64, y0: &[f64], f0: &[f64], y1: &[f64], f1: &[f64]) -> Result<Vec<f64>, ErrorsJSL> {
    let n = y0.len();
    let ym: Vec<f64> = (0..n).map(|k| 0.5 * (y0[k] + y1[k]) + h / 8.0 * (f0[k] - f1[k])).collect();
    let fm = eval(f, x0 + 0.5 * h, &ym)?;
    Ok((0..n).map(|k| y1[k] - y0[k] - h / 6.0 * (f0[k] + 4.0 * fm[k] + f1[k])).collect())
}

Residual control and mesh refinement

The cubic satisfies the differential equation exactly at the nodes and midpoints. Elsewhere its defect measures how well it solves the problem: if the defect is small, is the exact solution of a nearby problem. The library evaluates the relative defect at the quarter points of every interval and splits the intervals where it exceeds the tolerance (into three where it is very large), seeding the new nodes from the interpolant, then solves again. Nodes therefore accumulate where the solution changes quickly, as in this boundary layer of width :

Figure 2.26. Mesh points in a boundary layer.

Nonlinear problems and non-uniqueness

A nonlinear BVP may have several solutions, or none, and the starting guess decides which one Newton’s method finds. Bratu’s problem , , from the theory of combustion, has exactly two:

Figure 2.27. The two solutions of Bratu's problem.

Both agree with the closed-form solutions , where is either root of , to every digit shown. A small guess converges to the lower solution and a large one to the upper.

Algorithm

Shooting: from the guess , compute . While exceeds the tolerance: form by more initial value solves; solve for the Newton step; halve it until the residual decreases. Return the trajectory of the last solve.

Collocation:

  1. On the current mesh, solve the Hermite-Simpson equations and boundary conditions by damped Newton, with the Jacobian formed by perturbing one node at a time (each perturbation touches only the two neighbouring intervals and, at the ends, the boundary conditions).
  2. Compute the relative defect at the quarter points of each interval.
  3. If every defect is below the tolerance, stop. Otherwise split the offending intervals and return to step 1, unless the mesh would exceed max_nodes (then report non-convergence).

Implementation

  • The collocation Jacobian is block bidiagonal plus the boundary rows, but it is assembled and factorised as a dense matrix. That is simple and fine for a few hundred nodes; codes for large problems (COLSYS, bvp4c) exploit the block structure and scale linearly with the mesh.
  • BvpSolution::evaluate interpolates the solution anywhere with the same cubic Hermite polynomials, so collocation returns a continuous solution with the accuracy of the scheme.
  • The shooting tolerance applies to the boundary residual, which is not the same as the error in the solution: for an ill-conditioned problem a small residual may still mean a large error.

In practice

The shape of a hanging cable, the catenary between two supports, and both solutions of Bratu’s problem:

//! Two-point boundary value problems by shooting and by collocation.
//!
//! Run with `cargo run --release -p lib_jsl_integration --example ode_boundary_value`.

use lib_jsl_integration::boundary_value_problems::{BvpOptions, solve_bvp_collocation, solve_bvp_shooting};

fn main() {
    // A hanging cable (catenary): y'' = a √(1 + y'²), y(−1) = y(1) = 1, with a = 1.
    let catenary = |_: f64, y: &[f64]| vec![y[1], (1.0 + y[1] * y[1]).sqrt()];
    let ends = |ya: &[f64], yb: &[f64]| vec![ya[0] - 1.0, yb[0] - 1.0];
    // Exact: y = cosh x + 1 − cosh 1.
    let exact = |x: f64| x.cosh() + 1.0 - 1f64.cosh();

    let shot = solve_bvp_shooting(catenary, ends, -1.0, 1.0, vec![1.0, 0.0], BvpOptions::default()).unwrap();
    println!("shooting:    converged {}, sag y(0) = {:.12} (exact {:.12})", shot.converged, shot.evaluate(0.0)[0], exact(0.0));

    let x: Vec<f64> = (0..=8).map(|i| -1.0 + i as f64 / 4.0).collect();
    let guess: Vec<Vec<f64>> = x.iter().map(|_| vec![1.0, 0.0]).collect();
    let options = BvpOptions { tolerance: 1e-8, ..Default::default() };
    let col = solve_bvp_collocation(catenary, ends, x, guess, options).unwrap();
    println!("collocation: converged {}, sag y(0) = {:.12}, {} mesh points", col.converged, col.evaluate(0.0)[0], col.x.len());

    // Bratu's problem u'' + e^u = 0, u(0) = u(1) = 0 has two solutions; the guess picks one.
    let bratu = |_: f64, y: &[f64]| vec![y[1], -y[0].exp()];
    let zero = |ya: &[f64], yb: &[f64]| vec![ya[0], yb[0]];
    for amplitude in [0.5, 16.0] {
        let x: Vec<f64> = (0..=10).map(|i| i as f64 / 10.0).collect();
        let guess: Vec<Vec<f64>> = x.iter().map(|&t| vec![amplitude * t * (1.0 - t), amplitude * (1.0 - 2.0 * t)]).collect();
        let sol = solve_bvp_collocation(bratu, zero, x, guess, options).unwrap();
        println!("Bratu from guess {amplitude:>4}·x(1 − x): u(1/2) = {:.10}", sol.evaluate(0.5)[0]);
    }
}

Strengths

  • Shooting: very simple, reuses an accurate initial value solver, and needs no mesh.
  • Collocation: robust for boundary layers and problems whose initial value problems are unstable; returns a continuous solution with a controlled residual.

Weaknesses

  • Shooting fails when the initial value problem amplifies errors strongly over the interval.
  • Both need a reasonable starting guess for nonlinear problems, and different guesses may lead to different solutions.
  • The dense linear algebra limits the library’s collocation solver to moderate mesh sizes.

Exercises

  1. Solve , , by shooting. What goes wrong, and why? (This problem has infinitely many solutions.)
  2. Show that the Hermite cubic through and has the midpoint value given above.
  3. Verify the fourth-order convergence of collocation on Bratu’s problem by switching off refinement (tolerance infinity) and halving the mesh repeatedly.
  4. Bratu’s problem has two solutions for and none above. Trace both branches with collocation as increases, using each solution as the guess for the next (continuation), and estimate .
  5. Implement multiple shooting for with subintervals and show that it succeeds for when is large enough. How large must be?
Hints and answers
  1. The general solution is ; forces and then holds for every . The shooting residual is identically zero as a function of the slope , so there is nothing to solve for: the Jacobian of the shooting equation is singular.
  2. The Hermite cubic at the midpoint is : evaluate the four Hermite basis functions at , where and .
  3. With refinement off, halve the mesh and tabulate the maximum error; the ratios should approach .
  4. Increase in small steps, starting each solve from the previous solution. The lower branch exists for all ; the upper branch is reached by starting from a large guess. Near the Jacobian becomes singular, so cannot be used as the continuation parameter through the turning point.
  5. The solution grows like across an interval of length 1, so one-interval shooting amplifies errors by . With subintervals the amplification per piece is , so must be small enough that this is tolerable; of the order of 15 to 20 brings the amplification per piece down to about to .

Further reading

  • H. B. Keller, Numerical Methods for Two-Point Boundary-Value Problems, Blaisdell, 1968.
  • C. de Boor and B. Swartz, “Collocation at Gaussian points”, SIAM Journal on Numerical Analysis 10 (1973) 582–606.
  • U. Ascher, J. Christiansen and R. D. Russell, “A collocation solver for mixed order systems of boundary value problems”, Mathematics of Computation 33 (1979) 659–679.
  • J. Kierzenka and L. F. Shampine, “A BVP solver based on residual control and the MATLAB PSE”, ACM Transactions on Mathematical Software 27 (2001) 299–316.
  • U. M. Ascher, R. M. M. Mattheij and R. D. Russell, Numerical Solution of Boundary Value Problems for Ordinary Differential Equations, SIAM, 1995.