import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def f(y,t,A): return -A*y A = 0.3 # The A constant in the ODE t0 = 0. # Starting time tend = 10. # End time nt = 10 # Nr of time steps t = np.linspace(t0,tend,nt) y0 = 2. # Intial condition sol = odeint(f,y0,t,args=(A,)) y = sol[:,0].T yana = y[0]*np.exp(-A*t) plt.figure() plt.plot(t,yana,label='Analytic') plt.plot(t,y,'o',label='Scipy odeint') plt.xlabel('t') plt.ylabel('y(t)') plt.legend() plt.savefig('fig_ode_scipy_1_1.pdf') plt.show()