Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
afeiguin
GitHub Repository: afeiguin/comp-phys
Path: blob/master/02_01_central_potential.ipynb
374 views
Kernel: Python 3

Motion in a central potential

forces2

An object of mass mm under the effects of a central force FF.

Kepler’s problem

The motion of the sun and the earth is an example of a “two-body problem”. This is a relatively simple problem that can be solved analytically (it interesting to notice here, however, that adding a new object to the problem, the moon for instance, make it completely intractable. This is the famous “three body problem”). We can assume that, to a good approximation, the sun is stationary and is a convenient origin of our coordinate system. This is equivalent to changing to a “center of mass” coordinate system, where most of the mass is concentrated in the sun. The problem can be reduced to an equivalent one body problem involving an object of reduced mass μ\mu given by μ=mMm+M\mu=\frac{mM}{m+M} Since the mass of the earth is m=5.99×1024m=5.99\times 10^{24} kg and the mass of the sun is M=1.99×1030M=1.99\times 10^{30} kg we find that for most practical purposes, the reduced mass of the earth-sun system is that of the earth. Hence, in the following we are going to consider the problem of a single particle of mass mm moving about a fixed center of force, which we take as the origin of the coordinate system. The gravitational force on the particle m is given by F=GMmr3r,{\mathbf F}=-\frac{GMm}{r^3}{\mathbf r}, where the vector r{\mathbf r} is directed from MM to mm, and GG is the gravitation constant G=6.67×1011m3kg.s2G=6.67\times 10^{-11} \frac{m^3}{kg.s^2} The negative sign implies that the gravitational force is attractive, and decreases with the separation rr. The gravitational force is a “central force”: its magnitude depends on the separation between the particles and its direction is along the line that connects them. The assumption is that the motion is confined to the xyxy plane. The angular momentum L{\mathbf L} lies on the third direction zz and is a constant of motion, i.e. it is conserved: Lz=(r×mv)z=m(xvyyvx)=const.L_z=({\mathbf r}\times m{\mathbf v})_z=m(xv_y-yv_x)=\mathrm{const.} An additional constant of motion ins the total energy EE given by E=12mv2GmMrE=\frac{1}{2}mv^2-\frac{GmM}{r} If we fix the coordinate system in the sun, the equation of motion is md2rdt2=mMGr3rm\frac{d^2{\mathbf r}}{dt^2}=-\frac{mMG}{r^3}{\mathbf r} For computational purposes it is convenient to write it down in cartesian components: Fx=GMmr2cosθ=GMmr3x,Fy=GMmr2sinθ=GMmr3y.\begin{aligned} && F_x=-\frac{GMm}{r^2}\cos{\theta}=-\frac{GMm}{r^3}x, \\ && F_y=-\frac{GMm}{r^2}\sin{\theta}=-\frac{GMm}{r^3}y.\end{aligned} Hence, the equations of motions in cartesian coordinates are: d2xdt=GMr3x,d2ydt=GMr3y,\begin{aligned} && \frac{d^2x}{dt}=-\frac{GM}{r^3}x, \\ && \frac{d^2y}{dt}=-\frac{GM}{r^3}y, \end{aligned} where r2=x2+y2r^2=x^2+y^2. These are coupled differential equations, since each differential equation contains both xx and yy.

Circular motion

Since many planetary orbits are nearly circular, it is useful to obtain the condition for a circular orbit. In this case, the magnitude of the acceleration a{\mathbf a} is related to the radius by a=v2ra=\frac{v^2}{r} where vv is the speed of the object. The acceleration is always directed toward the center. Hence mv2r=mMGr2\frac{mv^2}{r}=\frac{mMG}{r^2} or v=(MGr)1/2.v=(\frac{MG}{r})^{1/2}. This is a general condition for the circular orbit. We can also find the dependence of the period TT on the radius of a circular orbit. Using the relation T=2πrv,T=\frac{2\pi r}{v}, we obtain T2=4π2r3GMT^2=\frac{4\pi^2r^3}{GM}

Elliptical orbits

An ellipse has two foci F1F_1 and F2F_2, and has the property that for any point the distance F1P+F2PF_1P+F_2P is a constant. It also has a horizontal semi-axis aa and a vertical bb. It is common in astronomy to characterize an orbit by its “eccentricity” ee, given by the ratio of the distance between the foci, and the length of the major axis 2a2a. Since F1P+F2P=2aF_1P+F_2P=2a, it is easy to show that (consider a point PP at x=0x=0,y=by=b) e=1b2a2,e=\sqrt{1-\frac{b^2}{a^2}}, with 0<e<10<e<1. A special case is a=ba=b for which the ellipse reduces to a circle and e=0e=0. The earth orbit has eccentricity e=0.0167e=0.0167.

Astronomical units

It is useful to choose a system of units where the product GMGM is of the order of unity. To describe the earth’s motion, the convention is to choose the earth’s semi-major axis as the unit of length, called “astronomical unit” (AU) and is 1AU=1.496×1011m.1AU=1.496 \times 10^{11}m. The unit of time is taken to be “one year”, or 3.15×1073.15 \times 10^7s. In these units, T=1T=1yr, a=1AUa=1AU, and we can write GM=4π2a3T2=4π2AU3/yr2.GM=\frac{4\pi ^2a^3}{T^2}=4\pi ^2 AU^3/yr^2.

Exercise 2.1: Simulation of the orbit

  1. Write a program to simulate motion in a central force field. Verify the case of circular orbit using (in astronomical units) (x0=1x_0=1, y0=0y_0=0 and vx(t=0)=0v_x(t=0)=0. Use the condition ([circular] to calculate vy(t=0)v_y(t=0) for a circular orbit. Choose a value of Δt\Delta t such that to a good approximation the total energy EE is conserved. Is your value of Δt\Delta t small enough to reproduce the orbit over several periods?

  2. Run the program for different sets of initial conditions x0x_0 and vy(t=0)v_y(t=0) consistent with the condition for a circular orbit. Set y0=0y_0=0 and vx(t=0)=0v_x(t=0)=0. For each orbit, measure the radius and the period to verify Kepler’s third law (T2/a3=const.T^2/a^3=\mathrm{const.}). Think of a simple condition which allows you to find the numerical value of the period.

  3. Show that Euler’s method does not shield stable orbits for the same choice of Δt\Delta t used in the previous items. Is it sufficient to simply choose a smaller Δt\Delta t or Euler’s method is no stable for this dynamical system? Use the average velocity 1/2(vn+vn+1)1/2(v_n+v_{n+1}) to obtain xn+1x_{n+1}. Are the results any better?

  4. Set y0=0y_0=0 and vx(t=0)=0v_x(t=0)=0. By trial and error find several choices of x0x_0 and vy(t=0)v_y(t=0) which yield coonvinient elliptical orbits. Determine total energy, angular momentum, semi-major and semi-nimor axes, eccentricity, and period for each orbit.

  5. You probably noticed that Euler’s algorithm with a fixed Δt\Delta t breaks down if you get to close to the sun. How are you able to visually confirm this? What is the cause of the failure of the method? Think of a simple modification of your program that can improve your results.

class particle2(object): def __init__(self, mass=1., x=0., y=0., vx=0., vy=0.): self.mass = mass self.x = x self.y = y self.vx = vx self.vy = vy def euler(self, fx, fy, dt): self.vx = self.vx + fx/self.mass*dt self.vy = self.vy + fy/self.mass*dt self.x = self.x + self.vx*dt self.y = self.y + self.vy*dt
%matplotlib inline import numpy as np from matplotlib import pyplot from matplotlib.colors import ColorConverter as cc import math GM = 4*math.pi**2 r = 1 # radius of the orbit v0 = math.sqrt(GM/r) # This is the condition for circular orbits x0 = r # initial position y0 = 0. # we asume we start from the x axis v0x = 0. # and the initial velocity v0y = v0 # is perpendicular to the vector position. dt = 0.001 # time step tmax = 4. nsteps = int(tmax/dt) x = np.zeros(nsteps) y = np.zeros(nsteps) vx = np.zeros(nsteps) vy = np.zeros(nsteps) energy = np.zeros(nsteps) x[0] = x0 y[0] = y0 vx[0] = v0x vy[0] = v0y energy[0] = 0.5*(v0y**2+v0x**2) - GM/r p = particle2(1., x0, y0, v0x, v0y) for i in range(0,nsteps): r = math.sqrt(p.x*p.x+p.y*p.y) r3 = r * r * r fx = -GM*p.x/r3 fy = -GM*p.y/r3 p.euler(fx, fy, dt) x[i] = p.x y[i] = p.y vx[i] = p.vx vy[i] = p.vy energy[i] = 0.5*(p.vx**2+p.vy**2) - GM/r t = np.linspace(0.,tmax,nsteps) pyplot.plot(t, energy, color='green', ls='-', lw=3) pyplot.xlabel('time') pyplot.ylabel('Energy');
Image in a Jupyter notebook
pyplot.plot(t, x, color='red', ls='-', lw=3) pyplot.xlabel('time') pyplot.ylabel('position x'); pyplot.xlim(0,4);
Image in a Jupyter notebook
pyplot.plot(x, y, color='blue', ls='-', lw=3) pyplot.xlabel('position x') pyplot.ylabel('position y');
Image in a Jupyter notebook

Challenge 2.1:

Modify the previous code to:

  • Write the axis labels in the right units according to the previous discussion

  • Answer Exercise 2.1, parts 2-5

  • Modifly class particle2 to add a higher order method such as Runge-Kutta

A mini solar system

The presence of other planets implies that the total force on a planet is no longer a central force. Furthermore, since the orbits are not exactly on the same plane, the analysis must be extended to 3D. However, for simplicity, we are going to consider a two-dimensional solar system, with two planets in orbit around the sun.

The equations of motion of the two planets of mass m1m_1 and m2m_2 can be written in vector form as m1d2r1dt2=m1MGr13r1+m1m2Gr213r21,m2d2r2dt2=m2MGr23r2+m1m2Gr213r21,\begin{aligned} && m_1\frac{d^2 {\mathbf r}_1}{dt^2}=-\frac{m_1MG}{r_1^3}{\mathbf r}_1+\frac{m_1m_2G}{r_{21}^3}{\mathbf r}_{21}, \\ && m_2\frac{d^2 {\mathbf r}_2}{dt^2}=-\frac{m_2MG}{r_2^3}{\mathbf r}_2+\frac{m_1m_2G}{r_{21}^3}{\mathbf r}_{21},\end{aligned} where r1{\mathbf r}_1 and r2{\mathbf r}_2 are directed form the sun to the planets, and r21=r2r1{\mathbf r}_{21}={\mathbf r}_2-{\mathbf r}_1 is the vector from planet 1 to planet 2. This is a problem with no analytical solution, but its numerical solution can be obtained extending our previous analysis for the two-body problem.

Exercise 2.2: A three body problem

Let us consider astronomical units, and values for the masses m1/M=0.001m_1/M=0.001 and m2/M=0.01m_2/M=0.01. Consider initial positions r1=1r_1=1 and r2=4/3r_2=4/3 and velocities v1,2=(0,GM/r1,2){\mathbf v}_{1,2}=(0,\sqrt{GM/r_{1,2}}).

  1. Write a program to calculate the trajectories of the two planets, and plot them.

  2. What would the shape and the periods of the orbits be if the don’t interact? What is the qualitative effect of the interaction. Why is one planet affected more by the interaction that the other? Are the angular momentum and energy of planet 1 conserved? Is the total momentum an energy of the two planets conserved?

NPLANETS = 2 m1 = 0.1 r1 = 1. # radius of the orbit v1 = math.sqrt(GM/r1) # This is the condition for circular orbits m2 = 0.01 r2 = 4./3. # radius of the orbit v2 = math.sqrt(GM/r2) # This is the condition for circular orbits dt = 0.001 # time step tmax = 2. nsteps = int(tmax/dt) x = np.zeros(shape=(nsteps,NPLANETS)) y = np.zeros(shape=(nsteps,NPLANETS)) vx = np.zeros(shape=(nsteps,NPLANETS)) vy = np.zeros(shape=(nsteps,NPLANETS)) energy = np.zeros(shape=(nsteps,NPLANETS)) x[0,0] = r1 y[0,0] = 0. vx[0,0] = 0. vy[0,0] = v1 energy[0][0] = 0.5*v1**2 - GM/r1 x[0,1] = r2 y[0,1] = 0. vx[0,1] = 0. vy[0,1] = v2 energy[0][1] = 0.5*v2**2 - GM/r2 planets = [particle2] for i in range(1,NPLANETS): # create a list of NPLANETS particle2's planets.append([particle2]) m = [m1, m2] for i in range(NPLANETS): planets[i] = particle2(m[i], x[0,i], y[0,i], vx[0,i], vy[0,i]) for i in range(1,nsteps): for n in range(0,NPLANETS): r = math.sqrt(planets[n].x*planets[n].x+planets[n].y*planets[n].y); r3 = r * r * r; fx = -GM*planets[n].mass*planets[n].x/r3; fy = -GM*planets[n].mass*planets[n].y/r3; planets[n].euler(fx, fy, dt) x[i,n] = planets[n].x y[i,n] = planets[n].y vx[i,n] = planets[n].vx vy[i,n] = planets[n].vy energy[i,n] = 0.5*(planets[n].vx**2+planets[n].vy**2) - GM/r t = np.linspace(0.,tmax,nsteps)
pyplot.plot(x[:,0], y[:,0], color='blue', ls='-', lw=3) pyplot.plot(x[:,1], y[:,1], color='red', ls='-', lw=3) pyplot.xlabel('position x') pyplot.ylabel('position y');
Image in a Jupyter notebook
pyplot.plot(t, energy[:,0], color='blue', ls='-', lw=3, label='Planet 1') pyplot.plot(t, energy[:,1], color='red', ls='-', lw=3, label = 'Planet 2') pyplot.plot(t, energy[:,0]+energy[:,1], color='green', ls='-', lw=3, label = 'Both planets') pyplot.xlabel('Energy') pyplot.ylabel('time');
Image in a Jupyter notebook

In this particular case, since both planets do not interact, the individual energies are conserved.

Challenge 2:2:

Modify the previous code to introduce the gravitational interaction between planets, and repeat the calculations. Consider masses m1=0.1m_1=0.1 and m2=0.01m_2=0.01, and the initial positions r1=(1,0){\bf r}_1=(1,0) and r2=(3,0){\bf r}_2=(-3,0), with velocities corresponding to circular orbits. Plot the orbits for 5 periods, and the individual and total energies.