4
PROJECT REPORT STUDY WEEK “FASCINATING INFORMATICS” N-Body Simulation with MATLAB Figure 1: Galaxy JC. Graf, T. Lässer, R. Spichtig Università Della Svizzera Italiana, Lugano, Switzerland Supervised by: Pietro Benedusi Date: 30 September 2017 Abstract Our problem was to calculate and visualise the interactions between n- bodies with the MATLAB framework. We are interested in the computation of the position and velocity of every particle at the time t +Dt knowing position and velocity at time t. Then repeating this process for many time steps we can draw trajectories. As a 1 0 0.1 0.2 0.3 0 0.4 0.5 0.6 z 0.7 0.2 0.4 x 0.6 0.8 0.7 y 0.6 0.8 0.5 0.4 0.3 0.2 0.1 0 Figure 2: Ten randomly created bodies interacting with each other

N-Body Simulation with MATLAB - Schweizer Jugend forscht€¦ · PROJECT REPORT STUDY WEEK “FASCINATING INFORMATICS” N-Body Simulation with MATLAB Figure 1: Galaxy JC. Graf, T

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: N-Body Simulation with MATLAB - Schweizer Jugend forscht€¦ · PROJECT REPORT STUDY WEEK “FASCINATING INFORMATICS” N-Body Simulation with MATLAB Figure 1: Galaxy JC. Graf, T

PROJECT REPORT STUDY WEEK “FASCINATING INFORMATICS”

N-Body Simulation with MATLAB

Figure 1: Galaxy

JC. Graf, T. Lässer, R. Spichtig

Università Della Svizzera Italiana, Lugano, Switzerland Supervised by: Pietro Benedusi

Date: 30 September 2017

Abstract Our problem was to calculate and visualise the interactions between n-bodies with the MATLAB framework. We are interested in the computation of the position and velocity of every particle at the time t +Dt knowing position and velocity at time t. Then repeating this process for many time steps we can draw trajectories. As a

1

0

0.1

0.2

0.3

0

0.4

0.5

0.6

z

0.7

0.20.4

x

0.60.80.7

y

0.60.8 0.50.40.30.20.10

Figure 2: Ten randomly created bodies interacting with each other

Page 2: N-Body Simulation with MATLAB - Schweizer Jugend forscht€¦ · PROJECT REPORT STUDY WEEK “FASCINATING INFORMATICS” N-Body Simulation with MATLAB Figure 1: Galaxy JC. Graf, T

model to describe the system we used classical mechanics, especially Newton’s laws. In the end we produced several simulations, such as the solar system, a swing-by or the collision of some bodies. For creating the simulation the most important thing was to have a working base structure, on which we could build and and created specific simulations. The process of creating the visualisations was a slow process with many difficulties.

1. Introduction/Question N-bodies are a random number of particles in space with a given mass. They interact with each other due to the Newton laws. The goal is the calculate the paths of each body and visualise it. In particular we want to make a nicely looking 3D simulation of interacting n-bodies. Since we reached this goal rather fast we went a step further and simulated the collision of bodies.

2. Materials & Methods Our simulation is based on a few basic physical laws. Given is the mass, and the initial position as also the initial velocity. Based on that we calculated the resulting force, the new position and velocity of each body after the time step. To get the results as precise as possible you have to chose a small enough time step so that you don’t miss and important events on the bodies path. On the other hand, a too small time step makes the simulation remarkably slow. So we always had to find the best time step with trial and error. At first we used the so called Explicit Euler (EE) for making these calculations. Later we switched to the Velocity Verlet (VV). It is very similar to the EE but since it gives a better approximation of the trajectories compared to the EE, we used this method instead. In contrast to the EE, the VV doesn’t just use the current acceleration for calculating the resulting forces, but it takes the average of the two previous acceleration. But the drawback of the VV is that since it does a more complex calculation than the EE, it also requires resources.

3. Results As our main product of this week can our fully working, but simplified, solar system be seen. It contains just on the tree inner planets, the sun and the earth moon. We gave these bodies the real masses, starting velocity and positions. That is also the reason why we created just three planets, then else they would be so small that you could barely see them.

2

Page 3: N-Body Simulation with MATLAB - Schweizer Jugend forscht€¦ · PROJECT REPORT STUDY WEEK “FASCINATING INFORMATICS” N-Body Simulation with MATLAB Figure 1: Galaxy JC. Graf, T

But we still that the problem that the earth moon was way too small and not visible. Therefore, we changed the perspective programmatically during the course of the simulation. In essence we “zoomed in” so that later in the simulation just the earth and the orbiting moon were visible.

We were also able to simulate a swing be. In a swing-by a smaller body which gets close to a body with a larger mass, gets attracted by it and accelerates towards the larger body. The force between the bodies is so strong that the smaller bodies spins partially around the larger one. When the centrifugal force gets too large, the smaller body movies away from the other one with a much higher speed.

We also extended our project in a way, that when two bodies get to close, they collide and merge into one. We used the momentum of the two bodies before the collision to calculate the new velocity of the body after the collision. Even tough we simplified the collisions quite a bit, the simulation looked quite real. It is also clearly visible that the momentum is preserved during the collision.

4. Discussion When we saw all these simulations we realised how complex and also fragile such a system is. This was pretty well visible with our solar system simulation. A small change in one of the numbers might result in the earth falling into the sun, or drifting away into space. It was hard to create a good looking simulation of the solar system since the distances between the planets are so large compared to their size. Therefore, we decided to just simulate three of them. But still we had the problem with the moon. We solved it be simple changing the perspective and zoom in during the simulation. For the swing by we had to give the two bodies the right position, mass as also an initial velocity, in order to get a nice swing by.

5. Acknowledgements We want to say thanks to Dario Moser for planning this study week as also Lia the local coordinator. A big thanks goes to our great tutor Pietro, who helped us a lot during the course of this study week. We also want to thank the University Delle Svizzera Italiana, especially Mauro Prevostini, for providing us with the needed material as also the rooms.

3

-100-50

050

100x-100

-50

0

50

100

y

-100

-50

0

50

100

z

Figure 4: Swing by of two bodies

Page 4: N-Body Simulation with MATLAB - Schweizer Jugend forscht€¦ · PROJECT REPORT STUDY WEEK “FASCINATING INFORMATICS” N-Body Simulation with MATLAB Figure 1: Galaxy JC. Graf, T

Last but no least we want to say thanks to the Hasler Stiftung, the main sponsor of this study week, without whom this week would have not been possible.

References Figure 1: Retrieved from: https://urbanfragment.files.wordpress.com/2012/10/m31-the-andromeda-galaxy-camerawork-by-adam-evans-ferante-edit.jpg

Figure 2,3,4: They are all created by us with MATLAB

4