1.1 overview - unistraastro.u-strasbg.fr/~siebert/pages/teaching/info-l2/projects.pdf · 2. a java...

24
chapter 1 POISSON EQUATION 1.1 Overview This project aims at solving the Poisson equation using different techniques. The Poisson equation is given by ΔΦ(x, y)= 2 φ ∂x 2 + 2 φ ∂y 2 = ρ(x, y) (1.1) and it relates a potential Φ to a density ρ. For instance, a Poisson equation can be found in electrostatics as ΔV = - ρ 0 . (1.2) If the distribution of charges ρ is known, the electrostatic potential can be obtained by solving equation 1.1. The same kind of equation exists for the gravitational force, in a slightly different form: ΔΦ = 4πGρ (1.3) During this project, different ways of finding Φ for an arbitrary ρ will be investigated. Figure 1.1: Left:the density field of large scale structures in the Universe. Right: the associated potential. 1

Upload: buihuong

Post on 15-Mar-2018

222 views

Category:

Documents


2 download

TRANSCRIPT

chapter 1

POISSON EQUATION

1.1 Overview

This project aims at solving the Poisson equation using different techniques.The Poisson equation is given by

∆Φ(x, y) =∂2φ

∂x2+

∂2φ

∂y2= ρ(x, y) (1.1)

and it relates a potential Φ to a density ρ. For instance, a Poisson equationcan be found in electrostatics as

∆V = − ρ

ε0

. (1.2)

If the distribution of charges ρ is known, the electrostatic potential can beobtained by solving equation 1.1. The same kind of equation exists for thegravitational force, in a slightly different form:

∆Φ = 4πGρ (1.3)

During this project, different ways of finding Φ for an arbitrary ρ will beinvestigated.

Figure 1.1: Left:the density field of large scale structures in the Universe.Right: the associated potential.

1

2 CHAPTER 1. POISSON EQUATION

1.2 Technique

In two dimensions, the Poisson equation can easily be solved on a grid usinga finite difference scheme such as:

∆φ ∼ Φi+1,j + Φi−1,j + Φi,j+1 + Φi,j−1 − 4Φi,j

∆X2(1.4)

where Φi,j stands for the potential at the grid point (i, j) and ∆X is thesize of a cell. Hence

Φi+1,j + Φi−1,j + Φi,j+1 + Φi,j−1 − 4Φi,j

∆X2= ρi,j. (1.5)

Solving for Φi,j leads to:

Φi,j =Φi+1,j + Φi−1,j + Φi,j+1 + Φi,j−1 − ρi,j∆X2

4(1.6)

The Jacobi’s iteration technique approximates Φi,j from successive cal-culations:

Φp+1i,j =

Φpi+1,j + Φp

i−1,j + Φpi,j+1 + Φp

i,j−1 − ρi,j∆X2

4(1.7)

where Φp is the potential at iteration p and Φp+1 at potential at the nextiteration. As the number of iterations increases, the approximation Φp

converges toward the correct value as:

limp→+∞

Φp = Φ (1.8)

1.3 Goals

The main objective of this project is to write a C code which computesthe potential on a 2D Grid for an arbitrary density using Jacobi’s iterationtechnique. In order to check the consistency of the result, the potentialsshould be visualised. Once the code is working, other techniques couldbe tested such as the Gauss-Seidel and successive over relaxation (SOR)iterative methods. In particular, the efficiency of the three methods couldbe compared.

1.4 Bibliography

1. Numerical Recipes http://www.nrbook.com/a/bookcpdf.php. Chap-ter 17.

1.4. BIBLIOGRAPHY 3

2. Wikipedia http://en.wikipedia.org/wiki/Relaxation method

3. Wikipedia http://en.wikipedia.org/wiki/Poisson equation

chapter 2

THE GAME OF LIFE

2.1 Overview

The goal of this project is to simulate the evolution of a living populationwhich follows a small set of simple rules. Depending on the initial condi-tions, different geometrical patterns emerge and evolve. The game of life is‘played’ on a regular grid, where each cell contains either 1 or 0. Each cellhas 8 neighbours and let N1 be the number of neighbours equal to 1.

Figure 2.1: Three successive patterns in a game of life. Note that somepatterns are stationary, others are moving and some are oscillatory.

The rules are :

• if N1 < 2 the cell is set to 0

5

6 CHAPTER 2. THE GAME OF LIFE

• if N1 > 3 the cell is set to 0

• if 2 ≤ N1 ≤ 3 and the cell is equal to 1, it remains unchanged

• if N1 = 3 and the cell is equal to 0, its value is changed to 1

2.2 Technique

This project does not require specific techniques or methods. Basically thegrid should be considered as a 2D array and its values are tested againstthe different rules.

Also, the boundary conditions (BC) should be considered with caution.At first, using fixed boundary conditions is the easiest path toward a func-tionnal program. Usually BC are take in account using a ‘ghost layer’ whichencompasses the computational domain. By assigning a fixed value to thesecells, one creates easily fixed BC. This method can easily be extended toperiodic, transmissive or reflexive boundary conditions.

Several options are possible for the display. At first, the code maydisplay the evolving grid directly in the terminal, but fancier displays maywork using third party software.

2.3 Goals

The objective is to write a C code which plays the Game of Life. The basicrequirement is to make it work and display the result on the terminal. Oncefunctionnal, the code should be modified to work in a Yorick environment.

Among the questions that can be investigated, the student should lookat the way boundary conditions modify the evolution of the patterns, howdifferent initial conditions seed different patterns or are there stationnarypatterns ?

2.4 Bibliography

1. Wikipedia http://en.wikipedia.org/wiki/Conway%27s Game of Life

2. a Java implementation http://www.bitstorm.org/gameoflife/

chapter 3

PROPERTIES OF THE RANDOM WALK

3.1 Overview

We aim at simulating the random walk process in 1D and 2D on cartesiannetworks. In 1D, the process is quite simple. Starting from an origin atx = 0, a point performs N steps and at each step it may increase itsposition by +1 or -1 with equal probabilities. In 2D, the process is identicalexcept the number of options is larger, with four posible directions if thedisplacements are constrained to occur on a grid. In any case, all thedirections have the same probability to occur. Theoretically speaking therandom walk process is well known and is involved in various processes suchas brownian motion or merger histories of galaxies.

Figure 3.1: examples of 2D random walks

3.2 Technique

Simulating random motions naturally deals with random generation of num-bers and a way to generate directions from two or four options must befound. Since all the directions are equiprobable, it should not be difficult.

7

8 CHAPTER 3. PROPERTIES OF THE RANDOM WALK

The current project also aims at finding the statistical properties ofthe walks, therefore the project should contain functions which are able tocompute the mean or the dispersion of values.

Visualisation is important : first to actually ‘see’ the random walks andsecond, to investigate the statistics of the random tracks.

3.3 Goals

The goal of the project is to simulate 1D and 2D random walks and investi-gate their statistical properties. The C code should be able to perform thewalks and calculate the mean and the dispersion of the different realisationsaround the origin. These statistical values are well known and can be foundin the litterature. Of course, the results from the code should be consistentwith the theoretical expectations.

If possible, the results should be visualized (the walk themselves, thedistributions of the final positions,etc...)

3.4 Bibliography

1. Wikipedia http://en.wikipedia.org/wiki/Random walk

2. Wikipedia http://en.wikipedia.org/wiki/Brownian motion

3. Wikipedia http://en.wikipedia.org/wiki/Binomial distribution

4. Wikipedia http://en.wikipedia.org/wiki/Normal distribution

chapter 4

TEXT ANALYSIS

4.1 Overview

This project aims at analysing texts and produce some statistics on them. Inparticular, is it possible for a computer program to guess if a text is writtenin French or in English ? These two languages differ by the frequency of thedifferent letters, by the average length of words or the number of words persentences. Consequently, by a proper analysis of the properties of a text, itshould be possible to guess the right answer with little error.

For example, the most common letters in French are e, s, a, i, t, nwhile in English those are e, a, o, i, t, n.

Figure 4.1: Histograms of the probability of finding a given letter in twotexts, one in English (left), the other in French(right).

9

10 CHAPTER 4. TEXT ANALYSIS

4.2 Technique

This project heavily relies on the manipulation of string objects. Thereforethe C code should be able to read a text (provided by the user) and extractstatistical properties about it. To extract these properties, one should befamiliar with the calculation of dispersions, average values and also withthe calculation of histograms. Finally, if theoretical data points have to beused, one should wonder how to include them properly in the project.

4.3 Goal

Write a C project which takes an arbitrary text as an input provided by theuser and analyse it. The code should return various statistics on the text aswell as the probability of finding a given letter in this text. By comparingit with theoretical expectations, the code should be able to discriminatebetween English and French language.

4.4 Bibliography

1. some advanced techniques http://www.xs4all.nl/∼ajwp/langident.pdf

2. Wikipedia. About the frequency of letters: http://en.wikipedia.

org/wiki/Letter frequency or http://fr.wikipedia.org/wiki/

Fr%C3%A9quence d%27apparition des lettres en fran%C3%A7ais

chapter 5

THREE-BODY PROBLEM

5.1 Overview

This project aims at studying the trajectories of three massive points whichinteract with each others through gravitation. This ‘problem’ is famous forbeing unpredictable and even chaotic. Mathematically speaking, it relies onthe resolution of first-order equations by a technique called ‘Runge-Kutta’.

Figure 5.1: An example of orbits for 3 bodies interacting through gravita-tion.

11

12 CHAPTER 5. THREE-BODY PROBLEM

5.2 Technique

The equation of motions of a massive point (1) interacting with two others(2) and (3) can be written as

d~r1

dt= ~v1 (5.1)

d~v1

dt=

Gm2

r212

~u12 +Gm3

r213

~u13 (5.2)

which can be rewritten as a first order differential equation:

d~y1

dt= f(~r1, ~r2, ~r3). (5.3)

Here, ~y stands as a six-element array defined by ~y = (~r,~v) and f is thefunction which reproduces the system 5.1 and 5.2. The 4th order Runge-Kutta technique solves this differential equation by providing the solutionyn+1 at timestep n + 1 from the state of the system yn at timestep n:

k1 = ∆t× f(yn) (5.4)

k2 = ∆t× f(yn +1

2k1) (5.5)

k3 = ∆t× f(yn +1

2k2) (5.6)

k4 = ∆t× f(yn +1

2k3) (5.7)

yn+1 = yn +k1

6+

k2

3+

k3

3+

k4

6. (5.8)

The smaller the timestep ∆t, the more accurate is the solution.

5.3 Goals

Write a C code which calculate the orbits of three bodies interacting witheach other through gravitation using the RK4 technique. The consistancyof the code should be tested against well-known cases such as circular orbits.The conservation of energy should also be tested.

Once the code is fully functionnal several experiments are possible :investigate the ‘chaotic’ nature of the situation by slowly varying the initialconditions, investigate the perturbations of an orbiting body due to a thirdmember, experiment ‘collisions’, etc...

5.4. BIBLIOGRAPHY 13

5.4 Bibliography

1. Numerical Recipes http://www.nrbook.com/a/bookcpdf.php Chap-ter 16.

2. Wikipedia http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta

methods

3. Wikipedia http://en.wikipedia.org/wiki/N-body problem

4. Wikipedia http://en.wikipedia.org/wiki/N-body simulation

chapter 6

SORTING COMPETITION

6.1 Overview

There exists a whole litterature of sorting algorithms :bubble sort, heapsort, straight insertion, shell sort, quicksort, etc... Their efficiency is alsoextremely variable and depends on the size and on the level of initial sortin the data. Some methods are also extremely stable while others may havean efficiency which is highly data-dependent. In this project, we aim atcoding and testing several sorting techniques.

6.2 Technique

No special technique is needed but a good understanding of the algorithmsis required to make them work. It would be valuable to write a functionwhich easily generates random arrays and displays them. Also, it wouldbe interesting to use the intrinsic function which measures the time spentin the calculations in order to compare the different algorithms. Finally,the scaling laws of the different algorithms (as a function of the number ofelements to sort) are documented and a mean to plot the experimental lawsshould be envisionned.

6.3 Goals

The current project should at least contain the following sorting algorithms:

• simple sort (seen during the first semester)

• straight insertion

• shell sort

• bubble sort

• quicksort

15

16 CHAPTER 6. SORTING COMPETITION

Figure 6.1: Timings for different kind of sorts

Compare their execution time, their efficiency on special sets (reversed or-der, already ordered arrays) of data and plot their scaling laws. Othersorting techniques can also be studied.

6.4 Bilbiography

1. Wikipedia http://en.wikipedia.org/wiki/Quicksort and referencestherein

2. http://www.cerfacs.fr/∼gondet/performance/clock.html

chapter 7

FRACTALS

7.1 Overview

This project aims at generating famous fractals in the complex plane. Thesefractals will be part of the ‘chaosbrot family’ which result from simple iter-ation relations. The most famous one is the also the simplest and is calledthe Mandelbrot set. Of course, this project involves visualisation of thisuncommon mathematical objects.

If we consider a complex number c and compute the following series:

zn+1 = |zn|2 + c (7.1)

the number c is said to belong to the set of Mandelbrot if

limn→∞

|zn| < ∞. (7.2)

If this test is performed for all the numbers in the complex plane, the famousMandelbrot figure arise. Different series lead to different fractals, such as:

zn+1 = |zn|2 + p(Re(z)Im(z)) + c (7.3)

where the Mandelbrot set corresponds to p = 0.

Figure 7.1: Three type of fractals. Black pixels correspond to points inthe complex plane which belong to a fractal set. The leftmost one is theMandelbrot set.

17

18 CHAPTER 7. FRACTALS

7.2 Technique

The project relies on complex arithmetic which can be treated through thecomplex.h library or built from scratch. The recursion relation 7.1 andthe condition 7.2 must be applied with caution : infinity is meaningless incomputer science, thus arbitrary thresholds must be chosen, maybe aftersome experimentations.

7.3 Goals

Construct and displays the Mandelbrot set in the complex plane. Practi-cally the result should be a plane, filled with 0 and 1, stating if a pointbelongs or not to the fractal set. Once this code is functionnal, constructother fractals ensemble following the same route. For example, one couldlook after the ‘Chaosbrot’ family.

7.4 Bibliography

1. Wikipedia http://en.wikipedia.org/wiki/Mandelbrot set and ref-erences therein

2. Wikipedia http://en.wikipedia.org/wiki/Complex.h for the com-plex library

chapter 8

TIC-TAC-TOE

8.1 Overview

This project aims at building a Tic-Tac-Toe game, written in C and playableby two human players. The rules are simple : the first player who manageto align three symbols wins. The game should be able to say who the winneris, if a draw occurs, and if fordbidden moves are made by the players.

Figure 8.1: The game may look like this...

8.2 Technique

The display should be performed in the Terminal. The C code must enforcethe rules and prevent the players to choose forbidden options. Special careshould be taken for the victory conditions.

If artificial intelligence is being considered, keep in mind that the numberof options is limited and finding the ‘best move’ should not be too difficult.

19

20 CHAPTER 8. TIC-TAC-TOE

8.3 Goals

Write a playable game ! Among the possible extensions, one can think of anartificial intelligence, where a human player plays against the computer ormodifying the Tic-Tac-Toe game to make it a ‘Puissance 4’ which is slightlydifferent.

8.4 Bibliography

1. There are tons of implementations of this game on the web. Justgoogle tic-tac-toe.

chapter 9

BITMAP MANIPULATION

9.1 Overview

The purpose of this project is to manipulate Bitmap images and constructsome statistics out of it. Bitmap are simple to read in C, and easy tounderstand in terms of structure. Because this image format is simple, itis also quite easy to manipulate them such as modify the color, reversingthem, etc...

Figure 9.1: A spiral picture modified using a simple C code. Left: theoriginal picture. Middle: exchanged channels. Right: reversed channels.

9.2 Technique

The bitmap format is well documented on the web. By following carefullythe standard data structure of this file, the data can be stored in an arrayand modified. The reading (and writing) of the .bmp file is performedusing the usual techniques of binary files manipulations. Structures can beused, since they provide a straightforward way to read a bunch of data atonce and are easier to manipulate than a collection of fields. Finally, it isrecommended to use 24-bits images since they are the easiest to manipulateas each color (Red Blue Green) channel has been separated.

21

22 CHAPTER 9. BITMAP MANIPULATION

9.3 Goals

Write a C code which is able to read a bitmap file. Once functional, ma-nipulate several images and reverse their color, saturate them, modify thecontrast, turn them black and white, etc... Also, some statistical studiescan be done on these images, in particular investigate the distribution ofcolors in different kind of pictures(portrait, landscape, object, etc...).

9.4 Bibliography

1. Wikipedia http://en.wikipedia.org/wiki/BMP file format. Ev-erything about the file format can be found on this page.

2. Test images here http://wvnvaxa.wvnet.edu/vmswww/bmp.html

chapter 10

MODELS OF GALAXIES AND CLUSTERS

10.1 Overview

Figure 10.1: Two distribution of stars. Left : a globular cluster (Plummermodel). Right : a galactic bulge Hernquist model.

Astronomers use so-called ‘dynamical models’ to study the dynamicalproperties of galaxies. These models are described by density profiles ρ(r)which detail how the matter is distributed within these objects as functionof the distance to the center of the galaxy. Two of the most common onesare the Plummer model and the Hernquist Model. The Plummer model isdefined by a polytropic density profile:

ρ(r) =ρ0

(1 + (r/a)2)5/2(10.1)

and is good approximation for the distribution of stars within globular clus-ters. The Hernquist profile is slightly different:

ρ(r) =M

a

r

1

(1 + r/a)3(10.2)

which in turn provides a good description for clusters of galaxies. In thecurrent projet, we aim at writing a C code which creates distributions ofstars following these simple laws. Simple properties of these models suchas the mass profile or the circular velocity curve will also be investigated.

23

24 CHAPTER 10. MODELS OF GALAXIES AND CLUSTERS

10.2 Technique

The code must generate the positions of stars with a given density profile.Since the density profiles ρ(r) give the amount of stars found at a givendistance of the center of the cluster ,they can be considered as probabilities.Several methods exist to draw events which follow an arbitrary distribution.The simplest is the rejection method. Basically, this method is equivalent todrawing randomly points in a 2D plane with the constrain that they mustfall under the probability curve.

Some properties of the profile require to compute integrals of the densitydistribution. These integrals can be computed using the simple extendedSimpson’s or extended Trapeziodal rules.

10.3 Goals

Write a C code which computes a 3D distribution of stars which follow thePlummer and Hernquist density profiles. For each of this model this C codeshould also calculate the mass profile:

M(r) =

∫ r

0

ρ(r)4πr2dr (10.3)

and the circular velocity curve

Vc(r) =

√M(r)

r(10.4)

Compare the two models in their appearance and dynamical properties,investigate the effect of the number of stars.

10.4 Bibliography

1. Wikipedia a simple technique to generate numbers following an ar-bitary PDF http://en.wikipedia.org/wiki/Rejection sampling

2. Wikipedia a more sophisticated one http://en.wikipedia.org/wiki/Inverse transform sampling

3. G. Mamon Webpage. Chapter 8 http://www2.iap.fr/users/gam/

M2/CT2/VIII Simulations numeriques.html