# Two Body problem using Verlet Algorithm Python

1. Nov 1, 2011

### Zaknife

1. The problem statement, all variables and given/known data

Hi !

I'm trying to solve numerically two body problem using Verlet algorithm in Python. I wrote a code which looks like that :

Code (Text):

import numpy as np
import scipy as sp
rm=np.array([0.,0.])
r0=np.array([2.,0.])
p0=np.array([0.,0.1])
dt=0.001
m=0.1
G=0.01
M=500.0

def r(dt):
if i == 0:
return r0
else:
return r == np.array([0.,0.])
def force(r):
return -G * M * m * r / np.sqrt(np.mdot(r,r,r))
def potential(r):
return -G * M * m * r / np.sqrt(np.vdot(r,r))
for i in range(1,50) :
r(i*dt+dt)=2*r(dt)-r(i*dt-dt)(force(r)/m)*i*dt**2
print r

My questions are:

1)When i'm trying to compile this code follolwing error occurs:
TypeError: unsupported operand type(s) for *: 'float' and 'function'
2)I'm not sure , if this for loop works correctly, because in the end i'd like to obtain a positions in every dt step. If positions r(dt) is defined correctly ?