The arithmetic-geometric mean

Question Q2.5.2

Write a while loop to calculate the arithmetic-geometric mean (AGM) of two positive real numbers, $x$ and $y$, defined as the limit of the sequences: \begin{align*} a_{n+1} &= \textstyle \frac{1}{2}(a_n + b_n)\\ b_{n+1} &= \sqrt{a_n b_n}, \end{align*} starting with $a_0 = x$, $b_0 = y$. Both sequences converge to the same number, denoted $\mathrm{agm}(x,y)$. Use your loop to determine Gauss's constant, $G = 1/\mathrm{agm}(1,\sqrt{2})$.


Solution Q2.5.2