Fundamentals / Numerical mathematics / Numerical ordinary differential equations

Shooting for two-point boundary values

Turn a missing initial slope into a scalar root, measure the sensitivity of endpoint matching and recognise an unstable propagation direction.

From first principles

Convert a missing boundary slope into a measurable residual

Consider a twice differentiable scalar field on \(0\le x\le L\) satisfying \(y''=f(x,y,y')\), \(y(0)=a\), \(y(L)=b\). A forward initial-value solver needs both the starting value and its slope. Guess a slope \(s\), integrate the two first-order equations \(y'=v,\ v'=f(x,y,v)\) from \((a,s)\), then record the signed endpoint discrepancy:

\[R(s)=y(L;s)-b .\]

Changing the guess by a small amount changes the residual by its derivative times the change. To compute that derivative along the same trajectory define \(z=\partial_s y\), \(w=\partial_s v\). Differentiate both the equations and their initial conditions:

\[z'=w,\]
\[w'=f_y z+f_v w,\]
\[z(0)=0,\]
\[w(0)=1 .\]

Now \(R'(s)=z(L)\). Setting the linearised next residual to zero gives the Newton correction:

\[s_{\rm new}=s-\frac{y(L;s)-b}{z(L)} .\]

For \(f=0\) the propagated sensitivity is exactly \(z(x)=x\). The correction recovers the slope of the line connecting the boundary values in one step. A nearly zero \(z(L)\) signals poor slope identifiability from that endpoint. A large growing sensitivity instead makes forward propagation vulnerable to numerical contamination between the boundaries.

Background · Shooting residual
\[F(s)=B(y(t_f;s))\]

Here s encodes missing initial data and B the final boundary condition. An unstable trajectory map can make the residual badly conditioned even with an accurate initial-value solver.

Derivation and applications

Recognize two shooting solutions and the fold between them

A successful endpoint residual can describe more than one solution. Consider the dimensionless steady boundary-value model \(u''+\lambda e^u=0\) on \(0<x<1\), with \(u(0)=u(1)=0\) and positive \(\lambda\). It represents a simplified nonlinear source balanced by diffusion. A shooting code would vary the unknown initial slope until the final value vanishes. To understand the possible roots, consider a symmetric trial family centred at \(x=1/2\):

\[u_\mu(x)=2\ln\!\frac{\cosh(\mu/2)}{\cosh[\mu(x-1/2)]},\qquad \mu>0 .\]

This family automatically enforces both boundary conditions. Differentiating twice gives

\[u_\mu''=-2\mu^2\operatorname{sech}^2[\mu(x-1/2)].\]

The exponential source has the same spatial factor. Cancel it to determine exactly which problem parameter each profile solves:

\[\lambda(\mu)=2\mu^2\operatorname{sech}^2(\mu/2),\]
\[u'_\mu(0)=2\mu\tanh(\mu/2).\]

As \(\mu\) increases, \(\lambda\) initially grows quadratically, then decays toward zero. Differentiate its logarithm to locate the turning point that separates the two branches of initial slopes:

\[\frac{d\ln\lambda}{d\mu}=\frac2\mu-\tanh(\mu/2)=0 .\]

Numerical solution of \(\mu\tanh(\mu/2)=2\) gives \(\mu\simeq2.3994\) and \(\lambda_{\rm fold}\simeq3.5138\). Below this value and above zero the family gives two distinct symmetric positive solutions. Close to the fold a small change in \(\lambda\) can produce a large change in the solution branch. Numerical residual alone cannot tell which branch a shooting iteration found.

Worked example

Generate a known solution for checking a solver

Choose \(\mu=2\). Then \(\lambda=8/\cosh^2(1)=3.3598\), the initial slope is \(4\tanh(1)=3.0464\) and the centre value is \(2\ln\cosh(1)=0.8676\). Integrating from \((u,u')=(0,3.0464)\) should return near zero at \(x=1\) and near \(0.868\) at the midpoint. The second observation checks the shape, not only the enforced endpoint.

Second application

Identify the branch from an additional reading

At the fold the maximum centre value on the lower-\(\mu\) branch is

\[2\ln\cosh(2.3994/2)=1.187.\]

A computed solution at \(\lambda=3.00\) with centre value \(1.98\) therefore lies on the higher-\(\mu\) branch. Solving \(\lambda(\mu)=3\) on that side gives \(\mu\approx3.29\) and centre value about \(1.98\). A different initial slope producing the same endpoint can represent another valid solution.

Replace a missing slope by a parameter

Consider \(y''=f(t,y,y')\), \(y(0)=a,\ y(T)=b\). Integrate as an initial-value problem with trial slope \(s=y'(0)\) and define \(R(s)=y(T;s)-b\). A root enforces the second boundary. If the initial-value solution is smooth in \(s\), its derivative satisfies \(v''=f_yv+f_{y'}v'\) with \(v(0)=0,\ v'(0)=1\). The derivative of the shooting residual is \(v(T)\). Newton therefore updates the missing slope by \(-R/v(T)\); a vanishing endpoint sensitivity calls for a different parameterisation or further analysis of existence and uniqueness.

Consider \(y''=-y,\ y(0)=0,\ y(T)=1\), for which \(y(t;s)=s\sin t\). At \(T=\pi/2\) the solution has \(s=1\). At \(T=\pi\) no slope reaches the required endpoint. Changing the terminal boundary to zero at the same time admits every slope. An integrator returning a tiny nonzero value for \(\sin\pi\) might suggest an enormous numerical slope, so inspect endpoint sensitivity and the mathematical boundary conditions before trusting a root.

A well-defined solution with a fragile shooting trajectory

For \(y''=k^2y,\ y(0)=1,\ y(1)=0\), direct propagation gives

\[y(t)=\cosh(kt)+(s/k)\sinh(kt),\]

with exact slope \(-k\coth k\). The required boundary-value solution is equivalently \(\sinh(k(1-t))/\sinh k\), a bounded positive curve. A slope perturbation \(\delta s\) produces endpoint error \(\sinh(k)\delta s/k\). For \(k=10\), this multiplier is approximately 1101.32. A slope error of \(10^{-5}\) thus creates endpoint error 0.0110 even though the exact profile stays between zero and one.

This large number describes forward amplification of slope error. The inverse sensitivity of the fitted slope to the terminal boundary value is its reciprocal. At large \(k\), direct propagation must subtract two growing numbers to recover the small endpoint. Tight initial-value tolerances can postpone the resulting loss of accuracy, while leaving the underlying direction of exponential growth intact.

Match shorter intervals

In multiple shooting introduce independent state guesses at intermediate nodes. Integrate each segment and impose matching equations equating its terminal state to the next guess. Together with the boundary conditions these equations form a sparse coupled nonlinear system. On a half interval the growing factor for \(k=10\) is \(e^5\) instead of \(e^{10}\). Requiring continuity couples the segments while reducing the range of each forward propagation. Cancelling all the intermediate states algebraically can reintroduce the original long product.

Check the final curve against both endpoint conditions, the maximum matching defect and the differential equation. Small endpoint mismatch alone says little about the interiors of independently matched segments. For highly unstable propagation a simultaneous boundary-value discretisation or collocation method can be a more suitable formulation.

Separate root iteration error from integration error

Suppose the propagated terminal state carries absolute numerical error at most \(\epsilon\). Near a simple shooting root the induced slope uncertainty is approximately \(\epsilon/|R'(s)|\). For the oscillator with \(T=\pi/6\), the sensitivity is one half, so endpoint uncertainty \(10^{-5}\) leaves slope uncertainty roughly \(2\times10^{-5}\). Solving the numerical shooting equation to a terminal residual of \(10^{-12}\) would not establish twelve accurate digits of slope. Change the propagation tolerance independently and compare the recovered slopes before interpreting the outer root solver's convergence.

Use shooting to locate an eigenvalue

For a string fixed at both ends, the eigenvalue problem \(-u''=\lambda u,\ u(0)=u(L)=0\) has the trivial solution for every parameter. A shooting formulation that merely adjusts the initial slope while allowing it to vanish can therefore converge to an uninformative zero mode. Fix the amplitude scale instead by prescribing \(u'(0)=1\). For each trial positive \(\lambda\) define the residual \(R(\lambda)=u(L;\lambda)\). A root then enforces the far boundary for a nonzero solution because the prescribed starting slope excludes the trivial state.

On the unit interval the solution is \(u(t;\lambda)=\sin(\sqrt\lambda\,t)/\sqrt\lambda\), so the residual vanishes at \(\lambda_j=j^2\pi^2,\ j=1,2,\ldots\). The limiting solution at zero is \(u=t\), which fails the far boundary. At \(\lambda<0\) the sine becomes a hyperbolic sine and again cannot vanish away from the origin. These facts locate the whole physical spectrum before considering numerical root searches. For a variable material coefficient the simple formula disappears, but amplitude normalisation and endpoint residual remain well-defined.

Bracket a mode and check its identity inside the interval

It is convenient to solve for wave number \(k=\sqrt\lambda>0\). At \(k=3\) the residual is \(\sin3/3\approx0.04704\), and at \(k=3.2\) it is \(\sin3.2/3.2\approx-0.01824\), bracketing the first eigenvalue. Its derivative is \((k\cos k-\sin k)/k^2\). Starting with \(k=\pi\) in the exact formula gives \(R'= -1/\pi\). An absolute integration error of \(10^{-5}\) in the endpoint displacement can therefore shift the fitted wave number by roughly \(3.14\times10^{-5}\). Propagating through \(\lambda=k^2\) gives eigenvalue uncertainty about \(1.97\times10^{-4}\).

A residual search on \(k\in[2,7]\) could instead overlook both \(k=\pi\) and \(2\pi\), since the residuals at the endpoints have the same positive sign. Counting interior nodes provides an independent mode label. With normalisation \(u'(0)=1\), the first eigenfunction has no internal zero and the second has exactly one at \(t=1/2\). Check these zero locations on the computed trajectory at a resolution sufficient to distinguish oscillations. A small endpoint residual alone confirms neither the desired mode index nor the absence of missed modes.

For high modes the physical wavelength decreases and the initial-value integrator must resolve phase over many cycles. A frequency estimate can drift substantially even while the trajectory's amplitude remains bounded. Refining the propagation tolerance, refining the scalar root tolerance and counting the interior nodes are three different checks. Changing all three simultaneously can hide which part of an apparent convergence failure needs attention.

A second normalisation issue appears when comparing eigenfunctions with sensor data. Multiplying any computed eigenfunction by a nonzero constant or by minus one leaves both homogeneous boundary conditions and the eigenvalue unchanged. Matching raw amplitudes or signs between two independently found modes can therefore suggest an error where only conventions differ. Normalise both functions in the same mass-weighted norm and align their signs before checking their shapes; keep the nodal count as a separate check on the mode index.

Measure the conditioning of a shooting residual

For \(y''=\kappa^2 y\) with fixed initial position, perturb the initial slope by one. The resulting change at distance \(L\) is \(\sinh(\kappa L)/\kappa\). Compare one shooting integration with a single segment of a multiple-shooting formulation.

Measure the conditioning of a shooting residual. Horizontal axis: Growth parameter κ. Vertical axis: Sensitivity of end value to initial slope. Data follow the figure.
At κ = 10 a slope error of 10⁻⁶ becomes roughly 1.10×10⁻³ across the full interval, versus 7.42×10⁻⁶ over one half. Multiple shooting still has to solve its matching equations; the half-interval curve measures only the local propagation.
Read values from the plot
Sensitivity of end value to initial slope at selected values of Growth parameter κ.
Growth parameter κIntegrate across full unit intervalOne half interval
0.11.00170.50021
3.5754.98830.81218
7.0581.7632.406
10.5251768.99.1667
144295039.165

Download all 241 plotted samples (CSV)

Change parameters · Measure the conditioning of a shooting residual

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Study the full derivation

Solving a two-point boundary problem without guessing the start slope · Dynamics and numerical time integration

When endpoint conditions act on different sides of an interval, shooting can amplify a tiny initial error. Construct a cubic collocation system, test its continuous differential residual and quantify which boundary-value solution the residual actually certifies.