VOOZH about

URL: https://www.geeksforgeeks.org/python/solve-differential-equations-with-odeint-function-of-scipy-module-in-python/

โ‡ฑ Solve Differential Equations with ODEINT Function of SciPy module in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Solve Differential Equations with ODEINT Function of SciPy module in Python

Last Updated : 7 Jul, 2025

In science and engineering, many problems involve quantities that change over time like speed of a moving object or temperature of a cooling cup. These changes are often described using differential equations.

SciPy provides a function called odeint (from the scipy.integrate module) that helps solve these equations numerically. By giving it a function that describes how your system changes and some starting values, odeint calculates how the system behaves over time.

Syntax

scipy.integrate.odeint (func, y0, t, args=())

Parameter:

  • func: function that returns the derivative (dy/dt).
  • y0: initial conditions.
  • t: time points to solve the ODE at.
  • args (optional): extra values passed to func.

Solving Differential Equations

Let's solve an ordinary differential equation (ODE) using the odeint() function.

Example 1

Output

๐Ÿ‘ graph_prob1soln
Graph for the solution of ODE

Explanation:

  • Defines and solves the ODE dy/dt = -y * t + 13 using odeint with initial value y = 1.
  • The graph shows how y changes over time.
  • y increases first then slows as -y * t term grows.

Example 2

Output

๐Ÿ‘ graph_prob2soln
Graph for the solution of ODE

Explanation:

  • Defines and solves ODE dy/dt = 13*eแต— + y using odeint starting from y = 1.
  • The graph shows y grows rapidly, driven by both exponential and linear terms.
  • The exponential term accelerates the growth of y as time increases.

Example 3

Output

๐Ÿ‘ graph_prob3soln
Graph for the solution of ODE

Explanation:

  • Defines and solves ODE dy/dt = (1โˆ’y)/(1.95โˆ’y) โˆ’ y/(0.05+y) using odeint with initial values y = 0, 1 and 2.
  • The graph shows how y evolves over time for each initial value.
  • The equation models a system with competing growth and decay rates, influenced by the values of y.

Related Article

Comment
Article Tags:
Article Tags: