Archimedes’s Method for π

MATH 242: Modern Computational Mathematics

Lists in Mathematica

When working with a sequence of values, it’s helpful to use a list. Here are two ways of creating lists:

myList=Range[10]

sampleList=Table[0,7]

Use the part operator, [[]], to access and assign values to list elements. Note that in Mathematica, list indexes start from 1.

Implementing Archimedes’s Method

Complete the code in the following cell to implement Archimedes’s method for approximating π with inscribed (2^n)-gons.

(* specify the number of iterations *)


(* initialize values *)


(* initialize a list for approximations of π *)


(* include the initial approximation in the list *)


(* main loop *)



(* display the results *)

Accuracy of Approximation

Assess the accuracy of your results. How does the number of correct digits of π relate to the number of iterations of Archimedes’s method?

The negative log of the difference is (roughly) the number of correct digits of π:

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

We can make a table like Table 1.1 in the text:

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

We can also make a plot similar to Figure 1.3 in the text:

ListPlot[accuracy,DataRange->{2,nMax},AxesLabel->{"n","accuracy"}]