Why use more than one slope?
For an initial-value problem, Euler’s method advances a solution using its slope at the start of a step. This gives a useful first approximation, but the slope may change noticeably across the step. The explicit midpoint and Heun methods improve the update by using additional slope information.
Both methods use two evaluations of the differential equation on each step. Their stage values are constructed explicitly from information already available, so neither method requires solving an equation for the new solution value. Their formulas differ, but each reproduces the exact solution’s Taylor terms through second order under suitable smoothness assumptions.
The second-order Taylor expansion of a solution
Consider the initial-value problem \(y'=f(t,y)\), with current value \(y(t_n)=y_n\). Assume \(f\) has continuous second partial derivatives in a neighborhood of the step, and that the solution is defined there. Write \(h\) for the step size, so the next time is \(t_n+h\). The chain rule gives the second derivative of the solution:
Taylor’s theorem, applied at \(t_n\), therefore gives the exact solution’s expansion. In the formulas below, \(f\), \(f_t\), and \(f_y\) without displayed arguments are evaluated at \((t_n,y_n)\).
The notation \(O(h^3)\) means that the remainder is bounded in magnitude by a constant times \(|h|^3\) for sufficiently small \(h\). The goal is to construct an update with the same constant, \(h\), and \(h^2\) terms. This is what it means here for a method to reproduce the solution terms through second order.
Deriving the explicit midpoint method
The midpoint method estimates the slope halfway across the step. First it uses the known initial slope to predict a value at the midpoint. It then evaluates \(f\) at that predicted midpoint and uses the resulting slope over the full step.
Here \(k_1\) is the slope at the start, and \(k_2\) is the estimated slope at the midpoint. The midpoint value \(y_n+\frac{h}{2}k_1\) is a predictor, not the final answer.
Deriving the Heun method
Heun’s method, also called the explicit trapezoidal method, predicts the endpoint with Euler’s method, evaluates the slope at that predicted endpoint, and averages the starting and predicted endpoint slopes. The average slope is then used across the whole step.
The endpoint argument \(y_n+h k_1\) is again a predicted value. The update averages the two slope evaluations; it does not simply accept the predictor as the answer.
Why both methods match through second order
The justification is a Taylor expansion of each method’s slope evaluation. Since \(f\) has continuous second partial derivatives, expanding \(f\) near \((t_n,y_n)\) gives a first-order linear part and a remainder of order \(h^2\) when both input changes are of order \(h\).
The midpoint changes the time by \(h/2\) and the solution value by \(h f/2\), because \(k_1=f\). Thus $$ k_2 =f\left(t_n+\frac h2,y_n+\frac h2 f\right) =f+\frac h2 f_t+\frac h2 f_y f+O(h^2). $$
Multiplying the slope expansion by \(h\) and adding \(y_n\) gives $$ y_{n+1} =y_n+h f+\frac{h^2}{2}(f_t+f_y f)+O(h^3). $$ This agrees with the exact solution’s Taylor expansion through the \(h^2\) term.
The predicted endpoint changes time by \(h\) and solution value by \(h f\). Therefore $$ k_2=f(t_n+h,y_n+h f) =f+h f_t+h f_y f+O(h^2). $$
Using \(k_1=f\), average the slopes and multiply by \(h\): $$ y_{n+1} =y_n+\frac h2\left(2f+h(f_t+f_y f)+O(h^2)\right) =y_n+h f+\frac{h^2}{2}(f_t+f_y f)+O(h^3). $$ This also agrees with the exact expansion through the \(h^2\) term.
The derivation shows why the methods work: both approximate the quantity \(f_t+f_y f\), which determines the curvature \(y''\) of the solution. The midpoint method captures it through a slope at the half step; Heun captures it through the change between the initial and predicted endpoint slopes. In either case, the one-step error from an exact starting value is \(O(h^3)\), provided the stated smoothness holds and the step stays within the region where the solution and \(f\) are defined.
Worked calculations
Worked Example: A linear equation with an exact solution
Apply both methods with \(h=0.2\) to \(y'=t+y\), \(y(0)=1\). Here \(t_n=0\), \(y_n=1\), and \(k_1=f(0,1)=0+1=1\).
For the midpoint method, the predicted midpoint is \(t=0+0.2/2=0.1\) and \(y=1+(0.2/2)(1)=1.1\). Its slope is \(k_2=0.1+1.1=1.2\). Hence \(y_1=1+0.2(1.2)=1.24\).
For Heun’s method, the predicted endpoint is \(t=0.2\) and \(y=1+0.2(1)=1.2\). Its slope is \(k_2=0.2+1.2=1.4\). The update is \(y_1=1+(0.2/2)(1+1.4)=1+0.1(2.4)=1.24\).
To check these results, the exact solution \(y(t)=2e^t-t-1\) satisfies \(y(0)=1\) and \(y'=2e^t-1=t+y\). At \(t=0.2\), it is approximately \(1.242806\), so both numerical values are below it by approximately \(0.002806\). The two methods happen to agree on this step; agreement in one example does not make their formulas identical.
Worked Example: A nonlinear equation
Apply both methods with \(h=0.1\) to \(y'=y^2\), \(y(0)=1\). The initial slope is \(k_1=1^2=1\).
For the midpoint method, the predicted midpoint value is \(1+(0.1/2)(1)=1.05\). The midpoint slope is \(k_2=(1.05)^2=1.1025\). Thus the result is \(y_1=1+0.1(1.1025)=1.11025\).
For Heun’s method, the predicted endpoint value is \(1+0.1(1)=1.1\). The endpoint slope is \(k_2=(1.1)^2=1.21\). Therefore \(y_1=1+(0.1/2)(1+1.21)=1+0.05(2.21)=1.1105\).
The exact solution is \(y(t)=1/(1-t)\): differentiation gives \(y'=1/(1-t)^2=y^2\), and \(y(0)=1\). At \(t=0.1\), its value is \(10/9\), or approximately \(1.111111\). The midpoint error is \(10/9-1.11025=31/36000\), approximately \(0.000861\). The Heun error is \(10/9-1.1105=11/18000\), approximately \(0.000611\). These checks verify the computed outputs and illustrate that the methods can differ even though both reproduce the same terms through second order.
Worked Example: A time-dependent nonlinear equation
Take one step of size \(h=0.1\) for \(y'=t+y^2\), \(y(0)=1\). The initial slope is \(k_1=0+1^2=1\).
For the midpoint method, the predicted midpoint is \((t,y)=(0.05,1.05)\). The midpoint slope is \(k_2=0.05+(1.05)^2=0.05+1.1025=1.1525\). The update gives \(y_1=1+0.1(1.1525)=1.11525\).
For Heun’s method, the predicted endpoint is \((0.1,1.1)\). Its slope is \(k_2=0.1+(1.1)^2=0.1+1.21=1.31\). Averaging the slopes gives \(y_1=1+0.05(1+1.31)=1+0.05(2.31)=1.1155\).
As a check against the second-order Taylor terms, \(f_t=1\), \(f_y=2y=2\), and \(f=1\) at \((0,1)\). Therefore \(y''=f_t+f_y f=1+2(1)=3\), and the exact expansion begins \(y(0.1)=1+0.1+(3/2)(0.1)^2+O((0.1)^3)=1.115+O(0.001)\). Both computed values have the required constant, first-order, and second-order terms; their differing extra digits are not asserted to be exact.
A common midpoint mistake
The midpoint method evaluates its second slope halfway through the time step and uses a solution predictor for that same halfway point. Replacing the half-step predictor by a full Euler step mixes quantities from different points.
For example, with \(y'=y^2\), \(y(0)=1\), and \(h=0.1\), this incorrect stage uses the endpoint predictor \(y=1.1\), giving slope \(1.21\) and result \(1+0.1(1.21)=1.121\). The correct midpoint stage uses \(y=1.05\), giving \(1.1025\) and result \(1.11025\). The mismatch also appears in the Taylor terms: the incorrect result is \(1.121\), whose \(h^2\) coefficient is \(2\), whereas the required coefficient is \(y''/2=2/2=1\) for this equation at the initial point. The correct midpoint formula has that coefficient.
What the second-order match does and does not say
The matching Taylor expansions explain each method’s local accuracy, not the exact value after a finite step. In general, the two methods produce different results, and each has a remainder beyond the displayed \(h^2\) terms. The \(O(h^3)\) local error statement concerns a step begun at the exact solution value; errors already present in a computed starting value are a separate matter.
The practical distinction is in where each method samples the slope. Midpoint uses one predicted slope at half time; Heun averages a starting slope and a predicted endpoint slope. Both choices incorporate information about how the slope changes during a step, which is why each captures the solution’s second-order Taylor term.
Check Your Understanding
Use the definitions and Taylor expansion above to answer these questions.
- For \(y'=f(t,y)\), what expression gives \(y''\) along a solution?
- In the explicit midpoint method, at what time and predicted solution value is the second slope evaluated?
- In Heun’s method, which two slopes are averaged, and how is the predicted endpoint formed?
- Why does an \(O(h^2)\) remainder in a stage slope contribute an \(O(h^3)\) remainder to the solution update?
- For \(y'=y^2\), \(y(0)=1\), \(h=0.1\), calculate the midpoint value and compare it with the Heun value.