1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Two Body problem using Verlet Algorithm Python

  1. Nov 1, 2011 #1
    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

    def r(dt):
        if i == 0:
            return r0
            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) :
        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: Nov 1, 2011
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted