Introduction to Mathematica SS 2023.

Solve two of the following three exercises.

Exercise 1. Central limit theorem.

Exercise 1. Verify the Central Limit Theorem. Generate nx random variates distributed uniformly within - 1, 1. Call y the sum of these variables . Generate a large number ny  (eg 10000) of such y variates . Find the mean and variance for the y variates . Show graphically  (eg using Histogram) that for increasing nx  the distribution of y approximates a Gaussian with the appropriate mean and variance. Optional: repeat for different distributions (not Gaussian) of the nx variates.

Exercise 2. A Three-body problem.

Exercise 2. Three - body problem. Evolve three masses under their own gravity on a plane. Plot the resulting trajectory (Optional: you might use an Animation or a a Manipulate command to visualize the trajectories). You can use DSolve but also, perhaps more easily, perform a Do in which for every time step you calculate the force on body A from the other two bodies, then the acceleration,  then the velocity, and finally the new positions of A, with little time increments, and repeat for every body. In this way you can  build a list of positions to be plotted. Use the constants below.

(*Define the gravitational constant*)

G=6.67430*10^(-11); (*m^3 kg^(-1) s^(-2)*)

(*Define the masses of the bodies*)
m1=5*10^7; (*Mass of body 1 in kg*)
m2=3*10^7; (*Mass of body 2 in kg*)
m3=4*10^7; (*Mass of body 3 in kg*)

(*Define the initial positions and velocities of the bodies*)
pos1={1,0}; (*Initial position of body 1 in meters*)
pos2={-1,0}; (*Initial position of body 2 in meters*)
pos3={0,1}; (*Initial position of body 3 in meters*)
vel1={0,0}; (*Initial velocity of body 1 in m/s*)
vel2={0,0}; (*Initial velocity of body 2 in m/s*)
vel3={0,0}; (*Initial velocity of body 3 in m/s*)

(*Define the time step and total time*)
dt=0.01; (*Time step in seconds*)
totalTime=200; (*Total simulation time in seconds*)

Exercise 3. MonteCarlo integration.

3. Define the function f (x) as below . Plot it in the interval (0, 3). Integrate f(x) inside this range. Find numerically the maximum f_max of f(x) within the range (0,3). Write a code that generate 10^N random points uniformly distributed  in the rectangular region defined by x between (0,3) and y betwen 0 and f_max and counts how many points are below f(x). Plot the points below f(x) and the function itself for a couple values of N, e.g. N=2 and N=4 or create a Manipulate command showing the plot when varying N. The ratio of points below f(x) and the total number of random points 10^N, multiplied by the total area of the rectangular region, should approximate the exact integral of f(x) between 0 and 3 (MonteCarlo integration). Plot the result of the MonteCarlo integration as a function of N and show graphically that it converges to the  true value for N increasing from 1 to 5 or more.

Clear[f];f[x_]=Sin[x]*Exp[-x^2];