Vous êtes sur la page 1sur 13

PH2150 Report H W Evans PH2150 Scientific Computing Skills: Report

Computing Planetary Motion with the Runge-Kutta Method


H W Evans 17th January 2011

Abstract
Java code was used to create a program which uses the Euler and the Runge-Kutta methods to simulate the orbit of mercury around the sun. Relativistic effects were added to add a precession to the orbit, which is verified by observation.

Introduction

The task set was to simulate and plot the orbit of a planet, in this case mercury, around the sun and show how its orbit processes over time.

3 Theory
The task was to analyse the nature of mercurys orbit around the sun using numerical methods, namely the Euler method and the Runge-Kutta method. The laws governing the orbit of a body around a fixed mass are classically known as Keplers laws. These laws are as follows: 1. The orbit of a planet is an ellipse with the Sun at one of a possible two foci1.

Planet Foci

Figure 1: Basic diagram of an elliptical orbit, showing the two possible foci at which the larger mass will be located.

PH2150 R

t H W Evans

Planet Foci

ea a 2a

Fi

2: Advanced diagram of elli tical planetary motion, highlighting the eccentricity of the orbit, e.

The eccent icit of a planets orbit can be defined as the ratio bet een 2a and 2ea, where a is the largest radi s of orbit of a planet, about the centre of the ellipse and ea is the distance between the centre and one of the foci of the ellipse. 2. A planet will sweep out equal areas during equal ti e at any point of its orbit .1

Fig 3:Digram ill trating the second law.

PH2150 Report H W Evans

3. Keplers third law states that the orbital period of a planet squared is proportional to the cube of its semi major axis. This part of theory, although integral to planetary motion will not be required in this project as we are not dealing with orbital periods, we are inste ad using a numerical iteration with position coordinates.

We also need to consider the gravitation equation, which in simple form is as follows:

Where m is the mass of the smaller, orbiting body, M is the mass of the large fi ed body, G is the gravitational constant and r is the radius of the orbit. This equation needs altering however, because this equation only describes a perfectly circular orbit and it is in spherical coordinates. To convert this equation to Cartesian coordinates and adding a theta dependence (angle from centre subtended at the edge) gives:

However when observing planets and other bodies as they process around an orbit, there is a slight shift in the orbit known as a precession. This precession of the perihelion is not predicted in Keplers laws, but thankfully it is predicted if you consider general relativistic effects. This transforms the equations above to:

This means that over time the perihelion of orbit of mercury (or any planet for that matter will) will process over time, and the task at hand was to use a series of Java programs to numerically simulate this.

[All equations on this page are taken from reference 2] 3

(1)

(2)

(3)

(4)

PH2150 Report H W Evans

4 Method
The experimental procedure was essentially computer programming in Java, and so this section will try to best illustrate how we constructed our programs and how they worked, most notably the outcome and plots. The first step was to understand the problem at hand, and so the first week was spent writing in lab books about how to begin programming, primarily this involved selecting the equations that we would need to simulate the orbit of a planet. To begin with we selected given equations of motion for any moving body in a gravitational orbit the gravitation equations mentioned in the theory section above (1,2,3). Once we had isolated the correct equations to use we began by creating a preliminary program to simulate the gravitation equation, the code was as follows:

Figure 4: Acceleration Java coding. No advanced commands, simply converting the required formulae into a format the computer can understand

PH2150 Report H W Evans

Once we had got the acceleration sorted out, we began researching the first method of numerical iteration that we had been set to use: Eulers Method. 4.1 E lers Method Eulers method is essentially a method for numerically iterating any function given some initial starting values. In our case these starting values are: x position, y position, velocity in the x direction and finally velocity in the y direction. The Euler method uses the following four coupled differential equations to iterate four quantities, which are again: x position (5), y position (6), velocity in the x direction (7) and finally velocity in the y direction (8). Euler Equations 2 (5) (6) (7) (8)

What these equations are essentially doing are taking an initial value for the velocity/position of a body or planet and inserting it into the corresponding part of the equations, and then working out a new value and inputting it again, and so on. Let us analyse one of the equations (8) to better understand what it means:

This is the initial value, which in this case would be initial velocity in the y direction. This is the time step (delta t) multiplied by the derivative of the velocity function in the y direction, which is acceleration. We already have an equation for this (3) however we will need to divide by mass because we have force rather than acceleration. The complicated part here is that our equation for acceleration includes x and y position values, meaning we will have to re-iterate this step every time a new set of x and y positions are created. This is the result for the velocity in the y direction at time tn+1.

In this case we must begin with the velocity equations (7) and (8) because equations (5) and (6) require results from these every iteration to enter new velocity values. This makes programming the method slightly complicated.

PH2150 Report H W Evans So the next step was to transfer our newly obtained knowledge of this method into java code The . plan was to create an iteration loop using a for loop which began by recognising the initial x, y, V, x Vy values and then worked out velocities followed by positions, beginning by using the initial values but after that the next iteration would use the newly calculated values as the new initial values. Here is that loop, programmed in Java code:

Figure 5: Eulers Method in Java code

PH2150 Report H W Evans And here is an example of the output of the program:

With this data we made our first initial plot, using Wolfram Mathmatica 7.0:

These results are for a non relativistic expression, and so there is no precession of the perihelion of the orbit.

PH2150 Report H W Evans 4.2 The Runge-Kutta method The Runge-Kutta method is basically an extension and a more complicated and accurate version of the Euler method. The following quote outlines what is wrong with the Euler method: The problem with the Euler method was that the approximation for x(tn+1) used the time derivative of x evaluated at time tn. But in the course of stepping from tn to tn+1 the derivative changes. 2

To solve this problem a new set of equations were derived to take a point halfway between t and n tn+1: Runge-Kutta Equations 2 (9) (10) (11) (12) (13)

In effect this method uses four different equations per variable, however when coding we found that it was more effective and less buggy to set the main variable as acceleration and iterate the positions using lots of different acceleration values, as is shown in our code below:

PH2150 Report H W Evans

Figure 6: Runge-Kutta Java coding. This program was written using equations (9-13) as well as the relativistic gravitation equation (4). This print-screen does not include all of the constants that were declared outside the loop, as it would not have been possible to fit all of them on the screen The following variables were declared . outside of the loop:

PH2150 Report H W Evans 4.3 Coding explanation. This section will try to explain the reasoning behind the coding of the Runge-Kutta method in detail.

This section of code is essentially putting equation (9) into Java code, utilising the relativistic gravitation equation (4) in the first two lines. Acceleration is used as the main variable.

This coding section is equation (10) into Java code, again obviously using the same variable acceleration. This section of code uses the results from k1 to calculate new results for all of the variables x, y, Vx, Vy.

Almost identical to the previous two pieces of code, this one uses k2 to calculate new results for all of the variables x, y, Vx, Vy. Equation (11) in Java code essentially.

Equation (12) describes this piece of code, in that it uses k3 to work out the final values for all of the variables.

10

PH2150 Report H W Evans

The final piece of code in the main code which executes the Runge -Kutta method. This line of code essentially puts equation (13) into Java code and combines all of the worked out k values to work our final values for the acceleration in the x and y planes, which are then used in the next iteration.

5 Anal sis of Results


The results we obtained were very good, for both the Eulers Method and the Runge -kutta method. In both cases a clear elliptical orbit was seen, with the correct eccentricity. Below is a plot of results from Eulers method, without relativistic effects. Figure 7: Plot of radius in x,y coordinates using Eulers Method.

This is clearly elliptical and there is no precession of the orbit, which is exactly what we would expect without adding the relativistic component. Instead of creating a relativistic Eulers method we simply used the Runge -Kutta method and added the extra component, as is seen in equation (4). To the left is a plot of the data obtained with high iteration value (106), and as is obvious from the graph this is not the kind of precession we are looking for, mercurys orbit only shifts by an extremely small amount and the radius should not increase so dramatically. This error is assumed to be cumulative in that if we did less iterations it should decrease the error. Figure 8: Plot of radius in x,y coordinates using Runge-Kutta Method.

11

PH2150 Report H W Evans . For low iteration values (up to 105) a precession in the perihelion was clearly seen, an example being below. This plot is the best looking one we produced and clearly illustrates what we are looking for in a precession, the very slight shift of the orbital radii in the x and y planes.

Figure 9: Plot of radius in x,y coordinates using Runge-Kutta Method.

6 Conclusion
In conclusion the experiment went very well and all of the code written worked as expected. The results produced were exactly what was expected, which was a precession in the perihelion of the orbit of mercury around the sun. Although there was clearly some cumulative error in the Runge Kutta method demonstrated by fig 8, this problem was easily avoided by reducing the number of iterations and we still obtained a nice plot with a slight precession: fig 9. Further improvements could be made however, for example the error on the method could be quantified and calculated and reduced from the results. However this would be extremely hard and take much more coding, as each iteration would have to inc lude it.

12

PH2150 Report H W Evans

References

1. Nave R, "Keplers Laws", http://hyperphysics.phy-astr.gsu.edu/hbase/kepler.html, retrieved 5th January 2011. 2. Prof. Cowan, Planetary Motion http://www.pp.rhul.ac.uk/~cowan/ph2150/kepler_xy.pdf, retrieved 6th January 2011.

13

Vous aimerez peut-être aussi