Unit 10, lesson 60

Numerical Boundary-Value Problems

How shooting turns a two-point boundary-value problem into a search for a root of the boundary residual, how finite differences lead to a tridiagonal system, and how conditioning and nonunique solutions limit both.

  • Video 60
  • Numerical Boundary Problems and Verification

An initial-value solver needs the complete state at one time, which for a second-order equation means a value and a slope. A boundary-value problem gives one condition at each end of an interval instead, so the starting slope is unknown. Throughout, xx is the independent variable on an interval [a,b][a, b] and y′=dy/dxy' = dy/dx. This lesson computes such problems in two ways, by adjusting the missing slope until the far boundary is met and by solving for the values on a whole grid at once, and it shows when neither method can single out an answer.

Key terms

Shooting method

Definition Consider the two-point boundary-value problem

y′′=f(x,y,y′),a≤x≤b,y(a)=α,y(b)=β.\begin{gathered} y'' = f(x, y, y'), \quad a \le x \le b, \\[0.4em] y(a) = \alpha, \qquad y(b) = \beta. \end{gathered}

The shooting method replaces the missing initial slope by a parameter ss and solves the initial-value problem with y(a)=αy(a) = \alpha and y′(a)=sy'(a) = s, whose solution is written y(x;s)y(x; s). It then adjusts ss until y(b;s)=βy(b; s) = \beta. When these initial-value problems have unique solutions that exist on all of [a,b][a, b], the solutions of the boundary-value problem correspond exactly to the slopes that hit the target, each solution yy belonging to its own slope s=y′(a)s = y'(a). In practice each trial is integrated numerically, for example with an adaptive Runge-Kutta method, and a root-finding method chooses the next slope.

In plain words Guess the launch slope, integrate across the interval, see by how much the far boundary was missed, and correct the guess. The boundary problem becomes a sequence of initial-value problems plus a search for one number.

Example Take y′′=−2y'' = -2 on [0,1][0, 1] with y(0)=0y(0) = 0 and y(1)=0y(1) = 0. With the trial slope y′(0)=sy'(0) = s, integrating once gives y′=s−2xy' = s - 2x, and integrating again with y(0)=0y(0) = 0 gives

y(x;s)=sx−x2.y(x; s) = sx - x^2.

The far value is y(1;s)=s−1y(1; s) = s - 1, so the slope s=1s = 1 hits the target and the solution is y=x(1−x)y = x(1 - x). It satisfies every part of the problem, since y′′=−2y'' = -2, y(0)=0y(0) = 0 and y(1)=0y(1) = 0. The trial with s=2s = 2 satisfies the equation and the left condition but ends at y(1)=1y(1) = 1, which is why each condition has to be checked on its own.

Boundary residual

Definition For a trial slope ss, the boundary residual is the amount by which the trajectory misses the far condition,

R(s)=y(b;s)−β.R(s) = y(b; s) - \beta.

Shooting is a search for the roots of RR. For a linear differential equation, RR is an affine function of ss, so two trial shots determine the root up to the integration error. For a nonlinear equation, bisection is reliable once two slopes with residuals of opposite signs are known. Newton’s method needs R′(s)R'(s), and when ff has continuous partial derivatives fyf_y and fy′f_{y'}, it equals w(b)w(b) for the sensitivity w=∂y/∂sw = \partial y/\partial s, which solves

w′′=fy w+fy′ w′,w(a)=0,w′(a)=1,\begin{gathered} w'' = f_y\,w + f_{y'}\,w', \\[0.4em] w(a) = 0, \qquad w'(a) = 1, \end{gathered}

with the partial derivatives evaluated along y(x;s)y(x; s). More generally, the boundary residual of any computed approximation is the amount by which it fails a boundary condition.

In plain words The residual is the miss distance at the far end, as a function of the launch slope. A zero miss means a solution, and the slope of the residual says how strongly the miss responds to a change of launch.

Example In the shooting example R(s)=s−1R(s) = s - 1 and R′(s)=1R'(s) = 1 for every ss. The sensitivity equation agrees, since w′′=0w'' = 0 with w(0)=0w(0) = 0 and w′(0)=1w'(0) = 1 gives w=xw = x, so w(1)=1w(1) = 1. Because RR is affine, the two trials R(0)=−1R(0) = -1 and R(2)=1R(2) = 1 already locate the root, since the line through the points (0,−1)(0, -1) and (2,1)(2, 1) crosses zero at s=1s = 1.

Finite-difference method

Definition Divide [a,b][a, b] into N+1N + 1 equal steps of length h=(b−a)/(N+1)h = (b - a)/(N + 1) with grid points xi=a+ihx_i = a + ih. Let YiY_i approximate y(xi)y(x_i) at the interior points i=1,…,Ni = 1, \dots, N, and fix Y0=αY_0 = \alpha and YN+1=βY_{N+1} = \beta from the boundary conditions. The finite-difference method replaces each derivative in the equation by a difference quotient at the grid points, here the centered second difference

y′′(xi)≈Yi−1−2Yi+Yi+1h2,y''(x_i) \approx \frac{Y_{i-1} - 2Y_i + Y_{i+1}}{h^2},

and solves the resulting algebraic equations for all interior values at once. If yy has a continuous fourth derivative, adding the Taylor expansions of y(xi+h)y(x_i + h) and y(xi−h)y(x_i - h) cancels the odd terms and gives

y(xi−1)−2y(xi)+y(xi+1)h2=y′′(xi)+h212 y′′′′(ξi)\begin{aligned} &\frac{y(x_{i-1}) - 2y(x_i) + y(x_{i+1})}{h^2} \\[0.4em] &\qquad = y''(x_i) + \frac{h^2}{12}\,y''''(\xi_i) \end{aligned}

for some ξi\xi_i between xi−1x_{i-1} and xi+1x_{i+1}. For the linear problem −y′′+q(x)y=r(x)-y'' + q(x)y = r(x) with qq and rr continuous and q≥0q \ge 0 on [a,b][a, b], the discrete equations have exactly one solution for every hh, and when the true solution has a continuous fourth derivative the errors ∣Yi−y(xi)∣\lvert Y_i - y(x_i) \rvert are at most a constant times h2h^2.

In plain words Instead of firing trajectories, put unknown heights on a grid and require the equation to hold approximately at every interior point. Each equation ties a point to its two neighbors, and the boundary values enter as known numbers.

Example For y′′=−2y'' = -2 on [0,1][0, 1] with zero boundary values, take h=1/4h = 1/4. The grid is 0,14,12,34,10, \tfrac14, \tfrac12, \tfrac34, 1, with unknowns Y1,Y2,Y3Y_1, Y_2, Y_3 and Y0=Y4=0Y_0 = Y_4 = 0. Each interior equation is

Yi−1−2Yi+Yi+11/16=−2,\frac{Y_{i-1} - 2Y_i + Y_{i+1}}{1/16} = -2,

and multiplying by −1/16-1/16 gives −Yi−1+2Yi−Yi+1=1/8-Y_{i-1} + 2Y_i - Y_{i+1} = 1/8 for i=1,2,3i = 1, 2, 3. The solution, found in the next card, is (Y1,Y2,Y3)=(3/16,1/4,3/16)(Y_1, Y_2, Y_3) = (3/16, 1/4, 3/16). These are exactly the values of x(1−x)x(1 - x) at the interior points, because a quadratic has y′′′′=0y'''' = 0 and the error term vanishes. That exactness is special to this example. In general the grid is refined and the values are checked for convergence.

Tridiagonal system

Definition A tridiagonal system is a linear system TY=dTY = d whose matrix has nonzero entries only on the main diagonal and on the two diagonals next to it. A centered three-point difference produces such a system, because each grid equation involves only Yi−1Y_{i-1}, YiY_i and Yi+1Y_{i+1}, and the known boundary values move to the right side. Gaussian elimination keeps this pattern and solves the system in a number of operations proportional to NN, a procedure often called the Thomas algorithm. It needs no row exchanges when TT is symmetric positive definite or strictly diagonally dominant. For y′′=g(x)y'' = g(x) with given boundary values, the matrix after multiplying by −h2-h^2 has 22 on the diagonal and −1-1 beside it, and it is symmetric positive definite.

In plain words Each unknown is linked only to its neighbors, so the matrix is empty except for a narrow band. Elimination sweeps down the band once and back up once, which is far cheaper than treating the matrix as full.

Example The finite-difference example leads to

[2−10−12−10−12][Y1Y2Y3]=18[111].\begin{bmatrix} 2 & -1 & 0 \\ -1 & 2 & -1 \\ 0 & -1 & 2 \end{bmatrix} \begin{bmatrix} Y_1 \\ Y_2 \\ Y_3 \end{bmatrix} = \frac{1}{8}\begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}.

Adding half of the first row to the second gives 32Y2−Y3=316\tfrac32 Y_2 - Y_3 = \tfrac{3}{16}, and adding two thirds of this new row to the third gives 43Y3=14\tfrac43 Y_3 = \tfrac14. Back substitution then gives Y3=316Y_3 = \tfrac{3}{16}, then Y2=14Y_2 = \tfrac14, then Y1=316Y_1 = \tfrac{3}{16}. Each row checks. The first gives 2⋅316−14=182 \cdot \tfrac{3}{16} - \tfrac14 = \tfrac18, the second gives −316+12−316=18-\tfrac{3}{16} + \tfrac12 - \tfrac{3}{16} = \tfrac18, and the third matches the first by symmetry.

Conditioning

Definition A problem is well conditioned when small changes in its data, such as boundary values, coefficients or small errors made during a computation, change its solution only by comparably small amounts, and ill conditioned when they can change it by much more. Conditioning belongs to the mathematical problem, or to a subproblem that an algorithm creates, not to the program. In shooting, if R(s∗)=0R(s^*) = 0 and R′(s∗)≠0R'(s^*) \ne 0, an error δ\delta in the computed far value shifts the selected slope by about δ/R′(s∗)\delta/R'(s^*), so a nearly flat residual makes the slope ill conditioned. Shooting also suffers when its initial-value problems have a fast growing mode such as ekxe^{kx} with k(b−a)k(b - a) large, because an error made near x=ax = a is multiplied by a factor that grows like ek(x−a)e^{k(x - a)} as the integration proceeds toward x=bx = b. Shooting can then fail in floating-point arithmetic even though the boundary-value problem itself is well conditioned. Finite differences, or multiple shooting, which shoots across short subintervals and matches the pieces, avoid that long-range amplification.

In plain words Ask how much the answer moves when the data move a little. If the far end barely responds to the launch slope, a tiny miss at the far end leaves the slope very uncertain. If the far end responds violently, every small error made along the way is blown up.

Example In the shooting example R′(s)=1R'(s) = 1, so an error of 10−610^{-6} at x=1x = 1 moves the slope by about 10−610^{-6}, and the matching is well conditioned. Now take y′′+k2y=0y'' + k^2 y = 0 on [0,1][0, 1] with y(0)=0y(0) = 0, y(1)=1y(1) = 1 and k=3.1k = 3.1. The trials are y(x;s)=ssin⁡(kx)/ky(x; s) = s\sin(kx)/k, so

R(s)=ssin⁡kk−1,R′(s)=sin⁡kk≈0.0134.\begin{gathered} R(s) = \frac{s\sin k}{k} - 1, \\[0.4em] R'(s) = \frac{\sin k}{k} \approx 0.0134. \end{gathered}

The root is s∗=k/sin⁡k≈74.6s^* = k/\sin k \approx 74.6, and an error of 10−310^{-3} in the far value moves it by about 0.0750.075, roughly 7575 times the error. The residual is nearly flat because kk is close to π\pi, where uniqueness breaks down, as the next card shows. The opposite trouble appears for y′′=1600yy'' = 1600y with y(0)=1y(0) = 1 and y(1)=0y(1) = 0, whose solution sinh⁡(40(1−x))/sinh⁡(40)\sinh(40(1 - x))/\sinh(40) stays between 00 and 11. That boundary-value problem is well conditioned, since changing either boundary value by δ\delta changes the solution by at most ∣δ∣\lvert \delta \rvert at every point. A change δ\delta in the trial slope changes the far value by δsinh⁡(40)/40≈2.9×1015 δ\delta\sinh(40)/40 \approx 2.9 \times 10^{15}\,\delta, so a slope error of 10−1410^{-14}, close to the spacing 7.1×10−157.1 \times 10^{-15} of double-precision numbers near 4040, moves y(1)y(1) by about 2929.

Nonunique boundary solutions

Definition A boundary-value problem has nonunique solutions when two different functions satisfy the differential equation and all the boundary conditions. Take a linear second-order equation with coefficients continuous on [a,b][a, b] and two linear boundary conditions. Every solution of the equation has the form y=yp+c1y1+c2y2y = y_p + c_1y_1 + c_2y_2, with a particular solution ypy_p and a fundamental pair y1,y2y_1, y_2 of the homogeneous equation, and the boundary conditions become a 2×22 \times 2 linear system for c1c_1 and c2c_2. If its matrix is invertible, the problem has exactly one solution. If the matrix is singular, the homogeneous problem, with zero forcing and zero boundary data, has a nonzero solution, and the original problem has either no solution or infinitely many. Nonlinear problems can also have several separate solutions, and a root finder then returns whichever one its starting guess leads to.

In plain words The data may fail to pin down one curve. A whole family can fit both ends, or no curve at all, and no algorithm can pick out an answer that the problem itself does not single out.

Example For y′′+π2y=0y'' + \pi^2 y = 0 on [0,1][0, 1] with y(0)=y(1)=0y(0) = y(1) = 0, every function y=Asin⁡(πx)y = A\sin(\pi x) satisfies the equation and both boundary conditions. The trials are y(x;s)=ssin⁡(πx)/πy(x; s) = s\sin(\pi x)/\pi, so R(s)=ssin⁡(π)/π=0R(s) = s\sin(\pi)/\pi = 0 for every slope and shooting has nothing to select. Changing the equation to y′′+π2y=1y'' + \pi^2 y = 1 leaves no solution at all, because the general solution 1/π2+c1cos⁡(πx)+c2sin⁡(πx)1/\pi^2 + c_1\cos(\pi x) + c_2\sin(\pi x) with y(0)=0y(0) = 0 forces c1=−1/π2c_1 = -1/\pi^2, and then y(1)=2/π2≠0y(1) = 2/\pi^2 \ne 0. The finite-difference system for the original problem is invertible for every h=1/(N+1)h = 1/(N + 1) and returns only Y=0Y = 0, which hides the family. Its smallest eigenvalue in absolute value is about π4h2/12\pi^4h^2/12, so its condition number grows from about 9090 at h=1/4h = 1/4 to about 5×1075 \times 10^7 at h=1/100h = 1/100. A nearly singular matrix may be faithfully reporting a problem without a unique solution. For a nonlinear example, y′′+ey=0y'' + e^y = 0 with y(0)=y(1)=0y(0) = y(1) = 0 has two solutions, with initial slopes s≈0.549s \approx 0.549 and s≈10.85s \approx 10.85 and largest values about 0.1410.141 and 4.094.09.

Check yourself

  1. Use shooting to solve y′′=6xy'' = 6x on [0,1][0, 1] with y(0)=0y(0) = 0 and y(1)=2y(1) = 2, and check the result against every part of the problem.
Show the answer

With y(0)=0y(0) = 0 and y′(0)=sy'(0) = s, integrating twice gives y′=s+3x2y' = s + 3x^2 and

y(x;s)=sx+x3.y(x; s) = sx + x^3.

The residual is R(s)=y(1;s)−2=s−1R(s) = y(1; s) - 2 = s - 1, so s=1s = 1 and y=x+x3y = x + x^3. The checks are y′′=6xy'' = 6x, y(0)=0y(0) = 0 and y(1)=1+1=2y(1) = 1 + 1 = 2.

  1. Set up and solve the finite-difference equations for the problem of question 1 with h=1/3h = 1/3. Compare the result with the exact solution and explain the agreement.
Show the answer

The grid is 0,13,23,10, \tfrac13, \tfrac23, 1 with Y0=0Y_0 = 0 and Y3=2Y_3 = 2. Since 1/h2=91/h^2 = 9 and the right sides at the interior points are 6⋅13=26 \cdot \tfrac13 = 2 and 6⋅23=46 \cdot \tfrac23 = 4, the two interior equations are

9 (0−2Y1+Y2)=2,9 (Y1−2Y2+2)=4.\begin{aligned} 9\,(0 - 2Y_1 + Y_2) &= 2, \\[0.4em] 9\,(Y_1 - 2Y_2 + 2) &= 4. \end{aligned}

They reduce to −2Y1+Y2=29-2Y_1 + Y_2 = \tfrac29 and Y1−2Y2=49−2=−149Y_1 - 2Y_2 = \tfrac49 - 2 = -\tfrac{14}{9}. The first gives Y2=29+2Y1Y_2 = \tfrac29 + 2Y_1, and substituting into the second gives −3Y1=−109-3Y_1 = -\tfrac{10}{9}, so Y1=1027Y_1 = \tfrac{10}{27} and Y2=2627Y_2 = \tfrac{26}{27}. The exact solution has y(13)=127+13=1027y(\tfrac13) = \tfrac{1}{27} + \tfrac13 = \tfrac{10}{27} and y(23)=827+23=2627y(\tfrac23) = \tfrac{8}{27} + \tfrac23 = \tfrac{26}{27}, the same values. The agreement is exact because x+x3x + x^3 is a cubic, so y′′′′=0y'''' = 0 and the error term of the centered difference vanishes. A common slip is to drop the boundary value Y3=2Y_3 = 2 from the second equation, which would solve a problem with y(1)=0y(1) = 0 instead.

  1. For y′′+k2y=0y'' + k^2 y = 0 on [0,1][0, 1] with y(0)=0y(0) = 0, y(1)=1y(1) = 1 and k>0k > 0, find the boundary residual. For which kk does the problem have exactly one solution, and what happens at k=πk = \pi?
Show the answer

The trials are y(x;s)=ssin⁡(kx)/ky(x; s) = s\sin(kx)/k, so

R(s)=ssin⁡kk−1.R(s) = \frac{s\sin k}{k} - 1.

If sin⁡k≠0\sin k \ne 0, that is, if kk is not an integer multiple of π\pi, the residual has the single root s=k/sin⁡ks = k/\sin k and the unique solution is y=sin⁡(kx)/sin⁡ky = \sin(kx)/\sin k. If k=nπk = n\pi, then R(s)=−1R(s) = -1 for every ss, so no slope works and the problem has no solution. The homogeneous problem with y(1)=0y(1) = 0 has the nonzero solutions Asin⁡(nπx)A\sin(n\pi x) at those values of kk, which is the singular case of the definition. Near k=πk = \pi the root k/sin⁡kk/\sin k is very large in absolute value and the residual is nearly flat, so the computed slope is ill conditioned even where a unique solution exists.

How this lesson connects