comoving distance (dotted), light travel time distance (dashed), angular diameter distance (solid)
(black):
function flrw2(H0, OmegaL, OmegaM, maxZ) {
maxZ = maxZ || 10
//var OmegaM = 1 - OmegaL
var OmegaK = 1 - OmegaL - OmegaM + 1 - 1
var curv = Math.sqrt(Math.abs(OmegaK))
// convert km/s/Mpc to Mly/My/Mly
H0 = H0 / 3.08e19 * 60 * 60 * 24 * 365 * 1e6
var H = H0
var c = 1
var t = 0
var z = 0
// these are our photons, one has a head start
var x1 = 0.1
var x2 = 0
var xx = 0
var data = []
while (z < maxZ) {
// move the photons with the hubble flow (in reverse)
x1 += c - H * x1
x2 += c - H * x2
// the redshift is how far apart the photons have drifted
z = 0.1 / (x1 - x2) - 1
t--
xx = curv * x2 * (1+z)
if (1+OmegaK === 1) xx = x2
else if (OmegaK < 0) xx = 1/H0 * Math.sin(xx * H0) / xx * x2
else xx = 1/H0 * Math.sinh(xx * H0) / xx * x2
data.push({
z,
d_A: xx ,
d_C: x2 * (1+z),
d_T: -t,
})
// update the Hubble parameter
H = H0 * Math.sqrt(OmegaM * Math.pow(1 + z, 3) + OmegaL + OmegaK * Math.pow(1 + z, 2))
}
return data
}