Union 2 supernova  (http://supernova.lbl.gov/Union/)

Get data file from:

http://supernova.lbl.gov/Union/figures/SCPUnion2.1_mu _vs _z.txt

Needs["ErrorBarPlots`"]

c=3.00*10^8 m s^-1;

yr=365.25*(24*3600)s;

km=10^3 m;

pc=3.26*c*yr;

Mpc=10^6pc;

Gyr=10^9yr;

H0[h_]=100.km s^-1 Mpc^(-1)h

Load data from file

LD[μ_]:=(10^(0.2 μ+1))

LDe[μ_,δμ_]:=0.461 LD[μ]δμ (*error on luminosity dist from dist mod and its error*)

Print["\n\nFormat:  sn id,  Z,  dist mod μ,  err in μ\n\n"];

sndata=Import[StringJoin[NotebookDirectory[],"SCPUnion2.1_mu_vs_z.txt"],"Table"][[6;;-1]];

size=Length[sndata];

getZ[ii_]:=sndata[[ii,2]];

getμ[ii_]:=sndata[[ii,3]];

getμerr[ii_]:=sndata[[ii,4]];

getLd[ii_]:=LD[sndata[[ii,3]]];

getLderr[ii_]:=LDe[sndata[[ii,3]],sndata[[ii,4]]];

datafit=Table[{getZ[ii],getLd[ii]},{ii,1,size}];

dataweights=Table[1/getLderr[ii]^2,{ii,1,size}];

Plots from data

Print["\n\nμ vs Z\n"]

ErrorListPlot[Table[{getZ[ii],getμ[ii],getμerr[ii]},{ii,1,size}]]

Print["\n\nLd (/pc) vs Z\n"]

dataplt=ErrorListPlot[Table[{getZ[ii],getLd[ii],getLderr[ii]},{ii,1,size}]]

Estimate cosmological parameters: Flat universe

dL[z_,h_,ΩM_]=c((1+z)/( H0[h]))*FullSimplify[Integrate[(1/(x^2Sqrt[(1-ΩM)+((ΩM)/(x^3))])),{x,(1/(1+z)),1}],{1>ΩM>0,z>0}]

Age[h_,ΩM_]=(1/( H0[h]))*FullSimplify[Integrate[(1/(x Sqrt[(1-ΩM)+((ΩM)/(x^3))])),{x,0,1}],{1>ΩM>0,z>0}]

Horizon[h_,ΩM_]=(1/( H0[h]))*FullSimplify[Integrate[(1/(x^2 Sqrt[(1-ΩM)+((ΩM)/(x^3))])),{x,0,1}],{1>ΩM>0,z>0}]

EventHorizon[h_,ΩM_]=(1/( H0[h]))*FullSimplify[Integrate[(1/(x^2 Sqrt[(1-ΩM)+((ΩM)/(x^3))])),{x,0,∞}],{1>ΩM>0,z>0}]

TimeAgonum[z_Real,h_Real,ΩM_Real]:=(1/( H0[h]))*NIntegrate[(1/(x Sqrt[(1-ΩM)+((ΩM)/(x^3))])),{x,(1/(1+z)),1}]

datafit=Table[{getZ[ii],getLd[ii]},{ii,1,size}];

dataweights=Table[1/getLderr[ii]^2,{ii,1,size}];

fit=NonlinearModelFit[datafit,(1/pc)*dL[z,h,ΩM],{{h,0.7},{ΩM,0.3}},z,Weights->dataweights];

param=fit["BestFitParameters"];

Print["\n\nBest fit parameters = ",param];

Print["\n\n95% confidence:     = ",fit["ParameterConfidenceIntervals",ConfidenceLevel->.95],"\n\n"];

Print["\n\n   h  = ",h/.param," +- ",fit["ParameterConfidenceIntervals",ConfidenceLevel->.95][[1,2]]-h/.param];

Print["\n\n   ΩM = ",ΩM/.param," +- ",fit["ParameterConfidenceIntervals",ConfidenceLevel->.95][[2,2]]-ΩM/.param,"\n\n"];

fitplt=Plot[fit[z],{z,0,1.5},PlotStyle->{Hue[0],Thickness[0.007]}];

Print["\n\nAge of universe (/Gyr) = ",(1/Gyr)Age[h,ΩM]/.param,"\n\nΩΛ = ",1-ΩM/.param,"\n\n"];

Print["\n\nHorizon (/pc) = ",(c/pc) Horizon[h,ΩM]/.param,"\n\n"];

Print["\n\nHorizon (/lightyrs) = ",(1/(10^9yr)) Horizon[h,ΩM]/.param,"\n\n"];

Print["\n\nEvent Horizon (/pc) = ",(c/pc) EventHorizon[h,ΩM]/.param,"\n\n"];

AccZ=Solve[2(1-ΩM)==ΩM(1+z)^3/.param,z][[-1]]

AccTime=(1/Gyr)TimeAgonum[z,h,ΩM]/.param/.AccZ

EqZ=Solve[(1-ΩM)==ΩM(1+z)^3/.param,z][[-1]]

EqTime=(1/Gyr)TimeAgonum[z,h,ΩM]/.param/.EqZ

Show[dataplt,fitplt,AxesLabel->{"z","(Subscript[d, L])/pc"}]

Estimate cosmological parameters: Curved universe

dLnum[z_Real,h_Real,ΩM_Real,ΩΛ_Real]:=c((1+z)/( H0[h]))Chop[(1/(Sqrt[1-ΩM-ΩΛ]))Sinh[Sqrt[1-ΩM-ΩΛ]*NIntegrate[(1/(x^2Sqrt[ΩΛ+(((1-ΩM-ΩΛ))/(x^2))+((ΩM)/(x^3))])),{x,(1/(1+z)),1}]]]

Agenum[h_Real,ΩM_Real,ΩΛ_Real]:=(1/( H0[h]))*NIntegrate[(1/(x Sqrt[ΩΛ+(((1-ΩM-ΩΛ))/(x^2))+((ΩM)/(x^3))])),{x,0,1}]

TimeAgonum[z_Real,h_Real,ΩM_Real,ΩΛ_Real]:=(1/( H0[h]))*NIntegrate[(1/(x Sqrt[ΩΛ+(((1-ΩM-ΩΛ))/(x^2))+((ΩM)/(x^3))])),{x,(1/(1+z)),1}]

fit=NonlinearModelFit[datafit,(1/pc)*dLnum[z,h,ΩM,ΩΛ],{{h,0.7},{ΩM,0.28},{ΩΛ,0.71}},z,Weights->dataweights];

param=fit["BestFitParameters"];

Print["\n\nBest fit parameters = ",param];

Print["\n\n95% confidence:     = ",fit["ParameterConfidenceIntervals",ConfidenceLevel->.95],"\n\n"];

Print["\n\n   h  = ",h/.param," +- ",fit["ParameterConfidenceIntervals",ConfidenceLevel->.95][[1,2]]-h/.param];

Print["\n\n   ΩM = ",ΩM/.param," +- ",fit["ParameterConfidenceIntervals",ConfidenceLevel->.95][[2,2]]-ΩM/.param,"\n\n"];

Print["\n\n   ΩΛ = ",ΩΛ/.param," +- ",fit["ParameterConfidenceIntervals",ConfidenceLevel->.95][[2,2]]-ΩΛ/.param,"\n\n"];

fitplt=Plot[fit[z],{z,0,1.5},PlotStyle->{Hue[0],Thickness[0.007]}];

Print["\n\nAge of universe (/Gyr) = ",(1/Gyr)Agenum[h,ΩM,ΩΛ]/.param,"\n\nΩK = ",1-ΩM-ΩΛ/.param,"\n\n"];

AccZ=Solve[2ΩΛ==ΩM(1+z)^3/.param,z][[-1]]

AccTime=(1/Gyr)TimeAgonum[z,h,ΩM,ΩΛ]/.param/.AccZ

EqZ=Solve[ΩΛ==ΩM(1+z)^3/.param,z][[-1]]

EqTime=(1/Gyr)TimeAgonum[z,h,ΩM,ΩΛ]/.param/.EqZ

Show[dataplt,fitplt,AxesLabel->{"z","(Subscript[d, L])/pc"}]