.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "intro/scipy/auto_examples/plot_solve_ivp_simple.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_intro_scipy_auto_examples_plot_solve_ivp_simple.py>` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_scipy_auto_examples_plot_solve_ivp_simple.py: ========================= Integrating a simple ODE ========================= Solve the ODE dy/dt = -2y between t = 0..4, with the initial condition y(t=0) = 1. .. GENERATED FROM PYTHON SOURCE LINES 9-33 .. image-sg:: /intro/scipy/auto_examples/images/sphx_glr_plot_solve_ivp_simple_001.png :alt: Solution of Initial Value Problem :srcset: /intro/scipy/auto_examples/images/sphx_glr_plot_solve_ivp_simple_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import scipy as sp import matplotlib.pyplot as plt def f(t, y): return -2 * y t_span = (0, 4) # time interval t_eval = np.linspace(*t_span) # times at which to evaluate `y` y0 = [ 1, ] # initial state res = sp.integrate.solve_ivp(f, t_span=t_span, y0=y0, t_eval=t_eval) plt.figure(figsize=(4, 3)) plt.plot(res.t, res.y[0]) plt.xlabel("t") plt.ylabel("y") plt.title("Solution of Initial Value Problem") plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.073 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_solve_ivp_simple.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_solve_ivp_simple.ipynb <plot_solve_ivp_simple.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_solve_ivp_simple.py <plot_solve_ivp_simple.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_solve_ivp_simple.zip <plot_solve_ivp_simple.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_