Exercises lecture 6

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

Exercise 1: This exercise require you to dig a bit into Mathematica documentation. There is a database of earthquakes that can be retrieved with EarthquakeData[location,magnitude range, time range].
Use this data to draw a map of earthquake locations above magnitude 3 in Germany in the last 20 years. (You can vary the country and the magnitude and time range at will). Optional: define a function that maps eartquakes for any country, in any time range, for any magnitude range.

Hints :
 - to input Germany as location you need to use Polygon[CountryData["Germany"]]
 - the output of the command EarthquakeData, let’s call it “quakes”, is a construct called an association (see https://reference.wolfram.com/language/ref/Association.html ) of the type <|a -> x, b -> y, c -> z|> in which the value x is associated to the key a, the value y is associated to the key b, etc.  We need to extract the value associated to the key “Position”. To do so, you need to apply the pure function #[“Position”] to the output “quakes”, using this form  #[“Position”]}&/@quakes

Exercise 2 .
 Recently, a survey called DESI (see 2404.03002) found the cosmological distances d(z) for several redshifts given in the list desi: first colum= redshift; second column=distance D_H/r_d=x1; third column= distance D_M/r_d=x2. (The first distance is a  Hubble distance, the second one is the angular diameter distance.) The second list, desierr, reports the redshift, the rms error on x1 (e1), the rms error on x2 (e2), and the correlation coefficient (r) between the two errors. The covariance matrix at each redshift is then
 C= {{e1^2,r*e1*e2}, {r*e1*e2,e2^2}}
 1) At every point, the region that defines the confidence region at 1sigma is given by an ellipse with semiaxes along the eigenvectors of C and length equal to 1.51 times the square root of the eigenvalues of C . You can use the graphic command Ellipsoid with a Sigma matrix equal to 1.51^2 C. Plot the confidence regions for every redshift. You should obtain something like the figure below (in the figure, also the 2sigma contours are displayed).
 2) Now take only the column of x1. Fit the points {z,x1} with the standard cosmological model Lambda CDM, according to which
 x1(z)=a/Sqrt[(Subscript[Ω, m])*(1+z)^3+1-(Subscript[Ω, m])]
 You have two free parameters: a and (Subscript[Ω, m]). Use the form of NonlinearModelFit that allows for the constraints a>0 and 0<om<1. Which values of a and (Subscript[Ω, m]) do you get? (a is in fact 1/H_0/r_d, where r_d is the sound horizon).

desi={{0.51,20.98,13.62},{0.71,20.08,16.85},{0.93,17.88,21.71},{1.32,13.82,27.79},{2.33,8.52,39.71}};
desierr={{0.51,0.61,0.25,-0.445},{0.71,0.6,0.32,-0.42},{0.93,0.35,0.28,-0.389},{1.32,0.42,0.69,-0.444},{2.33,0.17,0.94,-0.477}};

Exercise 3. Use Manipulate to visualize how the PDF and the CDF of the chi-squared distribution change with the number of degrees of freedom