Home > Python > Ordinary Differential Equation-2

Ch. 13.5 Solve ODE using scipy.integrate.odeint()

Chapters Index
Program 1

Solve ODE using scipy.integrate.odeint()

Python 3.11 Ready

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

Mathematical Problem Formulation

The differential equation is: $$ \frac{dx}{dt} = -k \cdot x $$ $$ x(t = 0) = 10 $$

Program 2

Solve ODE using scipy.integrate.odeint()

Python 3.11 Ready

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

Mathematical Problem Formulation

The ordinary differential equation (ODE) given by:

\[ \frac{dx}{dt} = -k \cdot x, \] where \( x(t) \) is a function of time \( t \) and \( k \) is a positive constant. Consider three different values of \( k \): \( k = 0.5, 1, 2.5 \) over the time interval \( t = [0, 10] \) with the initial condition \( x(0) = 10.0 \).
Program 3

Solve ODE using scipy.integrate.odeint()

Python 3.11 Ready

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

Mathematical Problem Formulation

The differential equation is: $$ \frac{d^2x}{dt^2} + \lambda \frac{dx}{dt} + kx = 0 $$ $$ x_{t=0} = 0 \quad \text{and} \quad \left. \frac{dx}{dt} \right|_{t=0} = 0.7$$

Theoretical Principles & Computational Physics Guide

Solve ODE using scipy.integrate.odeint(): 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 Solve ODE using scipy.integrate.odeint() 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).