Fundamentals / Numerical mathematics / Numerical ordinary differential equations

From one update to a trajectory

Set up a global error recurrence, verify Runge–Kutta order conditions and identify the role of explicitly time-dependent forcing.

Propagate a sequence of local disturbances

A one-step algorithm satisfies \(e_{n+1}\leq1.05e_n+0.0002\) K, and initially \(e_0=0.01\) K. Derive a bound after ten steps. How much is due to the initial uncertainty and how much is attributable to defects during the run?

Worked solution

Iterating the recurrence gives \(e_{10}\leq1.05^{10}e_0+0.0002(1.05^{10}-1)/(1.05-1)\). Using \(1.05^{10}=1.62889\) yields

\[0.01629+0.00252=0.01881\,\mathrm{K}.\]

A more accurate numerical step reduces the second contribution directly; reducing uncertainty in the initial measurement reduces the first. The bound allows maximally aligned and amplified disturbances at every step and need not be attained on a particular trajectory.

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.

Integrate a time ramp

For \(y'=3t+1\) with \(y(0)=0\), take one step of length 0.4. Compute the Euler, explicit midpoint and Heun values. Explain their performance and predict what happens if both Heun stages mistakenly evaluate the forcing at the old time.

Worked solution

Euler gives 0.4. At the midpoint the slope is \(1+3(0.2)=1.6\), so midpoint gives 0.64. Heun averages slopes 1 and 2.2 and likewise gives 0.64. Integrating analytically gives \(y=t+1.5t^2\), hence 0.64.

A linear forcing is integrated exactly by both second-order rules. If both evaluations use the old time the two slopes coincide and Heun degenerates into the Euler estimate 0.4 here, even if its state predictor is correct.

Explore the related calculation with adjustable inputs. Change the decay rate and forcing ramp, and compare the exact convolution with a frozen-input step.

Design a second-order formula

A two-stage explicit method uses its second stage at \(c=a=2/3\). Find both output weights for order two. Apply the resulting scheme to \(y'=y,\ y_0=2,\ h=0.3\) and compare with the exact endpoint.

Worked solution

The order conditions are \(b_2c=1/2\) and \(b_1+b_2=1\), giving \(b_2=3/4,\ b_1=1/4\). The first slope is 2 and the second is

\[2+0.2(2)=2.4.\]

The update gives

\[2+0.3(0.25\cdot2+0.75\cdot2.4)=2.69.\]

The exact value is

\[2e^{0.3}=2.69972.\]

Every explicit two-stage second-order method has the same stability polynomial on this constant linear equation, so this test alone cannot distinguish their different nonlinear error constants.

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.

Measure a collocation curve between its Gaussian nodes

On a unit step solve \(y'=t^3,\ y(0)=0\) by the two-node Gaussian collocation method. Determine the linear interpolant of the derivative at the two nodes, integrate it, and compare the endpoint and midpoint with the exact trajectory. The two Gaussian nodes satisfy \(c^2-c+1/6=0\).

Worked solution

At either node,

\[c^3=c(c-1/6)=(5/6)c-1/6.\]

Thus the interpolated derivative is \((5/6)t-1/6\) and \(U(t)=(5/12)t^2-t/6\). Its endpoint is \(1/4\), exactly the Gaussian quadrature integral of the cubic forcing.

At \(t=1/2\) the collocation polynomial gives \(1/48\), whereas the true value \(t^4/4\) is \(1/64\). The excess is \(1/192\). An exact integrated endpoint is compatible with an imperfect continuous curve. Endpoint superconvergence alone does not qualify an event interpolant.

Try this calculation. Change the parameters in the corresponding calculation and compare its independently recomputed values with the equation derived in this solution.

Revisit chapter 2 · Derive implicit stages from polynomial collocation.

Predict when a conservative calculation loses all reactant

Keep the same final time \(5/k\) and take five equal steps for the conversion \(A\to B\) starting at \(A=1,\ B=0\). Derive the first Euler update, the exact final \(A\), and the five-step RK4 prediction using its fourth-degree stability polynomial. Which mass-balance diagnostic would report a mistake?

Work through the solution

Here \(kh=1\), so Euler transfers all of A in the first step. Its final A is zero while the exact value is \(e^{-5}=0.00673795\) mol/m³. At \(z=-1\) the RK4 multiplier is \(1-1+1/2-1/6+1/24=3/8\), giving \((3/8)^5=0.00741577\) mol/m³. In every stage the increments to A and B are opposite, so a check on their total alone detects neither species error. Run the download first with five Euler steps and then with five RK4 steps.

Use the OneSimulation laboratory to check your answer