.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_scipy_auto_examples_plot_odeint_simple.py: ========================= Integrating a simple ODE ========================= Solve the ODE dy/dt = -2y between t = 0..4, with the initial condition y(t=0) = 1. .. image:: /intro/scipy/auto_examples/images/sphx_glr_plot_odeint_simple_001.png :class: sphx-glr-single-img .. code-block:: python import numpy as np from scipy.integrate import odeint from matplotlib import pyplot as plt def calc_derivative(ypos, time): return -2*ypos time_vec = np.linspace(0, 4, 40) yvec = odeint(calc_derivative, 1, time_vec) plt.figure(figsize=(4, 3)) plt.plot(time_vec, yvec) plt.xlabel('t: Time') plt.ylabel('y: Position') plt.tight_layout() **Total running time of the script:** ( 0 minutes 0.034 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_odeint_simple.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_odeint_simple.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_odeint_simple.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_