Archimedes's Method

Preliminary Calculations

Start with a square:

s2=Sqrt[2]

pi2=2*s2

N[pi2]

Now use an octagon:

a=Sqrt[1-(s2/2)^2]

b=1-a

s3=Simplify[Sqrt[b^2+(s2/2)^2]]

pi3=8s3/2

N[pi3]

Lists in Mathematica

When working with a sequence of values, it’s helpful to use a list.

Range[10]

sampleList=Table[0,7]

sampleList[[2]]=12

sampleList

sampleList[[4]]=-1

sampleList

Compute Approximations of Pi using a Loop

(* specify number of iterations *)
nMax=10;

(* inital values *)
sideLength=Sqrt[2];

(* create a list to store approximations *)
piValues=Table[0,nMax];

(* put initial approximation in the list *)
piValues[[2]]=2*sideLength

(* the loop *)
Do[
a=Sqrt[1-(sideLength/2)^2];
b=1-a;
sideLength=Simplify[Sqrt[b^2+(sideLength/2)^2]];
piValues[[n+1]]=2^n*sideLength
,{n,2,nMax-1}]

(* output results *)
piValues

N[piValues]

Accuracy

N[piValues]

N[Pi-piValues]

Pi

accuracy=N[-Log[10,Pi-piValues]]

Plot

ListPlot[accuracy,AxesLabel->{"iteration","accuracy"}]

Table

{Range[nMax],N[piValues],N[accuracy]}

TableForm[Transpose[{Range[nMax],N[piValues],N[accuracy]}],TableHeadings->{{},{"n","appox","accuracy"}}]