Exercises lecture 4

ClearAll["Global`*"];SetDirectory[NotebookDirectory[]]

Exercise 1: Consider this list of points on a plane: points= {{1,6},{4,1.5},{0.5,2.5},{3,3},{1,5}}. Find by trying out systematically all permutations of the points the minimal path that starts from the origin, touches all the points once and comes back to the origin.
Check your result by using the built-in function  FindShortestTour. Plot the resulting path through the points.

Exercise 2: draw a contour plot of a 2 D Gaussian function Exp[-1/2*(x^2+y^2)], Then normalize numerically the Gaussian by integrating it in a region such that x^2 + y^2 < a, where a is big enough that the results is close to the normalization 2Pi of the Gaussian, then find by trial and error the value of a such that the integral of the normalized Gaussian contain 68% of the probability

Exercise 3: Open outside of Mathematica the external file Union2.1.dat (located at https://www.thphys.uni-heidelberg.de/~amendola/teaching/Union2.1.dat, which contains supernovae Ia data and examine its structure.
Read the file Union2.1.dat and make a plot of distance modulus dm, defined as m-M=25+5Log[dL], versus redshift, including errorbars from the fourth column (sigma). Then use the expressions below to find the luminosity distance in a LCDM model, and evaluate the chisquare (dm-dL)^2/sigma^2 summed over every SNIa. Then find the best value of Omega_matter (assuming Omega_Lambda=1-Omega_matter) by minimizing the chisquare over a grid of Omega_matter values. Optional: find the confidence region for Omega_matter.

h=0.7;h0=1/3000*h;
hub[z_,omegaM_,omegaL_]:=h0 (Sqrt[omegaL+(1-omegaM-omegaL)(((1+z))^2)+omegaM(((1+z))^3)]);
(* luminosity distance in Mpc: *)
dLum[z_,omegaM_,omegaL_]:=(1+z)NIntegrate[(1/(hub[zz,omegaM,omegaL])),{zz,0,z},PrecisionGoal->5,AccuracyGoal->5]; 
(* theoretical distance modulus as a function of z, omega_matter, omega_lambda *)
dModTeo[z_,omegaM_,omegaL_]:=25+5*Log10[dLum[z,omegaM,omegaL]];

Exercise 4: Define a function f[lx,ly,lab1,lab2,s] that produces a plot of two functions (eg two polynomials) with a legend placed at position lx,ly carrying labels lab1, lab2 and with frame fonts of size s

Exercise 5: Find the Ricci scalar for a 3D spatial non-flat metric. You can use one or both of the following forms

Cartesian coordinates

Clear[metric];
metric:=DiagonalMatrix[
a^2*{1,1,1}/(1+k/4*(x^2+y^2+z^2))^2]

coord={x,y,z};

Spherical coordinates

Clear[metric];
metric:=DiagonalMatrix[
a^2*{1/(1-k*r^2),r^2,r^2*Sin[theta]^2}]

coord={r,theta,phi};