Last active
August 29, 2015 13:58
-
-
Save dmadisetti/10225121 to your computer and use it in GitHub Desktop.
The masses and coordinates of three spheres are as follows: 28 kg, x = 1.00 m, y = 2.50 m; 44 kg, x = -2.00 m, y = -1.75 m; 54 kg, x = 0.00 m, y= -0.50 m. What is the magnitude of the gravitational force on a 18 kg sphere located at the origin due to the other spheres?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
G = 6.67e-11 | |
class Point: | |
def __init__(self,m,x,y): | |
self.m = m | |
self.x = x | |
self.y = y | |
def force(self,m): | |
return (G*self.m*m)/(math.pow(self.x,2)+math.pow(self.y,2)) | |
def xD(self,m): | |
return self.component(m, self.x, math.cos) | |
def yD(self,m): | |
return self.component(m, self.y, math.sin) | |
def component(self,m,driving,f): | |
direction = ((-2 * (driving < 0)) + 1) * self.force(m) | |
try: | |
return direction *f(math.atan(self.y/self.x)) | |
except: | |
return direction *f(math.pi/2) | |
a = Point(28,1,2.5) | |
b = Point(44,-2,-1.75) | |
c = Point(54,0,-0.50) | |
m = 18 | |
fx = a.xD(m) + b.xD(m) + c.xD(m) | |
fy = a.yD(m) + b.yD(m) + c.yD(m) | |
print math.sqrt(math.pow(fx,2) + math.pow(fy,2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def force(m1,m2,r1,r2): | |
return (G*m1*m2)/(math.pow(r1,2)+math.pow(r2,2)) | |
def x(f,r1,r2): | |
try: | |
magnitude = f*math.cos(math.atan(r2/r1)) | |
except: | |
magnitude = f*math.cos(math.pi/2) | |
direction = 1 if (r1==0) else (math.fabs(r1)/r1) | |
return magnitude*direction | |
def y(f,r1,r2): | |
try: | |
magnitude = f*math.sin(math.atan(r2/r1)) | |
except: | |
magnitude = f*math.sin(math.pi/2) | |
direction = 1 if (r2==0) else (math.fabs(r2)/r2) | |
return magnitude*direction | |
G = 6.67e-11 | |
m1 = 28 | |
m1r1 = 1 | |
m1r2 = 2.5 | |
m2 = 44 | |
m2r1 = -2 | |
m2r2 = -1.75 | |
m3 = 54 | |
m3r1 = 0 | |
m3r2 = -0.50 | |
m = 18 | |
f1 = force(m1,m,m1r1,m1r2) | |
f2 = force(m2,m,m2r1,m2r2) | |
f3 = force(m3,m,m3r1,m3r2) | |
fx = x(f1,m1r2,m1r1) + x(f2,m2r2,m2r1) + x(f3,m3r2,m3r1) | |
fy = y(f1,m1r2,m1r1) + y(f2,m2r2,m2r1) + y(f3,m3r2,m3r1) | |
print math.sqrt(math.pow(fx,2) + math.pow(fy,2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Woah white space got funky during the declaration