Exercises lecture 6

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

Exercise 1: 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_,Ωm0_,ΩΛ0_]:=h0 (Sqrt[ΩΛ0+(1-Ωm0-ΩΛ0)(((1+z))^2)+Ωm0(((1+z))^3)]);
(* luminosity distance in Mpc: *)
dLum[z_,Ωm0_,ΩΛ0_]:=(1+z)NIntegrate[(1/(hub[zz,Ωm0,ΩΛ0])),{zz,0,z},PrecisionGoal->5,AccuracyGoal->5]; 
(* theoretical distance modulus as a function of z, omega_matter, omega_lambda *)
dModTeo[z_,Ωm0_,ΩΛ0_]:=25+5*Log10[dLum[z,Ωm0,ΩΛ0]];

Exercise 2: 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