|
Aims and Objectives: Provide an opportunity for students to apply their knowledge of pre-test loop constructs ("for" and "while") taught in week 7, and to buid a simple class hierarchy.
Over the centuries many mathematicians have proposed progressions for estimating PI. Including:
(1) Francois Vieta (1540-1603), a French mathematician who proposed the sequence:
2 sqrt(2) sqrt(2+sqrt(2)) sqrt(2+sqrt(2+sqrt(2))) sqrt(2+sqrt(2+sqrt(2+sqrt(2)))) ---- = ------- x --------------- x ----------------------- x ------------------------------- x .... PI 2 2 2 2
Considering only the first four terms:
2 1.41421 1.84776 1.96157 1.99037 ---- = --------- x --------- x --------- x --------- PI 2 2 2 2 = 0.70710 x 0.92388 x 0.98078 x 0.99518 = 0.63764
Which means that:
PI = 2/0.63764 = 3.13655
Note that in Vieta's progression, for each term, we add 2 to the dividend of the previous term and then find the square root. After only a few terms this gives a good approximation, for example 20 terms gives the estimate 3.1415926535886185, which is very close to the estimation we use today (3.141592653589793).
(2) John Wallis (1616-1703), an English Mathematician , who proposed:
PI 2 2 4 4 6 6 8 8 10 10 ---- = --- x --- x --- x --- x --- x --- x --- x --- x ---- x ---- x .... 2 1 3 3 5 5 7 7 9 9 11
Considering only the first eight terms:
= 2.0 x 0.66667 x 1.33333 x 0.8 X 1.2 x 0.85714 x 1.14286 x 0.88888 = 1.48608
Which means that:
PI = 2 x 1.48608 = 2.97215
Note that for Wallis's progrtession the dividend and divisor are alternatively incremented by 2. Wallis's progression does not operate as efficiently as that proposed by Franciscus Vieta, however if we multiply the first 20,000 terms we get 3.1415141186819087!
Francois Vieta (1540-1603) 1 |
John Wallis (1616-1703) 2 |
[1] Design, implement and test a class hierarchy of the form shown in Figure 1, which has a super-class PIestimation and two sub-classes (Vieta and Wallis), which can be used to produce estimates of PI, using either the method proposed by Franciscus Vieta or that of John Wallis. You should allow for a "number of terms" value to be supplied by the user. [2] Then design and implement an application class that uses the classes in the hierarchy to produce estimates for PI using the two approaches outlined above. |
Figure 1: Incomplete class diagram for PI estimation practical |
Test the programs using appropriate testing techniques including loop testing.
HINTS:
Refer back to the notes on pre-test loop constructs for week7: particularly the arithmetic expression, factorial series and Eulers number series example problems.Point of interest: Knowing PI to 39 decimal places is sufficient to calculate the circumference of the universe accurate to the radius of a hydrogen atom, however this has not prevented computer scientists from calculating PI to as many decimal places as possible (Singh 1997). In 1996 Yasumasa Kanada of the University of Tokyo calculated PI to six billion decimal places. Singh also reports that the Chudnovsky brothers in New Tork are aiming to reach a trilion decimal places!
Your solution should comprise the following:
The report should comprise the following sections:
Rember that all supporting documentation (i.e. excluding your source files) should be prepared as a single Microsoft Word file.
Once completed you should "up load" your Java source files (extension .java) and your word document to the CS department's electronic "practical assignment submission" system.
Marks will be awarded for:
With the total number of available marks distributed as indicated
Remember:
Created and maintained by Frans Coenen. Last updated 30 October 2006