TP :Runge-Kutta Methods-Solar System-The Method of Least Squares December 8, 2009 1 Runge-Kutta Method The problem is still trying to solve the first order differential equation dy = f(y, x). (1) dx In the Euler s method we approximate the function y = y(x) in each interval [x n, x n+1 ] by the straight line y n+1 = y n + xf(x n, y n ). (2) The slope f(x n, y n ) of this line is exactly given by the slope of the function y = y(x) at the begining of the inetrval [x n, x n+1 ]. Given the value y n at x n we evaluate the value y n+1 at x n+1 using the method of Runge-Kutta as follows. Firstly the middle of the interval [x n, x n+1 ] which is at the value x n + 1 2 x corresponds to the y value y n+1 calculated using the Euler s method, viz y n+1 = y n + 1 2 k 1 where Secondly the slope at this middle point (x n + 1 2 x, y n + 1 2 k 1) given by k 1 = xf(x n, y n ). () k 2 x = f(x n + 1 2 x, y n + 1 2 k 1) (4) is the value of the slope which will be used to estimate the correct value of y n+1 at x n+1 using again Euler s method,namely y n+1 = y n + k 2. (5) The error in this method is proportional to x. Let us apply this method to the problem of the harmonic oscillator. We have the differential equations Euler s equations read dθ dt = ω dω dt = g θ. (6) l θ n+1 = θ n + tω n ω n+1 = ω n g l θ n t. (7) 1
First we consider the function θ = θ(t). The middle point is (t n + 1 2 t, θ n + 1 2 k 1) where k 1 = tω n. For the function ω = ω(t) the middle point is (t n + 1 2 t, ω n + 1 2 k ) where k = g l tθ n. Therefore we have The slope of the function θ(t) at its middle point is The slope of the function ω(t) at its middle point is k 1 = tω n k = g l tθ n. (8) k 2 t = ω n + 1 2 k. (9) The Runge-Kutta solutions are then given by k 4 t = g l (θ n + 1 2 k 1). (10) θ n+1 = θ n + k 2 ω n+1 = ω n + k 4. (11) 2 Kepler s Laws-The Inverse-Square Law Newton s second law: We consider the motion of the earth around the sun. Let r be the distance and M s and M e the masses of the sun and the earth respectively. We neglect the effect of the other planets and the motion of the sun (i.e we assume that M s >> M e ). The goal is to calculate the position of the earth as a function of time. We start from Newton s second law of motion We get the two equations d 2 r M e dt 2 = GM em s r r = GM em s r (x i + y j). (12) d 2 x dt 2 = r x. (1) d 2 y dt 2 = r y. (14) We replace these two second order differential equations by the four first order differential equations dx dt = v x. (15) dv x r x. (16) dy dt = v y. (17) dv y r y. (18) 2
Astronomical units: The distance will be measured in astronomical units (AU) whereas time will be measured in years. One astronomical unit of lenght (1 AU) is equal to the average distance between the earth and the sun, viz 1AU = 1.5 10 11 m. The astronomical unit of mass can be found s follows. Assuming a circular orbit we have Equivalently M e v 2 r = M e r 2. (19) = v 2 r. (20) The radius is r = 1AU. The velocity of the earth is v = 2πr/yr = 2πAU/yr. Hence Kepler s laws: These are given by the following three statements: = 4π 2 AU /yr 2. (21) The planets move in elliptical orbits around the sun. The sun resides at one focus. The line joining the sun with any planet sweeps out equal areas in equal times. Given an orbit with a period T and a semimajor axis a the ratio T 2 /a is a constant. The inverse-square law and stability of orbits: Any object with mass generates a gravitational field. In other words gravitational field lines will emanate from the object and radiate outward to infinity. The number of field lines N is proportional to the mass. The density of field lines crossing a sphere of radius r surrounding this object is given by N/4πr 2. This is the origin of the inverse-square law. Therefore any other object placed in this gravitational field will experience a gravitational force proportional to the number of field lines which intersect it. If the distance between this second object and the source is increased the force on it will become weaker because the number of field lines which intersect it will decrease as we are further away from the source. Euler-Cromer Algorithm The time discretization is t t(i) = (i 1) t, i = 1,..., L + 1. (22) The total time interval T = L t. We define x(t) = x(i 1), v x (t) = v x (i 1), y(t) = y(i 1), v y (t) = v y (i 1). Equations (15), (16), (17) and (18) become (with i = 2,,..., L + 1) v x (i) = v x (i 1) x(i 1) t. (2) x(i) = x(i 1) + v x (i 1) t. (24) v y (i) = v y (i 1) y(i 1) t. (25) y(i) = y(i 1) + v y (i 1) t. (26)
This is Euler s algorithm. In order to maintain energy conservation we employ Euler-Cromer algorithm. We calculate as in the Euler s algorithm the velocity at time step i by using the position and velocity at time step i 1. However we compute the position at time step i by using the position at time step i 1 and the velocity at time stpe i, viz v x (i) = v x (i 1) x(i 1) t. (27) x(i) = x(i 1) + v x (i) t. (28) v y (i) = v y (i 1) y(i 1) t. (29) y(i) = y(i 1) + v y (i) t. (0) 4 Runge-Kutta Algorithm Let us consider the equations dx dt = v x. (1) dv x r x. (2) dy dt = v y. () dv y r y. (4) First we consider the function x = x(t). The middle point is (t n + 1 2 t, x n + 1 2 k 1) where k 1 = t v xn. For the function v x = v x (t) the middle point is (t n + 1 2 t, v xn + 1 2 k ) where k = GMs t x n. Therefore we have The slope of the function x(t) at the middle point is The slope of the function v x (t) at the middle point is k 4 k 1 = t v xn k = t x n. (5) k 2 t = v xn + 1 2 k. (6) t = (x n + 1 2 k 1). (7) R n Next we consider the function y = y(t). The middle point is (t n + 1 2 t, y n + 1 2 k 1 ) where k 1 = t v yn. For the function v y = v y (t) the middle point is (t n + 1 2 t, v yn + 1 2 k ) where k = GMs t y n. Therefore we have k 1 = t v yn k = t y n. (8) 4
The slope of the function y(t) at the middle point is The slope of the function v y (t) at the middle point is k 2 t = v yn + 1 2 k. (9) In the above equations R n = k 4 t = R n (y n + 1 2 k 1 ). (40) (x n + 1 2 k 1) 2 + (y n + 1 2 k 1 )2. (41) The Runge-Kutta solutions are then given by x n+1 = x n + k 2 v x(n+1) = v xn + k 4 y n+1 = y n + k 2 v y(n+1) = v yn + k 4. (42) 5 Solar System-Precession of the Perihelion of Mercury The orbit of mercury is elliptic. The orientation of the axes of the ellipse rotate with time. This is the precession of the perihelion (the point of the orbit nearest to the sun) of mercury. Mercury s perihelion makes one revolution every 2000 years. This is approximately 566 arcseconds per century. The gravitational forces of the other planets (in particular Jupiter) lead to a precession of 52 arcseconds per century. The remaining 4 arcseconds per century are accounted for by general relativity. For objects too close together (like the sun and mercury) the force of gravity predicted by general relativity deviates from the inverse-square law. This force is given by F = M m r 2 (1 + α r 2 ), α = 1.1 10 8 AU 2. (4) Initial Conditions: For the numerical simulations it is important to determine the correct initial conditions. The orbit of mercury is known to be an ellipse with eccentricity e = 0.206 and radius (semimajor axis) a = 0.9 AU with the sun at one of the foci. The distance between the sun and the center is ea. The first initial condition is x 0 = r 1, y 0 = 0 where r 1 is the maximum distance from mercury to the sun,i.e r 1 = (1 + e)a = 0.47 AU. The second initial condition is the velocity (0, v 1 ) which can be computed using conservation of energy and angular momentum. For example by comparing with the point (0, b) on the orbit where b is the semiminor axis, i.e b = a 1 e 2 the velocity (v 2, 0) there can be obtained in terms of (0, v 1 ) from conservation of angular momentum as follows Next conservation of energy yields M m r 1 r 1 v 1 = bv 2 v 2 = r 1v 1 b. (44) + 1 2 M mv 2 1 = M m r 2 + 1 2 M mv 2 2. (45) In above r 2 = e 2 a 2 + b 2 is the distance between the sun and mercury when at the point (0, b). By substituting the value of v 2 we get an equation for v 1. This is given by GMs 1 e v 1 = = 8.2 AU/yr. (46) a 1 + e 5
6 Method of Least Squares We assume that we have N data points (x(i), y(i)). We want to fit this data to some curve say a straight line y fit = mx + b. To this end we define the function N N = (y(i) y fit (i)) 2 = (y(i) mx(i) b) 2. (47) i=1 The goal is to minimize this function with respect to b and m. We have i=1 We get the solution m = 0, = 0. (48) b i b = x(i) j x(j)y(j) i x(i)2 j y(j) ( i x(i))2 N. (49) i x2 i i m = x(i) j y(j) N i x(i)y(i) ( i x(i))2 N. (50) i x2 i 6