CODE
t=0
G = 6.6726e-11 #gravitational constant
x = 5 #distance between the two masses
m1 = 30000 #mass1
m2 = 50000 #mass2
dt = 1 #step
v1=0 #speed1
v2=0 #speed2
while t<10000:
print 'distance: ',x
print 'speed1: ',v1
print 'speed2: ',v2,'\n'
Fg = (G*m1*m2)/(x**2) #gravitational force
a1 = Fg/m1 #Seeing how F = a * m, a would be F/m. So this is the acceleration of the first mass
a2 = Fg/m2 #Acceleration of the second mass
s1 = 0.5*a1*(dt**2)+v1*dt
s2 = 0.5*a2*(dt**2)+v2*dt
x = x-s1-s2
v1 = (a1*dt)+v1
v2 = (a2*dt)+v2
t = t+dt
G = 6.6726e-11 #gravitational constant
x = 5 #distance between the two masses
m1 = 30000 #mass1
m2 = 50000 #mass2
dt = 1 #step
v1=0 #speed1
v2=0 #speed2
while t<10000:
print 'distance: ',x
print 'speed1: ',v1
print 'speed2: ',v2,'\n'
Fg = (G*m1*m2)/(x**2) #gravitational force
a1 = Fg/m1 #Seeing how F = a * m, a would be F/m. So this is the acceleration of the first mass
a2 = Fg/m2 #Acceleration of the second mass
s1 = 0.5*a1*(dt**2)+v1*dt
s2 = 0.5*a2*(dt**2)+v2*dt
x = x-s1-s2
v1 = (a1*dt)+v1
v2 = (a2*dt)+v2
t = t+dt
So that's it. But there's a problem. It seems to be working just fine at first, but when the masses get past each other (ie: x < 0), they suddenly go away from each other at a great speed. I don't get it, because when x is negative, so will be Fg, so both the accelerations should be negative as well, which means the speeds will decrease and become negative after a while as well. But that doesn't happen...
Any ideas on why and how I could fix it?
Thanks in advance
PS: I tried to attach a copy of the file but was told the following: "The requested file upload failed because suitable permissions have not been enabled on the 'uploads' directory. Please contact the board administrator and inform them of this error."