Question: Pi can be computed using the following Leibniz formula: Pi= 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13
Pi can be computed using the following Leibniz formula:
Pi= 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - + 1/(2i-1))
Or:
Pi can be computed using the following Nilakantha formula:
Pi= 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10)+ 4/((2i)*(2*i+1)*(2*i+2))
Question 1: Which Pi formula is the fastest: Leibniz or Nilakantha?
Create a class that uses the Leibniz formula to calculate Pi for the first 1M iterations of terms.
Create a class that uses the Nilakantha formula to calculate Pi for the first 1M iterations of terms.
Determine which class is the fastest (Use milliseconds). Document your findings below.
Question 2: Does the scale of the problem matter? Which is more precise?
Repeat the exercises in question 1 for the first 100M, 200M, 300M, 400M, and 500M iterations.
Use Netbeans to determine which class executes the task the fastest. Compare the results to the Math.PI constant
Does the number of iterations affect the precision? Document your findings below.
Question 3: Document your findings.
Create a table that displays the results for each analysis relative to the number of iterations.
Create a bar graph of your data. Include the bar graph in you submitted zipped file.
Question 4: Draw conclusions. Which formula is fastest? More precise?
Which formula should be used when speed is the most important factor? Precision?
Speed isnt the only factor in determining which formula should be used. Make an argument for using each type of formula in a given program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
