Question
I am trying to graph ongoing data not just graph when the object hits the Earth. I want to see the object go around the
I am trying to graph ongoing data not just graph when the object hits the Earth. I want to see the object go around the Earth. Currently, my program gives x and y data infinity since it is orbiting around the Earth.
import math
import scipy.constants
import matplotlib.pyplot as plt
#import numpy as np
H = 8848 # m
R = 6.3781e6 # m
Rtotal = H + R
g0 = scipy.constants.g
G = scipy.constants.G
M = 5.972e24 # kg
m = 20 # kg
# v0 = 7897
# v0 = 7896.75
v0 = math.sqrt(9.81*(H+R))*math.sqrt(1.1)
x = [0]
y = [Rtotal]
ay = [-g0]
ax = [0]
vx = [v0]
vy = [0]
dt = 0.01
i = 0
while (x[i]**2+y[i]**2 > R**2 ):
vx.append(vx[i]+ax[i]*dt)
vy.append(vy[i]+ay[i]*dt)
x.append(x[i]+vx[i]*dt+0.5*ax[i]*dt**2)
y.append(y[i]+vy[i]*dt+0.5*ay[i]*dt**2)
ax.append(-(G*M/(x[i]**2+y[i]**2))*x[i]/math.sqrt(x[i]**2+y[i]**2))
ay.append(-(G*M/(x[i]**2+y[i]**2))*y[i]/math.sqrt(x[i]**2+y[i]**2))
print(f"X: {x[i]} Y: {y[i]} R: {math.sqrt(x[i]**2+y[i]**2)-R} I: {i}")
if math.sqrt(x[i]**2+y[i]**2)-R <= H:
if x[i] < 0:
print("STOP!!!")
break
i += 1
print(f"PE: {-(G*M*m/math.sqrt(x[i]**2+y[i]**2))} KE: {0.5*m*math.sqrt(vx[1]**2+vy[1]**2)}")
print(f"Excape V: {math.sqrt(g0*Rtotal)}")
circle1=plt.Circle((0,0),R,color='r')
plt.gcf().gca().add_artist(circle1)
plt.plot(x,y)
plt.show()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started