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 with and .
- 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 on [0, 1] by integrating from x = 0 with a guessed slope. A slope error of at the start becomes how large an error at x = 1?
About : a slope error δ grows to . The equation has a growing solution , and integrating from one end amplifies every error along it. With stiffer equations (larger k), shooting loses all accuracy, while finite differences, which treat both ends at once, stay well behaved.
Name it
Shooting
For with and : guess the slope s at a, integrate the initial-value problem to b, and call the miss . Then solve with the secant method or Newton's method. For a linear ODE, 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 by at each. For that gives , a tridiagonal system solved in O(N) operations (lesson 24). The error is , and Richardson extrapolation lifts it to . 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 (an insulated fin tip) uses a ghost point to keep second-order accuracy.
Where they come from
Fins and heat sinks (), cables and beams, carrier diffusion in a semiconductor (), the potential across a junction (Poisson's equation, nonlinear), and steady temperature in a wire with resistive heating.
Worked example
Solve with and by linear shooting.
Show the solution
- One shot. Starting with and slope s, the solution is , so One shot with s = 1 gives .
- Scale. The problem is linear, so
- The solution.
- 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 .
Worked example
Solve with and by finite differences with h = 0.25.
Show the solution
- The difference equations. At the three interior points so the diagonal is 2.25.
- Back-substitute. With and :
- Solve.
- Compare with the exact values. gives 0.5871, 0.3240 and 0.1437: errors of about 0.0025, from a grid of only three points.
- A finer grid. Halving h would cut them to about 0.0006.
Answer , and , within about 0.0025 of the exact values.
Worked example
Why does shooting fail on while finite differences succeed?
Show the solution
- The general solution. It is .
- What a slope error does. Shooting from x = 0 with a slope error δ adds which reaches at x = 1.
- Worse still. For the factor is , far beyond double precision, so no slope can be found.
- Finite differences. The system is diagonally dominant, so elimination is stable and every unknown is computed together, with both boundary values in view.
- 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, times for ), while the finite-difference system is diagonally dominant and pins both ends at once.
Check
Shooting solves with and . What starting slope hits the target?
Check
Finite differences on with h = 0.1: what is the diagonal of the system ?
Check
Shooting on 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 . What is a diagonal entry of the Jacobian at a point where = 1, with h = 0.5?
Check
A fin with (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 with and .
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°.
Step 2
What slope does it start with, the one shooting must find?
Explain why
Why do finite differences handle boundary-value problems with growing and decaying solutions better than shooting?
Shooting turns the problem into an initial-value problem integrated from one end, so any error at the start is carried across the whole interval by the ODE, and growing solutions magnify it enormously. Finite differences write one equation per grid point and solve them all together, with the conditions at both ends included from the start. Each solution component is effectively determined from the end where it is small: a growing exponential is pinned by its value at the far end, a decaying one by the near end. The resulting matrix is banded and diagonally dominant, so elimination is stable, and no error has to travel across the interval unchecked.
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.