keisoku

Pi Calculator (Gauss-Legendre AGM Method)

Compute pi using the Gauss-Legendre algorithm based on the arithmetic-geometric mean (AGM). Pick the iteration count to see each approximation, its error, correct digits, and the convergence table.

Input

Choose the iteration count to compute pi with the Gauss-Legendre method based on the arithmetic-geometric mean.

Number of iterations

4

The number of correct digits roughly doubles each iteration. In double precision, a few steps already match all digits of pi.

Result

Approximation of pi after 4 iterations

3.14159265359

Correct digits

about 15 digits

Absolute error

8.882e-16

Reference pi

3.14159265359

Convergence per iteration

The approximation after each iteration and its absolute error against the reference pi, showing how quickly the error shrinks.

IterationApproximationAbsolute error
13.1405792505221.013e-3
23.1415926462147.376e-9
33.141592653598.882e-16
43.141592653598.882e-16

Calculation steps

1

Set the initial values a=1, b=1 divided by the square root of 2, t=1 divided by 4, and p=1.

2

The new a is the arithmetic mean of the old a and b, namely (a+b) divided by 2.

3

The new b is the geometric mean of the old a and b, the square root of a times b.

4

Update the correction term by subtracting p times (old a minus new a) squared from t, then double the weight p.

5

The approximation is (a+b) squared divided by (4 times t). Each iteration roughly doubles the number of digits.

Error is the difference from pi as stored in double precision. Double precision reaches about 15 digits of machine accuracy after a few iterations.

How it works

  • The Gauss-Legendre method starts from a=1, b=1 divided by the square root of 2, t=1 divided by 4, and p=1. Each iteration updates a and b with the arithmetic and geometric mean, then updates the correction term t and weight p.
  • After each iteration the approximation is (a+b) squared divided by (4 times t). Because the gap between the arithmetic and geometric mean shrinks quadratically, the number of correct digits roughly doubles per iteration.
  • Error is shown as the absolute difference from pi as represented in double precision. Double precision reaches machine accuracy (about 15 digits) after only a few iterations, so further iterations do not add displayed digits.
  • Correct digits is an estimate derived from the size of the error.

Reviews

Tell us what you think of this calculator.

Write a review

  1. Home
  2. Pi Calculator (Gauss-Legendre AGM Method)