Python Uniform Circular Motion - python program

AI Thread Summary
The discussion centers around a programming assignment where the user created a program to calculate the radius of a circular orbit based on the orbiting object's velocity and other parameters. The program includes a narrative to enhance user engagement and utilizes the gravitational force formula to compute the necessary values. Key calculations involve determining the gravitational force, acceleration, and the new orbit radius using the relationship between velocity and acceleration in circular motion. A suggestion is made to refine the calculations by using the gravitational force at the new radius instead of the old one, emphasizing the need to combine the equations for circular motion and gravitational acceleration to accurately solve for the radius. The narrative element of the program is noted as a creative addition to the solution.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
1
Views
3K
Replies
17
Views
3K
Replies
3
Views
2K
Replies
2
Views
10K
Back
Top