Orbit of Earth: Plotting Trajectory

In summary, the plot does not have a nice circular shape. The equations may be incorrect or the plotting may be incorrect.
  • #1
Graham87
62
16
Homework Statement
Write a program to calculate the orbit of the Earth using leapfrog and plot it
Relevant Equations
-GM r/r^3
1.jpg


I am attempting this homework exercise but my plot does not show the whole trajectory. I don't know if it is something wrong with my equations or if it is a plotting matter.
earth trajectory.png

Cheers!This is my code:
Python:
import matplotlib.pyplot as plt
import numpy as np
import scipy.integrate as spi

G = 6.6738*10**-11
M = 1.9891*10**30
h = 3600
y = 1.4710*10**11
vx = 3.0287*20**4

def LeapFrog(f, t_start, t_stop, z0, h):

    t_vec = np.arange(t_start, t_stop, h)
    n = len(t_vec)
    d = len(z0) 
    z_vec = np.zeros((n, d))
    z_vec[0,:] = z0
    z_half_step=z_vec[0 , :] + (1/2)*h*f(z0,t_vec[0])    for i in range(0, n - 1):
        z_vec[i+1,:]=z_vec[i,:] + h*f(z_half_step, t_vec[i])
        z_half_step += h*f(z_vec[i+1,:], t_vec[i])   

    return t_vec, z_vec,def f(z,t):   

    x=z[0]
    y=z[1]
    vx=z[2]
    vy=z[3]
    r=np.sqrt(x**2+y**2)

    dz=np.zeros(4)

    dz[0]=vx
    dz[1]=vy
    dz[2]=-G*M*x/r**3
    dz[3]=-G*M*y/r**3

    return dz

t_start = 0
t_stop = 24*365*5
z0 = np.array([0,y,vx,0])
t_vec, z_vec = LeapFrog(f, t_start, t_stop, z0, h)

plt.plot(z_vec[:,0],z_vec[:,1], 'g', markersize=1, label='Earth trajectory')
plt.plot(0,0,'yo', label = 'Sun positon') 
plt.show()
 
Physics news on Phys.org
  • #2
vx = 3.0287*20**4
 
  • Like
Likes PeroK and Graham87
  • #3
drmalawi said:
vx = 3.0287*20**4
Ah!

Should be vx=3.0287*10**4 and
t_stop = 24 * 365 * 0.99 * h

Now it's correct.

Thanks!
 
  • #4
Graham87 said:
Now it's correct.

Plot works now?
 
  • Like
Likes Graham87
  • #5
drmalawi said:
Plot works now?
Works neatly !
5C7C0380-6069-49B0-B446-E61E2538233B.jpeg
 
  • Like
  • Love
Likes PeroK and malawi_glenn
  • #6
Great job!

Could you fix the plot so that the non-cicrular shape is manifest?
Perhaps also you can plot a circular orbit centered around the sun with the Earth's average orbital distance as well
 
  • Like
Likes Graham87
  • #7
drmalawi said:
Great job!

Could you fix the plot so that the non-cicrular shape is manifest?
Perhaps also you can plot a circular orbit centered around the sun with the Earth's average orbital distance as well
Great idea.
This is much clearer.
C17ADAC9-4085-4512-8CD8-E97F9772736E.jpeg
 
  • Like
Likes malawi_glenn

1. What is the orbit of Earth?

The orbit of Earth refers to the path that our planet takes around the sun. It is an elliptical shape and takes approximately 365.25 days to complete one full orbit.

2. How is the orbit of Earth plotted?

The orbit of Earth is plotted using mathematical equations and data collected from observations and measurements. Scientists use Newton's laws of motion and the law of universal gravitation to calculate the trajectory of Earth's orbit.

3. What factors affect the trajectory of Earth's orbit?

The trajectory of Earth's orbit is primarily affected by the gravitational pull of the sun and other planets in our solar system. Other factors such as the Earth's tilt and the moon's gravitational pull also play a role in the orbit's trajectory.

4. Is the orbit of Earth perfectly circular?

No, the orbit of Earth is not perfectly circular. It is slightly elliptical, meaning it is more oval-shaped than circular. This is due to the gravitational pull of other planets and the fact that the Earth is not perfectly spherical.

5. Can the orbit of Earth change?

Yes, the orbit of Earth can change over time. This is due to various factors such as the gravitational pull of other planets, the Earth's tilt, and even the influence of human activities on the Earth's mass. However, these changes are very small and occur over long periods of time.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
Back
Top