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φ ∂2φ + = ρ(x, y) ∂x2 ∂y 2 (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 2 CHAPTER 1. POISSON EQUATION 1.2 Technique In two dimensions, the Poisson equation can easily be solved on a grid using a finite difference scheme such as: ∆φ ∼ Φi+1,j + Φi−1,j + Φi,j+1 + Φi,j−1 − 4Φi,j ∆X 2 (1.4) where Φi,j stands for the potential at the grid point (i, j) and ∆X is the size of a cell. Hence Φi+1,j + Φi−1,j + Φi,j+1 + Φi,j−1 − 4Φi,j = ρi,j . ∆X 2 (1.5) Solving for Φi,j leads to: Φi,j = Φi+1,j + Φi−1,j + Φi,j+1 + Φi,j−1 − ρi,j ∆X 2 4 (1.6) The Jacobi’s iteration technique approximates Φi,j from successive calculations: Φp+1 i,j = Φpi+1,j + Φpi−1,j + Φpi,j+1 + Φpi,j−1 − ρi,j ∆X 2 4 (1.7) where Φp is the potential at iteration p and Φp+1 at potential at the next iteration. As the number of iterations increases, the approximation Φp converges toward the correct value as: lim Φp = Φ p→+∞ 1.3 (1.8) Goals The main objective of this project is to write a C code which computes the potential on a 2D Grid for an arbitrary density using Jacobi’s iteration technique. In order to check the consistency of the result, the potentials should be visualised. Once the code is working, other techniques could be tested such as the Gauss-Seidel and successive over relaxation (SOR) iterative methods. In particular, the efficiency of the three methods could be compared. 1.4 Bibliography 1. Numerical Recipes http://www.nrbook.com/a/bookcpdf.php. Chapter 17. 1.4. BIBLIOGRAPHY 2. Wikipedia http://en.wikipedia.org/wiki/Relaxation method 3. Wikipedia http://en.wikipedia.org/wiki/Poisson equation 3 chapter 2 THE GAME OF LIFE 2.1 Overview The goal of this project is to simulate the evolution of a living population which follows a small set of simple rules. Depending on the initial conditions, 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 cell has 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 some patterns 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 the grid should be considered as a 2D array and its values are tested against the different rules. Also, the boundary conditions (BC) should be considered with caution. At first, using fixed boundary conditions is the easiest path toward a functionnal program. Usually BC are take in account using a ‘ghost layer’ which encompasses the computational domain. By assigning a fixed value to these cells, one creates easily fixed BC. This method can easily be extended to periodic, transmissive or reflexive boundary conditions. Several options are possible for the display. At first, the code may display the evolving grid directly in the terminal, but fancier displays may work using third party software. 2.3 Goals The objective is to write a C code which plays the Game of Life. The basic requirement is to make it work and display the result on the terminal. Once functionnal, the code should be modified to work in a Yorick environment. Among the questions that can be investigated, the student should look at the way boundary conditions modify the evolution of the patterns, how different initial conditions seed different patterns or are there stationnary patterns ? 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 cartesian networks. In 1D, the process is quite simple. Starting from an origin at x = 0, a point performs N steps and at each step it may increase its position by +1 or -1 with equal probabilities. In 2D, the process is identical except the number of options is larger, with four posible directions if the displacements are constrained to occur on a grid. In any case, all the directions have the same probability to occur. Theoretically speaking the random walk process is well known and is involved in various processes such as 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 numbers and a way to generate directions from two or four options must be found. 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 of the walks, therefore the project should contain functions which are able to compute the mean or the dispersion of values. Visualisation is important : first to actually ‘see’ the random walks and second, 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 investigate their statistical properties. The C code should be able to perform the walks and calculate the mean and the dispersion of the different realisations around the origin. These statistical values are well known and can be found in the litterature. Of course, the results from the code should be consistent with the theoretical expectations. If possible, the results should be visualized (the walk themselves, the distributions 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. In particular, is it possible for a computer program to guess if a text is written in French or in English ? These two languages differ by the frequency of the different letters, by the average length of words or the number of words per sentences. Consequently, by a proper analysis of the properties of a text, it should be possible to guess the right answer with little error. For example, the most common letters in French are e, s, a, i, t, n while in English those are e, a, o, i, t, n. Figure 4.1: Histograms of the probability of finding a given letter in two texts, 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. Therefore the C code should be able to read a text (provided by the user) and extract statistical properties about it. To extract these properties, one should be familiar with the calculation of dispersions, average values and also with the calculation of histograms. Finally, if theoretical data points have to be used, 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 the user and analyse it. The code should return various statistics on the text as well as the probability of finding a given letter in this text. By comparing it with theoretical expectations, the code should be able to discriminate between 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 which interact with each others through gravitation. This ‘problem’ is famous for being unpredictable and even chaotic. Mathematically speaking, it relies on the resolution of first-order equations by a technique called ‘Runge-Kutta’. Figure 5.1: An example of orbits for 3 bodies interacting through gravitation. 11 12 5.2 CHAPTER 5. THREE-BODY PROBLEM Technique The equation of motions of a massive point (1) interacting with two others (2) and (3) can be written as d~r1 = ~v1 dt Gm3 Gm2 d~v1 = ~u12 + 2 ~u13 2 dt r12 r13 (5.1) (5.2) which can be rewritten as a first order differential equation: d~y1 = f (~r1 , ~r2 , ~r3 ). dt (5.3) Here, ~y stands as a six-element array defined by ~y = (~r, ~v ) and f is the function which reproduces the system 5.1 and 5.2. The 4th order RungeKutta technique solves this differential equation by providing the solution yn+1 at timestep n + 1 from the state of the system yn at timestep n: k1 = ∆t × f (yn ) 1 k2 = ∆t × f (yn + k1 ) 2 1 k3 = ∆t × f (yn + k2 ) 2 1 k4 = ∆t × f (yn + k3 ) 2 k1 k2 k3 k4 yn+1 = yn + + + + . 6 3 3 6 (5.4) (5.5) (5.6) (5.7) (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 with each other through gravitation using the RK4 technique. The consistancy of 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 initial conditions, investigate the perturbations of an orbiting body due to a third member, experiment ‘collisions’, etc... 5.4. BIBLIOGRAPHY 5.4 13 Bibliography 1. Numerical Recipes http://www.nrbook.com/a/bookcpdf.php Chapter 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, heap sort, straight insertion, shell sort, quicksort, etc... Their efficiency is also extremely variable and depends on the size and on the level of initial sort in the data. Some methods are also extremely stable while others may have an efficiency which is highly data-dependent. In this project, we aim at coding and testing several sorting techniques. 6.2 Technique No special technique is needed but a good understanding of the algorithms is required to make them work. It would be valuable to write a function which easily generates random arrays and displays them. Also, it would be interesting to use the intrinsic function which measures the time spent in the calculations in order to compare the different algorithms. Finally, the scaling laws of the different algorithms (as a function of the number of elements to sort) are documented and a mean to plot the experimental laws should 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 order, already ordered arrays) of data and plot their scaling laws. Other sorting techniques can also be studied. 6.4 Bilbiography 1. Wikipedia http://en.wikipedia.org/wiki/Quicksort and references therein 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. These fractals will be part of the ‘chaosbrot family’ which result from simple iteration relations. The most famous one is the also the simplest and is called the Mandelbrot set. Of course, this project involves visualisation of this uncommon 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 lim |zn | < ∞. n→∞ (7.2) If this test is performed for all the numbers in the complex plane, the famous Mandelbrot 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 in the complex plane which belong to a fractal set. The leftmost one is the Mandelbrot set. 17 18 CHAPTER 7. FRACTALS 7.2 Technique The project relies on complex arithmetic which can be treated through the complex.h library or built from scratch. The recursion relation 7.1 and the condition 7.2 must be applied with caution : infinity is meaningless in computer science, thus arbitrary thresholds must be chosen, maybe after some experimentations. 7.3 Goals Construct and displays the Mandelbrot set in the complex plane. Practically the result should be a plane, filled with 0 and 1, stating if a point belongs or not to the fractal set. Once this code is functionnal, construct other fractals ensemble following the same route. For example, one could look after the ‘Chaosbrot’ family. 7.4 Bibliography 1. Wikipedia http://en.wikipedia.org/wiki/Mandelbrot set and references therein 2. Wikipedia http://en.wikipedia.org/wiki/Complex.h for the complex library chapter 8 TIC-TAC-TOE 8.1 Overview This project aims at building a Tic-Tac-Toe game, written in C and playable by two human players. The rules are simple : the first player who manage to align three symbols wins. The game should be able to say who the winner is, 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 enforce the rules and prevent the players to choose forbidden options. Special care should be taken for the victory conditions. If artificial intelligence is being considered, keep in mind that the number of 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 an artificial intelligence, where a human player plays against the computer or modifying the Tic-Tac-Toe game to make it a ‘Puissance 4’ which is slightly different. 8.4 Bibliography 1. There are tons of implementations of this game on the web. Just google tic-tac-toe. chapter 9 BITMAP MANIPULATION 9.1 Overview The purpose of this project is to manipulate Bitmap images and construct some statistics out of it. Bitmap are simple to read in C, and easy to understand in terms of structure. Because this image format is simple, it is also quite easy to manipulate them such as modify the color, reversing them, etc... Figure 9.1: A spiral picture modified using a simple C code. Left: the original picture. Middle: exchanged channels. Right: reversed channels. 9.2 Technique The bitmap format is well documented on the web. By following carefully the standard data structure of this file, the data can be stored in an array and modified. The reading (and writing) of the .bmp file is performed using the usual techniques of binary files manipulations. Structures can be used, since they provide a straightforward way to read a bunch of data at once and are easier to manipulate than a collection of fields. Finally, it is recommended to use 24-bits images since they are the easiest to manipulate as 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, manipulate several images and reverse their color, saturate them, modify the contrast, turn them black and white, etc... Also, some statistical studies can be done on these images, in particular investigate the distribution of colors in different kind of pictures(portrait, landscape, object, etc...). 9.4 Bibliography 1. Wikipedia http://en.wikipedia.org/wiki/BMP file format. Everything 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 (Plummer model). Right : a galactic bulge Hernquist model. Astronomers use so-called ‘dynamical models’ to study the dynamical properties of galaxies. These models are described by density profiles ρ(r) which detail how the matter is distributed within these objects as function of the distance to the center of the galaxy. Two of the most common ones are the Plummer model and the Hernquist Model. The Plummer model is defined by a polytropic density profile: ρ0 (10.1) ρ(r) = (1 + (r/a)2 )5/2 and is good approximation for the distribution of stars within globular clusters. The Hernquist profile is slightly different: ρ(r) = Ma 1 2π r (1 + r/a)3 (10.2) which in turn provides a good description for clusters of galaxies. In the current projet, we aim at writing a C code which creates distributions of stars following these simple laws. Simple properties of these models such as 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 given distance 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 to drawing randomly points in a 2D plane with the constrain that they must fall under the probability curve. Some properties of the profile require to compute integrals of the density distribution. These integrals can be computed using the simple extended Simpson’s or extended Trapeziodal rules. 10.3 Goals Write a C code which computes a 3D distribution of stars which follow the Plummer and Hernquist density profiles. For each of this model this C code should also calculate the mass profile: Z r M (r) = ρ(r)4πr2 dr (10.3) 0 and the circular velocity curve r 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 arbitary 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