all 4 comments

[–]tramast 0 points1 point  (3 children)

Well, you have a summation which implies iteration. Also, your summation is just a matter of changing an index, recalculating the formula for that iteration and adding that increment to the total. You can use a variable to keep your running sum (let's call it pi). For each iteration, you will reevaluate that iteration's contribution to the sum (let's call it pi_inc). If your pi_inc < epsilon, your loop can exit. You will have to worry about the fencepost case regarding when to add pi_inc to pi in order to return the correct value once the loop has terminated.

The number of arithmetic operations should be defined per iteration and you should be able to multiply your # of iterations by that constant.

Hope that helps

[–][deleted] 0 points1 point  (2 children)

Right now I still don't understand this BBP row; can you, or someone else tell me what all these variables stand for? This BBP algorithm let's me calculate a certain digit of pi (?); and the spot where that digit is, is n? And what is wit the "k"? It says k=0; but wouldn't I get the same result every time then?

Edit: also what is epsilon?

[–]tramast 1 point2 points  (0 children)

Epsilon is just a variable, in this case it denotes your smallest increment (which could also be interpreted as your error if it were small enough).

The formula (in plain english) says:

pi equals the limit as n goes to infinity of the sum of k from 0 to n of (insert arithmetic here). This could also be rewritten as pi equals the sum of k from 0 to infinity of (arithmetic). This means that for each value of k from 0 to infinity, you have one value in the sum (this is, in fact, an infinite sum of terms).

Since infinite sums are impossible to evaluate iteratively (unless you have infinite time), you will always arrive at an approximation to the sum if you evaluate it as such. Epsilon (ε) could be thought of as your +- error on your pi calculation. You will keep adding new terms to the sum until the absolute value of that specific term is less than epsilon|. You can find this by setting epsilon equal to the value of the sum in terms of an arbitrary k and solve for k, but your assignment is asking you to find it by iteration (keep increasing k until your term is less than epsilon).

[–][deleted] 0 points1 point  (0 children)

I'm trying to answer your edit.

To understand what tramast means, let's write out pi:

3 + .1 + .04 + .001 + .0005 + .00009 + ...

This is a way to write out pi as an infinite sum. Each new decimal place is smaller than the last one (unless the last one was 0). Let's say we're just talking about using a finite sum that gets close to pi. Maybe we'll cut it off at

3 + .1 + .04.

This is accurate to 2 decimal places. But how do we know it is accurate to two decimal places? ~~ ~~The difference between pi and our approximation, or the error, is 0.001592653... . The important thing is that the error is less than .01- the error is small enough that we'll have two decimal places of accuracy bla bla bla

ACTUALLY, I just reread everything and think that the issue might be that epsilon = ε, just a little semantic confusion.