Differential Equations › Section H · Boundary value problems and Fourier series › Topic H.8

Numerical methods for systems and boundary problems

Most equations met in engineering and science have no formula solution, and many come as systems or with conditions at two ends. The stepping methods you already know extend to systems almost unchanged, and two further ideas, shooting and finite differences, handle boundary value problems.

Beyond one equation and one starting point

"Euler's method and error" and "Runge-Kutta and multistep methods" stepped a single first order equation forward from an initial value. Real problems are rarely so tidy: a spacecraft's motion couples several unknowns, a pendulum obeys a second order equation, and a heated rod gives conditions at both ends. Systems and higher order equations need only vector bookkeeping. Boundary value problems need more, because half the information sits at the far end.

Systems and higher order equations

Numerical solvers work with first order systems \(\mathbf{y}' = \mathbf{F}(t, \mathbf{y})\), where \(\mathbf{y}\) is a vector of unknowns. Euler's method becomes \(\mathbf{y}_{k+1} = \mathbf{y}_k + h\mathbf{F}(t_k, \mathbf{y}_k)\), applied to every component at once, and the classical Runge-Kutta method (RK4) works the same way with vector stages. A higher order equation is first rewritten as a system. For the pendulum \(\theta'' = -\sin\theta\), set \(y_1 = \theta\) and \(y_2 = \theta'\); then \(y_1' = y_2\) and \(y_2' = -\sin y_1\). An \(n\)th order equation always becomes \(n\) first order equations this way.

Worked example: stepping a system

Approximate the solution of \(y'' + y = 0\), \(y(0) = 1\), \(y'(0) = 0\), whose exact solution is \(\cos t\). 1. Set \(y_1 = y\) and \(y_2 = y'\): then \(y_1' = y_2\) and \(y_2' = -y_1\), starting from \((1, 0)\). 2. One Euler step with \(h = 0.1\) adds \(h\) times \((0, -1)\), giving \((1, -0.1)\). 3. A second step adds \(h\) times \((-0.1, -1)\), giving \((0.99, -0.2)\). 4. Compare \(\cos 0.2 \approx 0.98007\): Euler is off by about 0.01. 5. One RK4 step of the same size gives \(y_1 \approx 0.995004\), agreeing with \(\cos 0.1\) to six decimal places.

Applied example: a ball with air resistance

A ball moving through air, with drag proportional to the square of its speed, obeys \(x'' = -cvx'\) and \(y'' = -g - cvy'\), where \(v = \sqrt{x'^2 + y'^2}\) and \(c\) depends on the ball and the air. The model assumes constant \(c\), no wind and no spin. The speed couples the two equations, and in general there is no solution in elementary functions. Set \(\mathbf{y} = (x, x', y, y')\) to get four first order equations, step them with RK4, and stop when \(y\) returns to 0. This gives the path, range and flight time, and the same approach underlies trajectory tools in ballistics and sports analytics.

Why boundary problems are harder

For \(y'' = f(x, y, y')\) with \(y(a) = \alpha\) and \(y(b) = \beta\), a stepping method cannot start: it needs \(y\) and \(y'\) at \(x = a\), but \(y'(a)\) is unknown and \(\beta\) sits at the far end. As "Boundary value problems" showed, such a problem may even have no solution or many. Two standard strategies exist. Shooting turns the BVP into a sequence of initial value problems. Finite differences replace the derivatives with algebra on a grid and solve for all the unknown values at once.

The shooting method

Guess the missing slope \(y'(a) = s\), solve the initial value problem numerically, and read off the value \(y(b; s)\) that it reaches. If it misses \(\beta\), adjust \(s\) and fire again, just as a gunner corrects the angle after seeing where a shell lands. Finding the right \(s\) is a root-finding problem for \(\phi(s) = y(b; s) - \beta\), solved by bisection or the secant method. For a linear equation, \(y(b; s)\) is a linear function of \(s\), so two shots and a straight-line interpolation give the right slope at once. For nonlinear equations several rounds are usually needed.

Worked example: shooting

Solve \(y'' = y\), \(y(0) = 0\), \(y(1) = 1\) by shooting. 1. With \(y'(0) = s\), the initial value problem gives \(y(1; s) = s\sinh 1\); a numerical solver would produce these values to within its step error. 2. First shot: \(s = 0.5\) gives \(y(1) \approx 0.5876\), too low. 3. Second shot: \(s = 1\) gives \(y(1) \approx 1.1752\), too high. 4. The equation is linear, so interpolate:

s = 0.5 + 0.5 \cdot \frac{1 - 0.5876}{1.1752 - 0.5876} \approx 0.8509

5. Check: the exact slope is \(\frac{1}{\sinh 1} \approx 0.8509\), and the exact solution is \(y = \frac{\sinh x}{\sinh 1}\).

Finite differences

Divide \([a, b]\) into \(N\) steps of width \(h\), with grid points \(x_i = a + ih\) and unknown values \(y_i \approx y(x_i)\). Replace the second derivative by the central difference

y''(x_i) \approx \frac{y_{i+1} - 2y_i + y_{i-1}}{h^2}

whose error is proportional to \(h^2\) for smooth solutions. Writing the equation at each interior point, with \(y_0 = \alpha\) and \(y_N = \beta\) known, gives \(N - 1\) algebraic equations. For a linear equation each one involves only three neighbouring unknowns, so the system is tridiagonal, and it can be solved in a number of steps proportional to \(N\) rather than \(N^3\).

Worked example: a grid of four steps

Solve \(y'' = y\), \(y(0) = 0\), \(y(1) = 1\) with \(h = 0.25\). 1. At each interior point, \(y_{i+1} - 2y_i + y_{i-1} = h^2y_i\), so \(y_{i-1} - 2.0625y_i + y_{i+1} = 0\). 2. With \(y_0 = 0\) and \(y_4 = 1\): \(-2.0625y_1 + y_2 = 0\), \(y_1 - 2.0625y_2 + y_3 = 0\) and \(y_2 - 2.0625y_3 = -1\). 3. Solving gives \(y_1 \approx 0.2151\), \(y_2 \approx 0.4437\), \(y_3 \approx 0.7000\). 4. The exact values are 0.2150, 0.4434 and 0.6997, so the error is under 0.0003. 5. Halving \(h\) to 0.125 cuts the error at \(x = 0.5\) from about 0.00026 to about 0.00007, roughly a factor of 4, as an \(h^2\) error predicts.

Software and validation

In practice, use well-tested libraries: SciPy's solve_ivp and solve_bvp in Python, MATLAB's ode45 and bvp4c, or Julia's DifferentialEquations.jl. They choose step sizes adaptively and report failures. For stiff problems, where some components change far faster than others, explicit methods need tiny steps, so choose an implicit solver such as Radau or BDF in solve_ivp, or ode15s in MATLAB. Then test the code on a problem with a known solution, refine the step or grid until key results stop changing, check conserved quantities such as energy, confirm physical sense, and plot the results.

Common mistakes to avoid

First, converting \(y'' + py' + qy = g\) wrongly, for example forgetting that \(y_2' = g - py_2 - qy_1\) needs every term. Second, updating one component with an already-updated value of another inside the same Euler step. Third, giving up on shooting after one miss instead of adjusting the slope. Fourth, mixing up indices or dropping the \(h^2\) in the difference equations. Fifth, using an explicit solver on a stiff problem. Sixth, reporting results without checking that they converge as the step shrinks.

Key takeaways

Rewrite any higher order equation as a first order system and apply Euler or RK4 to the whole vector at once. Boundary value problems need extra ideas: shooting guesses the missing initial slope and corrects it by root finding, exactly in two shots for linear problems; finite differences replace \(y''\) with \(\frac{y_{i+1} - 2y_i + y_{i-1}}{h^2}\), giving a tridiagonal system with error proportional to \(h^2\). Use trusted libraries, implicit solvers for stiff problems, and always validate with known cases, refinement and physical checks.

Flashcards

Flashcard

y′ = F(t, y)

A first order system in vector form

What numerical solvers expect.

Test your understanding

Question 1 of 5

Writing y″ + 3y′ + 2y = 0 as a system with y₁ = y and y₂ = y′, what is y₂′?

Question 2 of 5

For y₁′ = y₂, y₂′ = −y₁ starting at (1, 0), what does one Euler step with h = 0.2 give?

Question 3 of 5

Shooting on a linear BVP, slope s = 0 gives y(L) = 2 and s = 1 gives y(L) = 5. Which slope hits y(L) = 11?

Question 4 of 5

A finite-difference solution has error 0.0008 with grid spacing h. About what error should h/2 give?

Question 5 of 5

On a grid with h = 0.5, three neighbouring values are 1.0, 1.5 and 3.0. What does the central difference give for y″ at the middle point?

← Previous topicNext topic →