Running FORTRAN programs using modules in Ubuntu:
gfortran -o file.exe usedmodule1.o usedmodule2.o program.f90 ./file.exe
Earth’s orbit around the Sun
To do a simulation of the Earth revolving around the sun, we will be using Newton’s Law of Gravitation, which says
F = GMm/r2
where, G = 6.67384e-11 m3 kg-1 s-2 (gravitational constant ) and M = 1.989e30 kg (mass of sun).
We also know the speed of the Earth and its distance from the Sun at the perihelion (closest point to the Sun).
Distance = 147.098e9 m and Speed = 30287.0 m/s
Hence, we have the equation of motion and the required initial conditions. With every graph we will plot a point at (0,0) which will represent the Sun.
The acceleration depends on r, so for every x and y we need to calculate r = √(x2 + y2). Also we need to calculate the Θ to resolve the velocity components.
Θ = tan-1(y/x). Remember that tan-1 always gives values between -π/2 and π/2. Just add π to Θ when x is negative to get rid of this inconvenience.
To make the animation look cooler, we can add labels to display additional information. The module plotting.f90 needs to be tweaked a bit (a subroutine needs to be added to write the necessary labels). You can find the modified modules and the program below. Comment in case of any problems.