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: Uniform Circular Motion - python program

  1. Jun 30, 2010 #1
    Hello guys. I am taking an introductory course in computer programming. For one assignment I was to make up a word problem, then write a program to solve it. I wrote a program to calculate the radius of a circular orbit based on the orbiting object's current velocity, and other parameters. Can someone check my math, to see if there are any obvious error?

    Code (Text):

    # Programmer : Mohd Ali
    # Date       : 6/29/2010
    # Description: calculates the radius of an orbit based on the
    #              current velocity that would give a circular orbit
    #              based on the uniform circular motion equation

    G = 6.67300e-11 # acceleration due to gravity

    # the story, makes it easier to print out
    story = ["You and your companions are traveling",
         "happily in your little spaceship. When",
             "suddenly fortune strikes! The person in",
             "charge of keeping track of the periapsis",
             "fell asleep, forgetting to perform the routine",
             "boost burns. Now the spaceship is entering the",
             "atmosphere at orbital velocities.",
             "This is not going to end well...",
             "                                   ",
             "But wait! Why not use the on board",
             "flight computer to calculate the jump",
             "coordinates to jump to a safer altitude?!",
         "                                            ",
         "                                            ",
             "*pilot fires up the onboard flight computer*",
             "                                            ",
             "                                            ",
             "                                            "
    # calculate the force of gravity between two objects r meters apart
    # and weighing m1 and m2 kg respectively

    def getGravForce(m1, m2, r):
        return (G*m1*m2)/(r*r);

    # "entry point"
    def main():
            # print the story
            for i in range(0, len(story)):
            print story[i]

            # get user input
        fPlanetRad = float(raw_input("Enter the major body's radius (m): "))
        fPMass     = float(raw_input("Enter the major body's mass (kg): "))
            fVMass     = float(raw_input("Enter the orbiting body's mass (kg): "))
            fVAlt      = float(raw_input("Enter the orbiting body's altitude (m): "))
            fVel       = float(raw_input("Enter the relative velocity (m/s): "))

            # phrasing the problem as a word problem
        print " "
            print " "
            print "*computer, what altitude should we jump to given that*"
            print "*the planet's mass is " + str(fPMass) + " kg and our mass is*"
            print "* " + str(fVMass) + " kg, our velocity with respect to the*"
            print "*planet's axis of rotation is " + str(fVel) + " m/s and our*"
            print "*altitude with respect to the surface is " + str(fVAlt/1000.0) + " km*"
            print "*with the radius of the planet being " + str(fPlanetRad/1000.0) + "km?*"
        print " "
            print " "
            print "calculating..."

            # some calculations, should be correct. It is very late here :)
            # a = v^2/r
            # a - acceleration
            # v - velocity
            # r - distance

            # r = v^2/a
            # f = ma

            # calculate the spaceship's acceleration with respect to the planet
            # based only on the force of gravity
            f = getGravForce(fPMass, fVMass, fPlanetRad+fVAlt)
            a = f/fVMass

            # calculate the new orbit radius
            r = fVel*fVel/a

            print " "
            print "Force due to gravity       : " + str(f) + " newtons"
            print "Acceleration due to gravity: " + str(a) + " m/s^2"
        print "Radius of new orbit        : " + str(r/1000.0) + " km"
            print " "

            # if rdiff < 0 | we are too energetic, we need to jump to a lower altitude (unlikely, as we are burning)
            rdiff = r-(fVAlt+fPlanetRad)
        if rdiff < 0:
            print "Jump inward " + str(rdiff*-1/1000.0) + " km"
            if rdiff > 0:
                        print "Jump outward " + str(rdiff/1000.0) + " km"
                        print "Your orbit is circular...sorry ;)"
  2. jcsd
  3. Jun 30, 2010 #2

    Filip Larsen

    User Avatar
    Gold Member

    Given that you you want calculate the orbital radius for a circular orbit that has the given (fixed) velocity you should use the force at that same radius and not the force at the "old" radius. Expressed as equations you have the equation for circular motion as [itex] a r = v^2[/itex] and you have the gravitational acceleration at that radius as [itex] a = GM/r^2 [/itex]. Combine these two equations and solve for [itex]r[/itex].

    Nice touch with the story aspect of the solution.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook