Numerical solutions
Direction fields, Euler's method and Heun's improved Euler method.
This page approximates solutions when no closed-form method applies, the last step of the method-selection workflow. The methods in first-order methods and second-order constant-coefficient equations can fail even for an equation that is easy to state and sometimes the derivative is known only from a calculation or a measurement.
A direction field gives a qualitative picture. Euler's and Heun's methods turn local slope information into a sequence of approximations.
Direction fields
Direction field
For
the direction field assigns a short line segment of slope to each point on a grid. A solution curve follows these local directions and an initial condition selects the curve passing through the prescribed point.
The field gives qualitative information before any numerical calculation. It can show increasing and decreasing regions, equilibrium levels and the way nearby solution curves behave.
A family of translated curves
For
every point with the same -coordinate has the same slope. Integrating gives
The curves through and are vertical translates of one another. The direction field displays this common slope pattern even though the initial condition chooses only one curve.
[routine]
- [1]:Direction field
A direction field is most useful when no formula is available. No general elementary procedure in first-order methods applies to , for instance, although is a particular solution.
Euler's method
Euler's method
For the IVP
choose a step size and define
The update uses the tangent line at the left endpoint of each step.
The formula uses the current slope over one short step: the tangent line through has value at . This is the degree-one Taylor model at the current point and Taylor's theorem describes the remainder omitted by one such step.
For an exact starting value , the fundamental theorem of calculus gives
Euler replaces the changing slope inside this integral by . If on the step, then , so this local error is at most .
In an actual computation is already approximate, so errors also propagate from previous steps. If the slope field changes at most proportionally with (the Lipschitz condition) and the solution is smooth on a fixed interval, standard stability estimates bound the largest accumulated error by a constant times as tends to zero. Thus, for a sufficiently small step size and a fixed interval, halving roughly halves Euler's global error. This numerical stability concerns error propagation in the method, not whether solutions of the ODE grow or decay.
- [1]:A visibly large step
- [2]:A smaller step
- [3]:Heun's method
A visibly large step
For
the first point is . Since , the next point is . The following slopes are and , giving
The exact solution is , whose value at is . The step size is too large to track the curvature accurately.
[routine]
- [1]:Euler's method
A smaller step
For
Euler's update gives
The exact solution is
whose value at is approximately . The Euler value is below it by about .
[routine]
- [1]:Euler's method
Improved Euler method
Euler drifts when the slope changes across a step. Heun's method corrects this by averaging the slopes at both ends of the step. It costs two evaluations of per step but attains higher order, so prefer it when is smooth and evaluations are cheap; keep Euler when a coarse qualitative trace of the direction field suffices.
Heun's method
Starting from , first predict the next value with Euler:
Then correct using the average of the slope at the current point and the predicted endpoint:
Where Euler uses only the left-endpoint slope, Heun's method applies the trapezoidal rule to
but the endpoint value is unknown, so the Euler prediction supplies it. Using both slopes makes Heun more accurate at the same step size.
When and the exact solution are sufficiently smooth and the usual Lipschitz and error-stability conditions hold on a fixed interval, Euler has local error and global error , whereas Heun has local error and global error . Thus halving roughly quarters Heun's global error (until round-off or other errors dominate).
Comparing Euler and Heun
Consider
whose exact solution is
With , . Euler predicts ; the predicted endpoint slope is . Heun therefore gives , closer to the exact value than Euler's . Repeating the updates on gives these maximum grid-point errors:
Reducing lowers the error for both methods and Heun keeps the smaller error.
[exam]
- [1]:Heun's method
To implement either method on with equal intervals, use
and store the successive approximations .
The methods also cover second-order problems, even though the formulas above begin with . For , set : the pair satisfies and each numerical update is applied to both components. The same componentwise formulas apply to any first-order vector system.