Home > Python > Ordinary Differential Equation-2

Ch. 13.1 1st Order ODE (RK2 Method)

Chapters Index
Program 1

1st Order ODE (RK2 Method)

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

An object in free fall under the influence of gravity, with constant acceleration: \(a = 9.81 \, \text{m/s}^2\)

$$ \frac{dv}{dt}=a ;\quad v(t=0)=0 $$

The following code implements the Runge-Kutta 2nd order (RK2) method to calculate the velocity of the object over a time period.

Theoretical Background & Computational Mechanics

RK2 Method

In general, the RK2 method for solving an ODE of the form \( \frac{dy}{dt} = f(t, y) \) over a time interval \([t_0, t_{\text{end}}]\) with initial condition \( y(t_0) = y_0 \) is implemented as follows:

  1. Compute \( k_1 \), an estimate of the slope at the beginning of the interval: \[ k_1 = f(t, y) \]
  2. Compute \( k_2 \), an estimate of the slope at the end of the interval using \( k_1 \): \[ k_2 = f\left(t + h, y + h \cdot k_1\right) \]
  3. Update the value of \( y \) for the next step \( y_{\text{next}} \) by averaging these slopes: \[ y_{\text{next}} = y + \frac{h}{2} \cdot (k_1 + k_2) \]
Theoretical Principles & Computational Physics Guide

1st Order ODE (RK2 Method): Differential Equations & Dynamical Simulation

Dr. Alorika Chatterjee & Dr. Anirban Shaw Science & Physics Learners Python 3 / NumPy / SciPy

1. Core Principles & Theoretical Framework

Dynamical Evolution: Solves differential equations governing kinematics, planetary orbits, electrical circuits, and wave propagation.
Step-by-Step Stepping: Advances continuous state vectors forward in discrete time intervals $\Delta t$ using slope estimates.
Conservation Laws: Evaluates preservation of physical invariants (total energy, angular momentum) across long integration horizons.

2. Mathematical Formulation & Algorithmic Pipeline

Vector initial value problem and numerical state advancement:

$$ \frac{d\mathbf{y}}{dt} = \mathbf{f}(t, \mathbf{y}), \quad \mathbf{y}(t_0) = \mathbf{y}_0 \implies \mathbf{y}_{n+1} = \mathbf{y}_n + \Delta t \cdot \mathbf{\Phi}(t_n, \mathbf{y}_n, \Delta t) $$

3. Numerical Mechanics & Implementation Logic

  • Coupled Reduction: Convert $n$-th order ODEs into systems of $n$ coupled first-order equations.
  • Intermediate Slopes: Compute weighted intermediate derivatives ($k_1, k_2, k_3, k_4$ in RK4).
  • State Update: Advance state variables simultaneously and verify energy/phase invariants.

4. Relevant Computational Practice Exercises

Exercise 1
Solve the differential equation for 1st Order ODE (RK2 Method) over 1000 time steps and plot state coordinates vs time.
Exercise 2
Compare numerical solution stability for small vs large step sizes $h = \Delta t$.
Exercise 3
Plot phase space trajectory demonstrating physical stability or damping attractors.
Standard Literature & References:
  • John R. Taylor, "Classical Mechanics", University Science Books (2005).
  • Mark Newman, "Computational Physics", University of Michigan (2013).