The code below basically illustrates my problem. It is a test code for a pendulum. I solve it using a method suggested on https://stackoverflow.com/questions/12926393/using-adaptive-step-sizes-with-scipy-integrate-ode). Now I want to plot points at a range of evenly spaced times to show the fact the dynamic nature of the pendulum swings. For example I want to get the solution and plot the corresponding solution state space points at the times
Is there any automatic way Python can do this (using interpolation of the internal solution points which are obtained during the ODE integration)?
Here is the main code:
import numpy as np from scipy.integrate import ode import matplotlib.pyplot as plt import warnings def f(t,y): l = 1 m = 1 d = 1 g = 9.8 return [y, -np.sin(y)*g/l-y*d/m] y0, t0 = [np.pi/2, 0], 0 t1 = 500 backend = 'vode' solver = ode(f).set_integrator(backend, nsteps=1) solver.set_initial_value(y0, t0) # suppress Fortran-printed warning solver._integrator.iwork = -1 y, t = ,  warnings.filterwarnings("ignore", category=UserWarning) while solver.t < t1: solver.integrate(t1, step=True) y.append(solver.y) t.append(solver.t) warnings.resetwarnings() y = np.array(y) t = np.array(t) plt.plot(y[:,0], y[:,1], 'b-') plt.plot(y[0::5,0], y[0::5,1], 'b.') plt.show()