Last modified: June 14, 2023
This article is written in: 🇺🇸
Heun's Method
Heun's method is an improved version of Euler's method that enhances accuracy by using an average of the slope at the beginning and the predicted slope at the end of the interval.
Mathematical Formulation
Assuming a first order differential equation:
dudt=f(t,u),
given u(t0)=u0 and a step size h, Heun's method predicts the solution at time (t0+h) as follows:
- Euler's step (predictor step): Predict the value at t=t0+h using Euler's method:
˜un+1=un+hf(tn,un),
- Heun's step (corrector step): Correct this prediction by taking an average of the slopes at the beginning and end of the interval:
un+1=un+h2[f(tn,un)+f(tn+h,˜un+1)].
This process is repeated for each point in the desired interval.
Derivation
The second-order Taylor series expansion around t is given by:
u(t+h)=u(t)+hu′(t)+12(h)2u″
where we approximate u''(t) by the first difference of u'(t):
u''(t) \approx \frac{u'(t+h) - u'(t)}{h} = \frac{f(t + h, u(t + h)) - f(t, u(t))}{h}.
Substituting this approximation into the Taylor series, we get:
u(t + h) = u(t) + h u'(t) + \frac{1}{2}(h)^2 \frac{f(t + h, u(t + h)) - f(t, u(t))}{h} + O(h^3),
and approximating u(t + h) by removing the higher order term yields Heun's method:
u(t + h) \approx u(t) + \frac{h}{2} [f(t, u(t)) + f(t + h, \tilde{u}_{n+1})].
Algorithm Steps
- Begin with initial conditions u_0 and t_0.
- Compute \tilde{u}_{n+1} using the predictor step.
- Calculate u_{n+1} using the corrector step.
- Repeat steps 2-3 for all points in the desired interval.
Example
Consider the differential equation
u'(t) = u(t),
with the initial condition u(0) = 1. We want to estimate the value of u at t = 0.1 using Heun's method with a step size of h = 0.05.
- We start at t = 0 with u(0) = 1.
First, we calculate the Euler's step (predictor):
\tilde{u} = u(0) + h \cdot f(t, u(0)) = 1 + 0.05 \cdot 1 = 1.05.
Then, we correct this estimation:
u(0.05) \approx u(0) + \frac{h}{2} [f(t, u(0)) + f(t + h, \tilde{u}_{n+1})] = 1 + \frac{0.05}{2} [1 + 1.05] = 1.05125.
- Now, we have u(0.05), we move on to t = 0.1.
Similarly, we calculate the Euler's step:
\tilde{u} = u(0.05) + h \cdot f(t, u(0.05)) = 1.05125 + 0.05 \cdot 1.05125 = 1.1025625.
Then, we correct this estimation:
u(0.1) \approx u(0.05) + \frac{h}{2} [f(t, u(0.05)) + f(t + h, \tilde{u}_{n+1})] = 1.05125 + \frac{0.05}{2} [1.05125 + 1.1025625] = 1.105158203125.
So, the approximate solution to u(0.1) with Heun's method is 1.105158203125.
Advantages
- Heun's method is simple to implement and easy to understand, making it accessible for introductory numerical analysis.
- It often provides a more accurate approximation than Euler's method by incorporating a correction step based on the trapezoidal rule.
- The method offers a good balance between computational simplicity and improved accuracy for many non-stiff problems.
Limitations
- While more accurate than Euler’s method, Heun's method can still introduce significant errors when using large step sizes or dealing with highly nonlinear functions.
- Like other explicit methods, it is not well-suited for stiff systems, where implicit methods are typically more effective.
- The need to evaluate f(t, u) at multiple points in each step increases the computational effort compared to simpler methods like Euler’s.
- The accuracy of Heun’s method is still limited for complex dynamics, requiring smaller step sizes to achieve desired precision, which may increase computational cost.