Uniform Circular Motion - python program

Click For Summary
SUMMARY

The discussion centers on a Python program created by Mohd Ali to calculate the radius of a circular orbit based on the object's velocity and other parameters. The program utilizes the gravitational force formula and the principles of uniform circular motion to derive the new orbital radius. Key equations include the gravitational force equation \( F = \frac{G \cdot m_1 \cdot m_2}{r^2} \) and the circular motion equation \( a = \frac{v^2}{r} \). The program effectively combines these equations to provide actionable outputs for orbital adjustments.

PREREQUISITES
  • Understanding of Python programming (version 2.x)
  • Knowledge of gravitational force calculations
  • Familiarity with the principles of uniform circular motion
  • Basic algebra for solving equations
NEXT STEPS
  • Explore Python's scientific libraries, such as NumPy, for advanced calculations.
  • Learn about orbital mechanics and Kepler's laws for deeper insights into orbits.
  • Study the implementation of Python 3.x for modern programming practices.
  • Investigate simulation tools for visualizing orbital dynamics.
USEFUL FOR

Students in introductory programming courses, educators teaching physics concepts, and anyone interested in applying programming to solve real-world physics problems related to orbital mechanics.

computerex
Messages
68
Reaction score
0
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:
# 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"
	else:
		if rdiff > 0:
                	print "Jump outward " + str(rdiff/1000.0) + " km"
        	else: 
                	print "Your orbit is circular...sorry ;)"
        
main()
 
Technology news on Phys.org
computerex said:
Code:
        f = getGravForce(fPMass, fVMass, fPlanetRad+fVAlt)
        a = f/fVMass
        r = fVel*fVel/a

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 a r = v^2 and you have the gravitational acceleration at that radius as a = GM/r^2. Combine these two equations and solve for r.

Nice touch with the story aspect of the solution.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
17K
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 10 ·
Replies
10
Views
11K
  • · Replies 2 ·
Replies
2
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K