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!

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
    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 ?


    Thanks in advance !
     
    Last edited: Nov 1, 2011
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

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



Similar Discussions: Two Body problem using Verlet Algorithm Python
  1. Python: print problem (Replies: 2)

Loading...