Objective:¶
This Lab will help you develop and practice your ability to write Python functions in the context of cosmology.
Background: Hubble’s Law¶
Hubble’s Law describes the relationship between the velocity of a galaxy and its distance from us:
where is is the recession velocity of a galaxy (in km/s), is the Hubble constant (in km/s/Mpc, assume 70 km/s/Mpc), and is the distance of the galaxy (in Mpc). is the present-day expansion rate of the universe. In general, we cannot measure direct distances to very distant galaxies, and so we measure the recessional velocity and can use that to find . The fact that this correlation exists is a consequence of the fact that our universe is expanding.
Questions 5-6 above get at a core concept in Python: vectorization. In Python, it will essentially always be faster to carry out an operation over a vector (array) simultaneously (part 5) as opposed to using a loop (part 4). This might not matter for small datasets but will become increasingly relevant as your dataset grows.
Now, we can make it even more sophisticated! We will now build subsequent functions that expand upon the one above. This incremental function-building is a core component of research, since you rarely write a single function that does everything you want.
Background: The Cosmic Critical Density¶
The cosmic critical density is the average density of matter and energy needed for the universe to be flat. If the actual density is higher, the universe is “closed” may eventually collapse; if the density is lower, the universe is “open” and will expand forever. It can be calculated from the Hubble Constant via
Background: The Age of the Universe¶
Because the universe has been continuously expanding since the origin of the universe, the present-day expansion rate can be used to approximate the age of the universe. Put explicitly, the age of the universe can be estimated roughly as
(but you need to be careful about units: you need to first convert to units of inverse seconds for this to work.