.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/mechanical_engineering/vibration/plot_01_rayleigh_free_vibration.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_mechanical_engineering_vibration_plot_01_rayleigh_free_vibration.py: Rayleigh's *Theory of Sound*: free vibration (1877) =================================================== Lord Rayleigh's *The Theory of Sound* (1877) treated every vibrating system, from strings to bells, as a set of linear oscillators. The simplest is a mass on a spring with a dashpot, :math:`m\ddot x + c\dot x + kx = 0`. It rings at :math:`\omega_n = \sqrt{k/m}` (:func:`~engineeringkit.mechanical_engineering.natural_frequency`), and damping lowers the frequency to :math:`\omega_n\sqrt{1 - \zeta^2}` (:func:`~engineeringkit.mechanical_engineering.damped_frequency`, :func:`~engineeringkit.mechanical_engineering.damping_ratio`). Rayleigh also showed how to estimate a frequency from energy alone: equate the peak kinetic and potential energies for an assumed shape. With a linear stretch profile, a spring's own mass :math:`m_s` adds :math:`m_s/3` to the moving mass. The example checks the simulated response (:func:`~engineeringkit.mechanical_engineering.simulate_sdof`) and Rayleigh's correction against the exact solution. .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from scipy.optimize import brentq from engineeringkit.mechanical_engineering import damped_frequency, damping_ratio, natural_frequency, natural_frequency_hz, simulate_sdof .. GENERATED FROM PYTHON SOURCE LINES 29-34 Free decay ---------- Release a 2 kg mass on an 800 N/m spring from 10 mm. Time the peaks of the simulated response and compare with the damped frequency. .. GENERATED FROM PYTHON SOURCE LINES 34-51 .. code-block:: Python m, k = 2.0, 800.0 t = np.linspace(0, 2, 40001) fig, axes = plt.subplots(1, 2, figsize=(10, 3.8)) for c in (0.0, 4.0, 16.0): result = simulate_sdof(m, c, k, x0=0.01, t=t) x = result.displacement peaks = np.flatnonzero((x[1:-1] > x[:-2]) & (x[1:-1] > x[2:])) + 1 period = np.mean(np.diff(t[peaks])) zeta = damping_ratio(c, k, m) print(f"zeta = {zeta:.3f}: measured {2 * np.pi / period:.4f} rad/s, omega_d = {damped_frequency(k, m, c):.4f} rad/s") assert np.isclose(2 * np.pi / period, damped_frequency(k, m, c), rtol=1e-4) axes[0].plot(t, 1e3 * x, label=f"zeta = {zeta:.2f}") print(f"undamped: {natural_frequency(k, m):.1f} rad/s = {natural_frequency_hz(k, m):.3f} Hz") axes[0].set(xlabel="time [s]", ylabel="displacement [mm]", title="Free decay") axes[0].legend() .. image-sg:: /api/gallery/mechanical_engineering/vibration/images/sphx_glr_plot_01_rayleigh_free_vibration_001.png :alt: Free decay :srcset: /api/gallery/mechanical_engineering/vibration/images/sphx_glr_plot_01_rayleigh_free_vibration_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none zeta = 0.000: measured 20.0000 rad/s, omega_d = 20.0000 rad/s zeta = 0.050: measured 19.9752 rad/s, omega_d = 19.9750 rad/s zeta = 0.200: measured 19.5964 rad/s, omega_d = 19.5959 rad/s undamped: 20.0 rad/s = 3.183 Hz .. GENERATED FROM PYTHON SOURCE LINES 52-59 Rayleigh's correction for the spring's mass ------------------------------------------- A uniform spring fixed at one end and carrying the mass at the other has the exact fundamental :math:`\omega = \beta\sqrt{k/m_s}` with :math:`\beta\tan\beta = m_s/m`. Rayleigh's energy estimate is :math:`\sqrt{k/(m + m_s/3)}`. .. GENERATED FROM PYTHON SOURCE LINES 59-75 .. code-block:: Python ratios = np.linspace(0.01, 2, 100) exact = np.array([brentq(lambda b, s=s: b * np.tan(b) - s, 1e-9, np.pi / 2 - 1e-9) * np.sqrt(k / (s * m)) for s in ratios]) rayleigh = natural_frequency(k, m * (1 + ratios / 3)) naive = natural_frequency(k, m) * np.ones_like(ratios) error = rayleigh / exact - 1 equal = np.argmin(abs(ratios - 1)) print(f"spring as heavy as the mass: exact {exact[equal]:.3f}, Rayleigh {rayleigh[equal]:.3f} rad/s") assert np.all(error >= 0) and np.max(error[ratios <= 1]) < 0.01 axes[1].plot(ratios, 100 * error, label="Rayleigh, m + m_s/3") axes[1].plot(ratios, 100 * (naive / exact - 1), label="spring mass ignored") axes[1].set(xlabel="spring mass / end mass", ylabel="frequency error [%]", title="Rayleigh's energy estimate") axes[1].legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none spring as heavy as the mass: exact 17.218, Rayleigh 17.331 rad/s .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.127 seconds) .. _sphx_glr_download_api_gallery_mechanical_engineering_vibration_plot_01_rayleigh_free_vibration.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/mechanical_engineering/vibration/plot_01_rayleigh_free_vibration.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_rayleigh_free_vibration.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_rayleigh_free_vibration.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_rayleigh_free_vibration.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_