.. 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_damped_spring_mass.py: ============================================ Integrate the Damped spring-mass oscillator ============================================ .. image:: /intro/scipy/auto_examples/images/sphx_glr_plot_odeint_damped_spring_mass_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 mass = 0.5 # kg kspring = 4 # N/m cviscous = 0.4 # N s/m eps = cviscous / (2 * mass * np.sqrt(kspring/mass)) omega = np.sqrt(kspring / mass) def calc_deri(yvec, time, eps, omega): return (yvec[1], -eps * omega * yvec[1] - omega **2 * yvec[0]) time_vec = np.linspace(0, 10, 100) yinit = (1, 0) yarr = odeint(calc_deri, yinit, time_vec, args=(eps, omega)) plt.figure(figsize=(4, 3)) plt.plot(time_vec, yarr[:, 0], label='y') plt.plot(time_vec, yarr[:, 1], label="y'") plt.legend(loc='best') plt.show() **Total running time of the script:** ( 0 minutes 0.015 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_odeint_damped_spring_mass.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_odeint_damped_spring_mass.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_odeint_damped_spring_mass.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_