I have the coupled ODE, but when i run this code i get this error: TypeError: 'float' object is not subscriptable
The error occurs on the line^ return array([-si*p[0], Here is my code:
from scipy.integrate import ode
import matplotlib.pyplot as plt
import warnings
si = 1/25 #0.053
fi = 1/23 #0.05
def deriv(p,t):
return array([-si* p[0],
si * p[0] - fi * p[1],
fi * p[1] - fi * p[2],
fi * p[2] - fi * p[3],
fi * p[3] - fi * p[4],
fi * p[4] - fi * p[5],
fi * p[5] - si * p[6],
si * p[6]])
backend = 'dopri5'
t0 = 0
t1 = 2000.0
p_init = array([1, 0, 0, 0, 0, 0, 0, 0])
r = .01
solver = ode(deriv).set_integrator(backend, nsteps=1)
solver.set_initial_value(p_init, t0).set_f_params(r)
solver._integrator.iwork[2] = -1
sol = []
warnings.filterwarnings("ignore", category=UserWarning)
while solver.t < t1:
solver.integrate(t1, step=True)
sol.append([solver.t, solver.p])
warnings.resetwarnings()
sol = array(sol)
plt.plot(sol[:,0], sol[:,1], 'b.-')
plt.show()
Where is the mistake?