Ramanujan and Salamin-Brent Methods for π

Math 242 Modern Computational Mathematics

Ramanujan's Method

Here is Ramanujan's sum:
(1/π)=((2(Sqrt[2]))/9801)  (∑_(k=0)^∞)(((4k)!(1103+26390k))/((((k!))^4)(396^(4k))))

Complete the following module to add up the first n terms of Ramanujan’s sum and return an approximation of π:

ramanujan[n_]:=Module[

Do[
sum+=(((4k)!(1103+26390k))/((k!)^4*396^(4k))),
{k,0,n}];


]

Demonstrate that your module returns exact values that are close to π.

How many correct digits of π are produced by each term of Ramanujan’s sum?

nMax=20;
piValuesRamanujan=

accuracyRamanujan=

ListPlot[accuracyRamanujan,AxesLabel->{"n","correct digits"}]

TableForm[Transpose[{Range[nMax],accuracyRamanujan}],TableHeadings->{None,{"terms","correct digits"}}]

Salamin-Brent Algorithm

Implement a module that computes approximations of π using the Salamin-Brent method (Algorithm 1.20 on page 31 in the text). Your module should accept one input parameter: an integer that specifies how many iterations of the algorithm to compute. Make a table showing how the number of correct digits of π increases with the number of terms that you add up. Answer the question: What is the relationship between the number of iterations and the number of correct digits of π?