- #1
Zaknife
- 12
- 0
Homework Statement
Hi !
I'm trying to solve numerically two body problem using Verlet algorithm in Python. I wrote a code which looks like that :
Code:
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.0def 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 ?
Thanks in advance !
Last edited: