Uniform Circular Motion - python program

In summary, the conversation discusses a programming assignment where the individual created a program to calculate the radius of a circular orbit based on an object's current velocity and other parameters. They ask for someone to check their math and provide a story to make the problem more interesting. The program calculates the acceleration and new orbit radius using the force of gravity and the relative velocity.
  • #1
computerex
68
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
  • #2
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 [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.
 

Related to Uniform Circular Motion - python program

1. What is Uniform Circular Motion?

Uniform Circular Motion is a type of motion in which an object moves along a circular path at a constant speed. This motion is characterized by the object's velocity remaining constant in both magnitude and direction throughout the circular path.

2. How can I create a python program to simulate Uniform Circular Motion?

To create a python program for Uniform Circular Motion, you can use the built-in functions and libraries in python such as the math and matplotlib libraries. You can also use the equations of uniform circular motion to calculate the position and velocity of the object at different points along the circular path.

3. What are the key components of a python program for Uniform Circular Motion?

The key components of a python program for Uniform Circular Motion include defining the initial conditions such as the radius of the circular path, the object's initial position and velocity, and the time interval. Then, using equations of motion and loops, you can calculate the position and velocity of the object at different time intervals and plot them on a graph using matplotlib.

4. Can I use the python program to visualize different parameters of Uniform Circular Motion?

Yes, you can use the python program to visualize various parameters of Uniform Circular Motion, such as the position, velocity, acceleration, and centripetal force of the object at different points along the circular path. This can help in understanding the behavior and characteristics of the motion.

5. Are there any limitations to the python program for Uniform Circular Motion?

While the python program can simulate Uniform Circular Motion accurately, there are some limitations to consider. The accuracy of the simulation depends on the chosen time interval and the precision of the calculations. Additionally, factors such as air resistance and friction may not be accounted for in the simulation, which can affect the accuracy of the results.

Similar threads

  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
17
Views
3K
  • Programming and Computer Science
Replies
2
Views
16K
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
3K
Replies
19
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
10
Views
10K
  • Programming and Computer Science
Replies
2
Views
10K
Back
Top