📚 Numerical methods for the solution of first order differential equations | 一阶微分方程的数值解法
Many first order differential equations cannot be solved analytically, or their analytic solutions are too complicated to be useful in practice. Numerical methods provide approximate solutions by stepping forward from a known initial condition.
许多一阶微分方程无法解析求解,或者其解析解复杂得难以应用。数值方法通过从已知初值逐步推进,给出近似解。
1. Why do we need numerical methods? | 为什么需要数值方法?
An initial value problem for a first order differential equation can be written as \( \frac{dy}{dx}=f(x,y) \) with \( y(x_0)=y_0 \). Only a limited class of such equations have closed-form solutions.
一阶微分方程的初值问题可以写作 \( \frac{dy}{dx}=f(x,y) \),并满足 \( y(x_0)=y_0 \)。只有有限类这样的方程具有封闭形式的解。
Even when an analytic solution exists, it may involve integrals or special functions that are difficult to evaluate. Numerical methods allow us to compute \( y \) at discrete values of \( x \) using only arithmetic operations.
即使解析解存在,也可能包含难以计算的积分或特殊函数。数值方法仅用算术运算即可在离散的 \( x \) 值处计算 \( y \) 的近似值。
2. The idea of stepping forward | 逐步推进的基本思想
Suppose we know the value \( y_n \) at \( x_n \). To estimate \( y_{n+1} \) at \( x_{n+1}=x_n+h \), we use the slope of the solution. If the step size \( h \) is small, the error in each step can be kept small.
假设已知 \( x_n \) 处的值 \( y_n \)。为了估计 \( x_{n+1}=x_n+h \) 处的 \( y_{n+1} \),我们利用解的斜率。只要步长 \( h \) 足够小,每一步的误差就可以保持很小。
All the methods below follow the same basic pattern: choose a step size \( h \), start from \( (x_0,y_0) \), and repeatedly apply a formula that updates \( y_n \) to \( y_{n+1} \).
下面所有方法都遵循相同的基本模式:选择步长 \( h \),从 \( (x_0,y_0) \) 出发,反复使用某个公式将 \( y_n \) 更新为 \( y_{n+1} \)。
3. Euler’s method | 欧拉法
Euler’s method uses the slope at the current point to predict the next value. The formula is
欧拉法使用当前点的斜率来预测下一个值。公式为
\( y_{n+1} = y_n + h f(x_n, y_n) \)
This is the simplest numerical method for a first order differential equation. It is derived from the Taylor series by keeping only the linear term.
这是求解一阶微分方程最简单的数值方法。它由泰勒展开式仅保留线性项而得到。
-
Example: Solve \( y’ = x + y \) with \( y(0)=1 \) using \( h=0.1 \) on \( 0 \le x \le 0.2 \).
-
示例:用步长 \( h=0.1 \) 在 \( 0 \le x \le 0.2 \) 上求解 \( y’ = x + y \),初值 \( y(0)=1 \)。
At \( x_0=0, y_0=1 \), \( f(0,1)=1 \). Then \( y_1 = 1 + 0.1 \times 1 = 1.1 \) at \( x_1=0.1 \). Next, \( f(0.1,1.1)=1.2 \), so \( y_2 = 1.1 + 0.1 \times 1.2 = 1.22 \) at \( x_2=0.2 \).
在 \( x_0=0, y_0=1 \) 处,\( f(0,1)=1 \)。于是 \( y_1 = 1 + 0.1 \times 1 = 1.1 \),对应 \( x_1=0.1 \)。下一步,\( f(0.1,1.1)=1.2 \),所以 \( x_2=0.2 \) 处 \( y_2 = 1.1 + 0.1 \times 1.2 = 1.22 \)。
4. Error in Euler’s method | 欧拉法的误差
The local truncation error of Euler’s method is proportional to \( h^2 \), while the global error over a fixed interval is proportional to \( h \). This means that halving \( h \) roughly halves the total error.
欧拉法的局部截断误差与 \( h^2 \) 成正比,而在固定区间上的全局误差与 \( h \) 成正比。这意味着将步长减半,总误差大约也减半。
Because the method uses only the first derivative, it is called a first order method. For problems requiring high accuracy, Euler’s method demands very small step sizes, which increases computation time.
由于该方法只使用了导数的一阶项,因此称为一阶方法。对于需要高精度的问题,欧拉法需要非常小的步长,这会增加计算时间。
In AQA examinations, Euler’s method is often tested with a small number of steps. You should show all intermediate values in a table.
在 AQA 考试中,欧拉法通常以少量步长进行考查。你应在表格中展示所有中间值。
5. The midpoint (improved Euler) method | 中点法(改进欧拉法)
The midpoint method estimates the slope at the midpoint of the interval, \( x_n + \frac{h}{2} \). First compute
中点法估计区间中点 \( x_n + \frac{h}{2} \) 处的斜率。先计算
\( k_1 = h f(x_n, y_n) \),
\( k_2 = h f\left(x_n + \frac{h}{2}, y_n + \frac{k_1}{2}\right) \)
Then the step is
然后步进公式为
\( y_{n+1} = y_n + k_2 \)
This method is second order accurate, meaning the global error is proportional to \( h^2 \). It requires two evaluations of \( f \) per step.
这种方法具有二阶精度,即全局误差与 \( h^2 \) 成正比。每一步需要计算两次 \( f \) 的值。
6. The improved Euler method (Heun’s method) | 改进欧拉法(Heun 法)
Heun’s method also uses two slope evaluations, but averages the slopes at the beginning and end of the interval. The formula is
Heun 法同样计算两次斜率,但对区间起点和终点的斜率取平均。公式为
\( k_1 = h f(x_n, y_n) \),
\( k_2 = h f(x_n+h, y_n+k_1) \),
\( y_{n+1} = y_n + \frac{1}{2}(k_1 + k_2) \)
Heun’s method is also second order. For the same step size, it is usually more accurate than Euler’s method, but requires more computation per step.
Heun 法也是二阶方法。在相同步长下,它通常比欧拉法更准确,但每步计算量更大。
Both the midpoint method and Heun’s method are sometimes called “improved Euler methods” in textbooks. In AQA specifications, the term “improved Euler method” usually refers to Heun’s formula above.
中点法和 Heun 法有时在教材中都被称为“改进欧拉法”。在 AQA 考纲中,“改进欧拉法”通常指上述 Heun 公式。
7. Fourth order Runge-Kutta method (RK4) | 四阶龙格-库塔法(RK4)
RK4 is the most widely used numerical method for first order ordinary differential equations. It combines four slope estimates to achieve fourth order accuracy.
RK4 是求解一阶常微分方程最广泛使用的数值方法。它综合了四个斜率估计值,以达到四阶精度。
The standard RK4 step is
标准 RK4 步进公式为
\( k_1 = h f(x_n, y_n) \),
\( k_2 = h f\left(x_n+\frac{h}{2}, y_n+\frac{k_1}{2}\right) \),
\( k_3 = h f\left(x_n+\frac{h}{2}, y_n+\frac{k_2}{2}\right) \),
\( k_4 = h f(x_n+h, y_n+k_3) \),
\( y_{n+1} = y_n + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4) \)
The weighted average gives a very accurate estimate of the change in \( y \). The global error of RK4 is proportional to \( h^4 \), so it converges quickly as \( h \) decreases.
加权平均给出了 \( y \) 增量的非常精确的估计。RK4 的全局误差与 \( h^4 \) 成正比,因此随着 \( h \) 减小,它收敛得很快。
8. Step size and convergence | 步长与收敛性
For any consistent method, as \( h \to 0 \), the numerical solution should approach the exact solution. The order of the method tells us how quickly this happens.
对于任何相容的方法,当 \( h \to 0 \) 时,数值解应当趋近精确解。方法的阶数告诉我们收敛速度的快慢。
| Method | Global error ~ \( h^p \) |
| Euler | \( p = 1 \) |
| Midpoint / Heun | \( p = 2 \) |
| RK4 | \( p = 4 \) |
In practice, if the differential equation has rapidly changing solutions, a smaller step size is needed to capture the behaviour. However, too small an \( h \) can lead to rounding error accumulation in floating-point arithmetic.
在实际中,若微分方程的解变化很快,则需要更小的步长来捕捉其行为。然而,\( h \) 过小可能导致浮点运算中舍入误差的积累。
9. Stability considerations | 稳定性考虑
Euler’s method can become unstable for certain equations unless the step size is sufficiently small. A classic test equation is \( y’ = \lambda y \), where \( \lambda < 0 \).
对于某些方程,除非步长足够小,否则欧拉法可能变得不稳定。经典的测试方程是 \( y’ = \lambda y \),其中 \( \lambda < 0 \)。
For Euler’s method to remain stable, we need \( |1 + \lambda h| < 1 \). For example, if \( \lambda = -10 \), then \( h \) must be less than \( 0.2 \) to avoid oscillatory or growing errors.
为使欧拉法保持稳定,需要 \( |1 + \lambda h| < 1 \)。例如,若 \( \lambda = -10 \),则 \( h \) 必须小于 \( 0.2 \),以避免误差振荡或增大。
Higher order methods, especially implicit ones, have larger stability regions. But explicit RK4 is also more stable than Euler for the same step size.
高阶方法,尤其是隐式方法,具有更大的稳定区域。不过对于相同步长,显式 RK4 也比欧拉法更稳定。
10. Worked example with Euler and Heun | 欧拉法与 Heun 法的算例
Consider \( y’ = 2x – y \), \( y(0) = 1 \), with step \( h = 0.1 \). Compute \( y(0.2) \).
考虑 \( y’ = 2x – y \),\( y(0) = 1 \),取步长 \( h = 0.1 \),计算 \( y(0.2) \)。
Euler: At \( x=0, y=1 \), \( f = 2(0)-1 = -1 \). So \( y(0.1) \approx 1 + 0.1(-1) = 0.9 \). At \( x=0.1, y=0.9 \), \( f = 0.2-0.9 = -0.7 \). So \( y(0.2) \approx 0.9 + 0.1(-0.7) = 0.83 \).
欧拉法:在 \( x=0, y=1 \) 处,\( f = 2(0)-1 = -1 \)。所以 \( y(0.1) \approx 1 + 0.1(-1) = 0.9 \)。在 \( x=0.1, y=0.9 \) 处,\( f = 0.2-0.9 = -0.7 \)。因此 \( y(0.2) \approx 0.9 + 0.1(-0.7) = 0.83 \)。
Heun: First step: \( k_1 = 0.1(2(0)-1) = -0.1 \), predicted \( y = 0.9 \). \( k_2 = 0.1(2(0.1)-0.9) = 0.1(-0.7) = -0.07 \). Then \( y(0.1) \approx 1 + \frac{1}{2}(-0.1-0.07) = 0.915 \).
Heun 法:第一步:\( k_1 = 0.1(2(0)-1) = -0.1 \),预测 \( y = 0.9 \)。\( k_2 = 0.1(2(0.1)-0.9) = 0.1(-0.7) = -0.07 \)。于是 \( y(0.1) \approx 1 + \frac{1}{2}(-0.1-0.07) = 0.915 \)。
Second step: from \( x=0.1, y=0.915 \), \( k_1 = 0.1(0.2-0.915) = -0.0715 \), predicted \( y = 0.8435 \). \( k_2 = 0.1(0.4-0.8435) = 0.1(-0.4435) = -0.04435 \). Then \( y(0.2) \approx 0.915 + \frac{1}{2}(-0.0715-0.04435) = 0.857075 \).
第二步:从 \( x=0.1, y=0.915 \) 出发,\( k_1 = 0.1(0.2-0.915) = -0.0715 \),预测 \( y = 0.8435 \)。\( k_2 = 0.1(0.4-0.8435) = 0.1(-0.4435) = -0.04435 \)。于是 \( y(0.2) \approx 0.915 + \frac{1}{2}(-0.0715-0.04435) = 0.857075 \)。
The exact solution is \( y = 2e^{-x} + 2x – 1 \), giving \( y(0.2) \approx 0.837462 \). Euler’s error is about \( 0.007462 \), while Heun’s error is about \( 0.019613 \). Wait—check carefully! The exact value is \( 2e^{-0.2}+0.4-1 = 2(0.81873075)+0.4-1 = 0.6374615 \). I made an error above. Let us correct it.
精确解为 \( y = 2e^{-x} + 2x – 1 \),所以 \( y(0.2) \approx 0.837462 \)。等等——仔细检查!精确值是 \( 2e^{-0.2}+0.4-1 = 2(0.81873075)+0.4-1 = 0.6374615 \)。我上面出错了,让我们更正。
Correcting: \( 2 \times 0.81873075 = 1.6374615 \), then \( +0.4-1 = 1.0374615 \). So \( y(0.2) \approx 1.0374615 \). Euler gives 0.83, Heun gives 0.857075. Both are underestimates because the slope is decreasing.
更正:\( 2 \times 0.81873075 = 1.6374615 \),再加 \( 0.4-1 = 1.0374615 \)。所以 \( y(0.2) \approx 1.0374615 \)。欧拉法得到 0.83,Heun 法得到 0.857075。两者都偏低,因为斜率在减小。
Indeed, the exact value is \( 1.0374615 \). Euler’s error is \( 1.0374615 – 0.83 = 0.2074615 \). Heun’s error is \( 1.0374615 – 0.857075 = 0.1803865 \). Heun is more accurate.
实际上,精确值为 \( 1.0374615 \)。欧拉法的误差为 \( 1.0374615 – 0.83 = 0.2074615 \)。Heun 法的误差为 \( 1.0374615 – 0.857075 = 0.1803865 \)。Heun 法更准确。
11. Choosing a method | 如何选择方法
For an AQA examination, you may be asked to perform a fixed number of steps using a given method. Always write down the recurrence formula before substituting numbers.
在 AQA 考试中,你可能会被要求用给定方法执行固定步数的计算。在代入数值前,务必写出递推公式。
-
Euler: simple, one evaluation per step, low accuracy.
-
欧拉法:简单,每步一次函数求值,精度低。
-
Heun / midpoint: two evaluations per step, second order accuracy.
-
Heun 法 / 中点法:每步两次函数求值,二阶精度。
-
RK4: four evaluations per step, high accuracy, suitable for small \( h \).
-
RK4:每步四次函数求值,精度高,适合小步长。
If you need a quick estimate, Euler is enough. If you need better accuracy without reducing \( h \) too much, use RK4.
如果只需要粗略估计,欧拉法就够了。如果不想过度减小 \( h \) 而获得更高精度,可使用 RK4。
12. Common pitfalls in exams | 考试中的常见错误
Students often forget that \( f(x,y) \) must be evaluated at the new \( (x,y) \) after each step. Another common mistake is using the wrong step size, especially when the interval is given as \( 0 \le x \le 1 \) with \( n=10 \) steps.
学生经常忘记每一步后必须在新的 \( (x,y) \) 处计算 \( f(x,y) \)。另一个常见错误是使用错误的步长,尤其是当区间给定为 \( 0 \le x \le 1 \) 且 \( n=10 \) 步时。
Always check that the number of steps equals the number of times you apply the formula, not the number of points. For \( n \) steps, you will obtain \( n+1 \) points including the initial one.
始终注意:步数等于公式应用的次数,而不是点的个数。执行 \( n \) 步后,会得到包括初值在内的 \( n+1 \) 个点。
Finally, keep enough decimal places during intermediate calculations. Premature rounding can destroy the accuracy of Heun or RK4 methods.
最后,在中间计算中要保留足够的小数位。过早舍入会破坏 Heun 法或 RK4 法的精度。
Published by TutorHao | 数学 Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导