A1344 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A13 · Lesson 44 · Boundary-value problems

Shooting and finite differences for conditions at both ends

The ODE solvers so far start from known values at one point and march forward. Many engineering problems instead fix conditions at both ends: a cooling fin's temperature at its base and its insulated tip, the potential at both contacts of a diode, a beam supported at both ends. These boundary-value problems need different tools. Shooting guesses the missing starting slope, integrates, and corrects the guess until the far end comes out right. Finite differences replace the derivatives with differences at every grid point at once and solve the resulting banded system. Each has a regime where the other fails.

  • The curve is the exact solution of y′′=k2y with y(0)=1 and y(1)=0.
  • Raise k: the solution hugs zero except near x = 0. The first readout shows how much a slope error at x = 0 grows by x = 1 when you shoot; it passes a thousand at k = 10.
  • The second readout is the diagonal of the finite-difference system with h = ¼. It stays above 2, so the system stays diagonally dominant and easy to solve, however large k gets.

Predict

Shooting solves y′′=100y on [0, 1] by integrating from x = 0 with a guessed slope. A slope error of 10−8 at the start becomes how large an error at x = 1?

Name it

Shooting

For y′′=f(x,y,y′) with y(a)=α and y(b)=β: guess the slope s at a, integrate the initial-value problem to b, and call the miss F(s)=y(b;s)−β. Then solve F(s)=0 with the secant method or Newton's method. For a linear ODE, y(b;s) is linear in s, so two shots determine s exactly.

Shooting reuses good IVP solvers, but if the ODE has rapidly growing solutions the miss is extremely sensitive to s, and errors explode. Multiple shooting (restarting from several points) tames that.

Finite differences

Put N interior points with spacing h and replace y′′ by yi+1−2yi+yi−1h2 at each. For y′′=k2y that gives yi−1−(2+k2h2)yi+yi+1=0, a tridiagonal system solved in O(N) operations (lesson 24). The error is O(h2), and Richardson extrapolation lifts it to O(h4). Nonlinear problems give nonlinear algebraic systems, solved by Newton's method with a tridiagonal Jacobian.

Boundary conditions

Fixed values go straight into the equations' right sides. A slope condition like y′(L)=0 (an insulated fin tip) uses a ghost point yN+1=yN−1 to keep second-order accuracy.

Where they come from

Fins and heat sinks (T′′=m2(T−Tair)), cables and beams, carrier diffusion in a semiconductor (n′′=n/L2), the potential across a junction (Poisson's equation, nonlinear), and steady temperature in a wire with resistive heating.

Worked example

Solve y′′=y with y(0)=0 and y(1)=1 by linear shooting.

Show the solution
  1. One shot. Starting with y(0)=0 and slope s, the solution is y=ssinh⁡x, so y(1)=ssinh⁡1 One shot with s = 1 gives y(1)=1.1752.
  2. Scale. The problem is linear, so s=11.1752=0.8509
  3. The solution. y=sinh⁡xsinh⁡1
  4. Nonlinear problems. For a nonlinear equation, the secant method on the miss does the same job in a few iterations, each one a full IVP solve.

Answer the starting slope is 0.8509, and the solution is y=sinh⁡xsinh⁡1.

Worked example

Solve y′′=4y with y(0)=1 and y(1)=0 by finite differences with h = 0.25.

Show the solution
  1. The difference equations. At the three interior points yi−1−(2+4×0.0625)yi+yi+1=0 so the diagonal is 2.25.
  2. Back-substitute. With y0=1 and y4=0: y2=2.25y3y1=4.0625y31=6.8906y3
  3. Solve. y3=0.1451y2=0.3265y1=0.5896
  4. Compare with the exact values. sinh⁡2(1−x)sinh⁡2 gives 0.5871, 0.3240 and 0.1437: errors of about 0.0025, from a grid of only three points.
  5. A finer grid. Halving h would cut them to about 0.0006.

Answer y1=0.5896, y2=0.3265 and y3=0.1451, within about 0.0025 of the exact values.

Worked example

Why does shooting fail on y′′=100y while finite differences succeed?

Show the solution
  1. The general solution. It is Ae10x+Be−10x.
  2. What a slope error does. Shooting from x = 0 with a slope error δ adds δsinh⁡10x10 which reaches 1101δ at x = 1.
  3. Worse still. For y′′=104y the factor is 1041, far beyond double precision, so no slope can be found.
  4. Finite differences. The system yi−1−(2+100h2)yi+yi+1=0 is diagonally dominant, so elimination is stable and every unknown is computed together, with both boundary values in view.
  5. Why that works. The growing and decaying solutions are each pinned at the end where they're small.

Answer shooting multiplies any slope error by the growing exponential (1101 times here, 1041 times for y′′=104y), while the finite-difference system is diagonally dominant and pins both ends at once.

Check

Shooting solves y′′=32y with y(0)=0 and y(1)=1. What starting slope hits the target?

Check

Finite differences on y′′=22y with h = 0.1: what is the diagonal of the system yi−1−dyi+yi+1=0?

Check

Shooting on y′′=102y over [0, 1]: by what factor does a starting slope error grow by x = 1?

Check

A second-order finite-difference solution has error 0.004 at a given point.

(a)

What error do you expect with h divided by 2?

(b)

And the number of points grows by about what factor?

Check

Newton's method on the finite-difference form of y′′=ey. What is a diagonal entry of the Jacobian at a point where yi = 1, with h = 0.5?

Check

A fin with T′′=m2T (T measured from the air temperature), m = 10 m⁻¹, length 0.02 m, base at T = 1 and an insulated tip. What is the tip temperature?

Check

When is shooting a poor choice for a two-point boundary-value problem?

Check

Solve y′′=k2y with y(0)=0 and y(1)=1.

Step 1

What is y(x)?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why do finite differences handle boundary-value problems with growing and decaying solutions better than shooting?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.