A8 · Lesson 51 · Lab: boundary value problems
Finite differences, shooting and eigenvalues
An initial-value problem gives everything at one end and steps forward. A boundary-value problem gives conditions at both ends, so stepping from one end means guessing what you don't know there. Lesson 50 solved these by hand when a formula exists. In this lab you'll solve them numerically in the two standard ways: finite differences, which turn the equation into a tridiagonal linear system, and shooting, which guesses the missing slope and corrects it. Then you'll find a string's vibration modes as the eigenvalues of a matrix.
- The curves are mode of a string or line fixed at both ends, , and its finite-difference approximation's eigenvalue against the exact .
- Low modes are resolved well by a 50-point grid. Raise : as the wavelength shrinks toward the grid spacing, the finite-difference eigenvalue falls further below the true one.
- That's the general rule for discretized waves: a grid needs several points per wavelength.
Predict
Second-order finite differences solve with on a grid of only 10 intervals. How accurate is the answer at the grid points?
Exact. The central difference has an error proportional to , and the true solution here is a parabola, whose fourth derivative is zero. For any other solution the error shrinks by 4 each time halves.
Name it
Finite differences
Divide into intervals of width , and replace at each interior point by
For with known end values, that's equations in the interior values, with a tridiagonal matrix: on the diagonal and beside it. Known end values move to the right side. The error is .
Shooting
Turn the boundary-value problem into an initial-value problem with a guessed slope at the left end, integrate to the right end, and compare with the right-end condition. The mismatch is a function of ; find its zero by bisection or the secant method. For a linear equation the mismatch is linear in , so two shots determine the answer exactly.
Eigenvalues
with becomes for the tridiagonal with on the diagonal and beside it. Its eigenvalues are exactly
which approach as and fall below them for modes with few points per wavelength.
Worked example
Set up the finite-difference system for , , with .
Show the solution
- Unknowns. The interior points are , 0.5 and 0.75, with unknowns .
- One equation per point. With , each equation is
- The system.
- Solve and check. The solution is , exactly at those points: the middle value is .
Answer the three equations above, whose solution matches exactly.
Worked example
Solve with , by shooting.
Show the solution
- Integrate with a guessed slope. Integrating from , gives so .
- The mismatch is linear. The mismatch is linear in , as it must be for a linear equation.
- Two shots. misses by and misses by ; interpolating gives .
- Nonlinear equations. For a nonlinear equation the mismatch is curved, and the secant method takes a few more shots.
Answer .
Check
A finite-difference grid of 20 intervals on approximates . What is the diagonal entry of its matrix?
Check
What is the finite-difference estimate of the = 2 eigenvalue of on with 5 intervals?
Check
Solve on with zero ends by finite differences, = 10 intervals. Set err to the largest difference from the exact at the interior points.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write fd_error(n) that solves with zero ends on intervals and returns the largest error against the exact . Set ratio = fd_error(10) / fd_error(20).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Solve with and by shooting: write shoot(s) returning after integrating from , with RK4 (1000 steps), then bisect on (50 steps) and set s_star.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Build the matrix for on with 50 intervals. Set lam to its three smallest eigenvalues (with np.linalg.eigvalsh) and exact to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A cooling fin obeys with (the base) and (an insulated tip), with = 2. Solve it by finite differences with 100 intervals, using a ghost point for the tip, and set tip to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a finite-difference grid underestimate the high modes' eigenvalues so much more than the low ones'?
The central difference measures curvature from three points spaced apart. For a sine of wavelength much longer than , three points trace the curve closely and the estimate is nearly exact. As the wavelength shrinks toward a few grid spacings, the three points sample the wave so coarsely that the curvature they see is smaller than the true curvature: the estimate becomes instead of , and for every positive . The relative error is about , so it grows with the square of the mode number. Simulations of waves use ten or more points per wavelength for that reason.
Practice
Keep practicing
4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.