odeint(deriv_x, xinit, t)
uses xinit as its initial assumption for x . This value for x used when evaluating deriv_x .
deriv_x(xinit, t)
causes a division by zero error, since x[0] = xinit[0] is 0, and deriv_x divides by x[0] .
It looks like you are trying to solve a second order ODE
r'' = - C rhat --------- |r|**2
where rhat is the unit vector in the radial direction.
It seems that you are separating the x and y coordinates into separate second order ODES:
x'' = - C y'' = - C ----- and ----- x**2 y**2
with initial conditions x0 = 0 and y0 = 20056.
This is very problematic. Among the problems is that when x0 = 0 , x'' explodes. The initial second-order ODE for r'' does not have this problem - the denominator does not explode when x0 = 0 , because y0 = 20056 , and therefore r0 = (x**2+y**2)**(1/2) far from zero.
Conclusion: your method of splitting an ODE r'' into two ODEs for x'' and y'' incorrect.
Try to find another way to solve r'' ODE.
Hint:
- What if your state vector
z = [x, y, x', y'] ? - Can you write first-order ODEs for
z' in terms of x , y , x' and y' ? - Can you solve this problem with a single call to
integrate.odeint ?
source share