John Wallis, 25 or so years older than Issac Newton, was one of the creators of
ID: 3569110 • Letter: J
Question
John Wallis, 25 or so years older than Issac Newton, was one of the creators of the calculus. He also created the infinity symbol ?. Wallis developed the following infinite product formula for pi/4, and first reported it in 1655:
Gottfried Leibnitz, a co-inventor of calculus along with Issac Newton, gave a different formula for pi/4 using an infinite sum:
Your job for this assignment is to interactively enter a level of precision, e.g., .001, and then report how many terms are necessary for each of these estimates to come within the specified precision of the value of pi. For .001, for example, how many terms does it take for each of these formulas to reach a value between 3.14059.. and 3.14259... Remember that the more or less true value for pi, and the one you should use in your code, is a constant in the Java Math class, java.lang.math: Math.PI. Remember that you don't need to import java.lang - it's loaded automatically when you start up Java.
Use Scanner to read in the user-provided value for the intended precision.
(Note: because the expressions approximates pi/4 and not pi, you will have to multiply your estimates by 4).
Here is the driver class for your project. Note that you will need to implement the two methods wallisEstimate and leibnitzEstimate, as well as the PiEstimates constructor. Enter you code for the class PiEstimates in the box below.
Explanation / Answer
Program : public class PiEstimates{ double i; public PiEstimates(double tolerance) { i = tolerance; } public double leibnitzEstimate(){ int j = 0; int count = 1; while(jMath.PI+i) {j = j + 4*(((-1)^count)*(1/(1+2*(count-1)))); count = count + 1; } System.out.println("Leibnitz: " + count); return count; } public double wallisEstimate(){ int q = 0; int count2 = 1; while(4*qMath.PI+i) {q = q * ((2+(2*((count2+1)/2)))/(3+(2*(count2/2)))); count2 = count2 + 1; } System.out.println("Wallis: " + count2); return count2; } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.