Numerical Methods for Differential Equations
Numerical Methods of DE
Standard Integration »
Power Series »
First Order »
Statistics and Probability »
Differential Equation Calculus
Solve $\frac{dy}{dx} = f(x,y)$
Why Use Numerical Methods for DEs?
Differential equations (DEs) are fundamental in describing dynamic systems in science and engineering. While some DEs can be solved analytically to find an exact symbolic solution $y(x)$, many real-world problems lead to DEs that are too complex for such solutions.
Reasons for using numerical methods:
- No Analytical Solution: Many DEs, especially non-linear ones or those with complicated coefficient functions, do not have known analytical solutions.
- Complex Functions: Even if an analytical solution exists, it might involve integrals that are themselves difficult or impossible to evaluate symbolically.
- Approximation Suffices: In many practical scenarios, an approximate numerical solution with a controlled degree of accuracy is sufficient for analysis and design.
- Computational Power: Modern computers can perform the iterative calculations required by numerical methods quickly and efficiently.
Numerical methods provide a way to approximate the solution of a DE at discrete points, starting from an initial condition and stepping forward.
Euler's Method
Euler's method is the simplest numerical method for solving first-order ordinary differential equations of the form $\frac{dy}{dx} = f(x,y)$ with an initial condition $y(x_0) = y_0$.
It uses the tangent line at the current point to approximate the value of $y$ at the next point. Given a step size $h$, the iterative formula is:
$$ y_{i+1} = y_i + h \cdot f(x_i, y_i) $$ Where:- $x_{i+1} = x_i + h$
- $y_i$ is the approximate value of $y$ at $x_i$.
- $y_{i+1}$ is the approximate value of $y$ at $x_{i+1}$.
Euler's method is a first-order method, meaning its local error is proportional to $h^2$ and its global error is proportional to $h$. It's generally not very accurate unless a very small step size $h$ is used.
Euler-Cauchy Method (Improved Euler or Heun's Method)
The Euler-Cauchy method, also known as Heun's method or the Improved Euler method, is a more accurate predictor-corrector method. It aims to improve upon Euler's method by using an average of slopes.
The steps for each iteration are:
- Predictor Step: Estimate $y_{i+1}^*$ using Euler's method: $$ y_{i+1}^* = y_i + h \cdot f(x_i, y_i) $$
- Corrector Step: Refine the estimate using the average of the slope at $(x_i, y_i)$ and the slope at the predicted point $(x_{i+1}, y_{i+1}^*)$: $$ y_{i+1} = y_i + \frac{h}{2} \left[ f(x_i, y_i) + f(x_{i+1}, y_{i+1}^*) \right] $$
The Euler-Cauchy method is a second-order method, with local error proportional to $h^3$ and global error proportional to $h^2$, making it generally more accurate than Euler's method for the same step size.
Runge-Kutta Method (RK4)
The classical fourth-order Runge-Kutta method (RK4) is a widely used and highly accurate numerical method. It achieves better accuracy by evaluating the slope $f(x,y)$ at several points within each step.
For each step from $(x_i, y_i)$ to $(x_{i+1}, y_{i+1})$ with step size $h$:
- Calculate $k_1$: $$ k_1 = h \cdot f(x_i, y_i) $$
- Calculate $k_2$: $$ k_2 = h \cdot f\left(x_i + \frac{h}{2}, y_i + \frac{k_1}{2}\right) $$
- Calculate $k_3$: $$ k_3 = h \cdot f\left(x_i + \frac{h}{2}, y_i + \frac{k_2}{2}\right) $$
- Calculate $k_4$: $$ k_4 = h \cdot f(x_i + h, y_i + k_3) $$
- Calculate $y_{i+1}$: $$ y_{i+1} = y_i + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4) $$
The RK4 method is a fourth-order method, meaning its local error is proportional to $h^5$ and its global error is proportional to $h^4$. This provides significantly better accuracy than Euler or Euler-Cauchy methods for a given step size.