Fundamentals / Numerical mathematics / Numerical ordinary differential equations

Boundary and algebraic conditions

Recover missing initial data, measure shooting amplification, and calculate a consistent implicit step for a constrained state.

A slope from an endpoint

Solve \(y''=2\), \(y(0)=1,\ y(2)=3\) by shooting. Write the endpoint residual and derivative, take a Newton update from zero, and evaluate the fitted midpoint value.

Worked solution

With initial slope \(s\), \(y(t)=1+st+t^2\). The residual is

\[1+2s+4-3=2+2s.\]

Its derivative is 2.

The update from zero gives \(s=-1\) exactly because the residual is affine. At \(t=1\) the fitted value is 1; at \(t=2\) it returns 3. The trajectory initially decreases before turning upward.

Explore the related calculation with adjustable inputs. Change the propagation length scale and mesh resolution to compare shooting sensitivity with a boundary-value discretisation.

Quantify an unstable direction

For \(y''=16y,\ y(0)=0\), express \(y(1)\) as a function of the initial slope. Calculate the slope needed for \(y(1)=2\), and estimate the change in terminal value caused by an absolute slope error of 0.001.

Worked solution

Superposition gives

\[y(t)=(s/4)\sinh(4t).\]

Hence \(s=8/\sinh4\approx0.29315\) and the endpoint sensitivity is \(\sinh4/4\approx6.8225\).

A slope error of 0.001 causes terminal error about 0.00682. This is exact up to rounding in the multiplier because the differential equation and its slope dependence are linear.

Explore the related calculation with adjustable inputs. Change the propagation length scale and mesh resolution to compare shooting sensitivity with a boundary-value discretisation.

Enforce a time-dependent constraint

For \(y'=z,\ y+z=1+t,\ y(0)=0\), find consistent initial values and one backward Euler step of length 0.5. Solve the reduced equation and assess why the step has this particular error.

Worked solution

The initial constraint gives \(z(0)=1\) and therefore \(y'(0)=1\). At the new time \(y_1=0.5z_1\), \(y_1+z_1=1.5\), yielding \(y_1=0.5,z_1=1\).

The reduced equation \(y'=1+t-y\) has exact solution \(y=t\) with this initial value. Its derivative is constant along the trajectory, so backward Euler reproduces it exactly here. Different initial data introduce an exponential transient for which the step would have time-discretisation error.

Explore the related calculation with adjustable inputs. Change the parameters in the corresponding calculation and compare its independently recomputed values with the equation derived in this solution.

Separate conservation, stability and accuracy in a decay calculation

A transfers to B with rate 0.8 s⁻¹ and A+B = 1 mol/m³. Start from pure A. Use Euler with a 1.5 s step, backward Euler with the same step, and the exact solution to find A and B after one step. Which tests pass? Predict the fine-grid error ratio for RK4 in the downloadable run, and identify a meaningful comparison of computational effort.

Worked solution

The exact A concentration is exp(−1.2) ≈ 0.3010, leaving B ≈ 0.6990. Forward Euler multiplies A by 1−1.2 = −0.2, giving A = −0.2 and B = 1.2. Total concentration is conserved. The amplification modulus is less than one, so repeated steps decay, but every other A value is negative. Absolute stability and positivity test different properties.

Backward Euler gives A = 1/(1+1.2) ≈ 0.4545 and B ≈ 0.5455. Both are positive and their sum is one, yet the A error is about 0.1535. These invariant checks detect important failures, but their success cannot quantify time-discretisation error.

For a smooth solution on a fixed interval the global RK4 error should fall by approximately 2⁴ when the step is halved in its asymptotic range. Use the chapter 2 OneSimulation plot to estimate the order from the last two mesh sizes. For a cost comparison count four right-hand-side calls per RK4 step versus one per Euler step. This model is deliberately small enough that wall-clock startup time would obscure that comparison.

Explore the related calculation with adjustable inputs. Change the parameters in the corresponding calculation and compare its independently recomputed values with the equation derived in this solution.