Numerical Solutions to Differential Equations

Differential equations model dynamic systems, from planetary orbits to disease spread. Ordinary differential equations (ODEs) of the form \( \frac{dy}{dt} = f(t, y) \) with initial condition \( y(t_0) = y_0 \) often lack closed-form solutions, especially for nonlinear cases. Numerical methods approximate solutions by discretizing time into steps, balancing accuracy and computational efficiency.

This MathMultiverse guide explores key methods like Euler’s Method and Runge-Kutta, with detailed examples, interactive graphs, and applications in physics, engineering, and biology. We’ll analyze accuracy, stability, and trade-offs, making complex concepts accessible.

Euler’s Method

Euler’s Method approximates ODE solutions using tangent lines. For \( \frac{dy}{dt} = f(t, y) \), with \( y(t_0) = y_0 \):

\[ y_{n+1} = y_n + h f(t_n, y_n) \] \[ t_{n+1} = t_n + h \]

Here, \( h \) is the step size. Derived from the Taylor series, it truncates higher-order terms, yielding a local error of \( O(h^2) \) and global error of \( O(h) \). It’s simple but less accurate for stiff or nonlinear ODEs.

Stability depends on \( h \). For \( \frac{dy}{dt} = -\lambda y \), stability requires \( h < \frac{2}{\lambda} \).

Examples

Let’s apply Euler’s Method and compare with exact solutions.

Example 1: \( \frac{dy}{dt} = -y \), \( y(0) = 1 \)

Exact: \( y = e^{-t} \). Use \( h = 0.1 \), \( t = 0 \) to 0.3:

\[ y_0 = 1, \quad t_0 = 0 \] \[ y_1 = 1 + 0.1 (-1) = 0.9, \quad t_1 = 0.1 \] \[ y_2 = 0.9 + 0.1 (-0.9) = 0.81, \quad t_2 = 0.2 \] \[ y_3 = 0.81 + 0.1 (-0.81) = 0.729, \quad t_3 = 0.3 \]

Exact: \( y(0.3) = e^{-0.3} \approx 0.7408 \). Error: \( 0.0118 \).

Euler’s Method vs. exact for \( y' = -y \).

Example 2: \( \frac{dy}{dt} = t - y \), \( y(0) = 1 \)

Exact: \( y = t - 1 + 2e^{-t} \). \( h = 0.2 \), to \( t = 0.4 \):

\[ y_0 = 1, \quad t_0 = 0 \] \[ y_1 = 1 + 0.2 (0 - 1) = 0.8, \quad t_1 = 0.2 \] \[ y_2 = 0.8 + 0.2 (0.2 - 0.8) = 0.68, \quad t_2 = 0.4 \]

Exact: \( y(0.4) \approx 0.7103 \). Error: \( 0.0303 \).

Example 3: \( \frac{dy}{dt} = y^2 \), \( y(0) = 1 \)

Exact: \( y = \frac{1}{1 - t} \). \( h = 0.1 \), to \( t = 0.3 \):

\[ y_1 = 1 + 0.1 (1^2) = 1.1 \] \[ y_2 = 1.1 + 0.1 (1.1^2) = 1.21 \] \[ y_3 = 1.21 + 0.1 (1.21^2) \approx 1.3641 \]

Exact: \( y(0.3) \approx 1.4286 \). Error: \( 0.0645 \).

Advanced Methods

More accurate methods improve on Euler’s limitations.

Runge-Kutta 2 (RK2)

Midpoint method:

\[ k_1 = h f(t_n, y_n) \] \[ k_2 = h f\left(t_n + \frac{h}{2}, y_n + \frac{k_1}{2}\right) \] \[ y_{n+1} = y_n + k_2 \]

For \( \frac{dy}{dt} = -y \), \( h = 0.1 \), \( y_0 = 1 \):

\[ k_1 = 0.1 (-1) = -0.1 \] \[ k_2 = 0.1 [-(1 - 0.05)] = -0.095 \] \[ y_1 = 1 - 0.095 = 0.905 \]

Exact: \( e^{-0.1} \approx 0.9048 \). Error: \( 0.0002 \).

Runge-Kutta 4 (RK4)

Fourth-order method:

\[ k_1 = h f(t_n, y_n) \] \[ k_2 = h f\left(t_n + \frac{h}{2}, y_n + \frac{k_1}{2}\right) \] \[ k_3 = h f\left(t_n + \frac{h}{2}, y_n + \frac{k_2}{2}\right) \] \[ k_4 = h f(t_n + h, y_n + k_3) \] \[ y_{n+1} = y_n + \frac{1}{6} (k_1 + 2 k_2 + 2 k_3 + k_4) \]

Error: \( O(h^4) \), ideal for smooth ODEs.

Implicit Methods

For stiff ODEs, implicit Euler:

\[ y_{n+1} = y_n + h f(t_{n+1}, y_{n+1}) \]

Requires solving algebraic equations but ensures stability.

Applications

Numerical methods solve real-world ODEs.

  • Physics - Projectile Motion: \( \frac{d^2y}{dt^2} = -g \). RK4 approximates trajectory accounting for air resistance.
  • Engineering - Circuit Analysis: \( \frac{dI}{dt} = \frac{V - IR}{L} \). Euler’s Method models current changes.
  • Biology - Population Dynamics: \( \frac{dP}{dt} = rP(1 - \frac{P}{K}) \). RK4 tracks logistic growth.