- #1
yik-boh
- 57
- 0
Homework Statement
We need to plot a two points (representation of planets). One is stationary and one is supposed to move on a circular orbit. We are using Python, Matplotlib and Numpy. We're not getting a circular orbit. We're just getting a line.
Homework Equations
a = F / mass1
x = x + (v * t) + (0.5 * a * t**2)
y = y + (v * t) + (0.5 * a * t**2)
The Attempt at a Solution
Code:
import matplotlib.pyplot as plt
from math import *
i = 0
t = 0
x1 = []
y1 = []
x = 5
y = 0
bx = 2
by = 0
v = 0
mass1 = input("input mass 1: ")
mass2 = input("input mass 2: ")
G = 6.67e-11
bigx = x
bigy = y
smallx = bx
smally = by
while i < 10000:
i = i+1
while t<100:
r = sqrt((x-bx)**2 + (y-by)**2)
t = t + 0.001
F = G * mass1 * mass2 / r**2
a = F / mass1
v = v + a * t
x = x + (v * t) + (0.5 * a * t**2)
y = y + (v * t) + (0.5 * a * t**2)
y1.append(y)
x1.append(x)
plt.plot(x1,y1)
plt.plot(smallx,smally, marker ='o',linestyle = '-', color = 'b')
plt.plot(bigx,bigy, marker ='o', color = 'r')
plt.axis([-20,20,-20,20])
plt.show()