import matplotlib.pyplot as plt import numpy as np from scipy.integrate import solve_ivp def f(t, y): """this is the rhs of the ODE to integrate, i.e. dy/dt=f(y,t)""" return -2 * y y0 = [10] # initial value y0=y(t0) t0 = 0 # integration limits for t: start at t=0 tf = 2 # and finish at t=2 t_eval = np.linspace(t0, tf, 50) sol = solve_ivp(fun=f, t_span=[t0, tf], y0=y0, t_eval=t_eval) fig, ax = plt.subplots() ax.plot(sol.t, sol.y[0], "o-") ax.set_xlabel("t") ax.set_ylabel("y(t)") fig.savefig("odeintexample1.pdf")