Friday, February 28, 2014

Infinite Greg Lib Series for Pi

The key in this program is recongizing the the odd numbers with the pi sequence. Here are a few rules I follow when defining some sort of sequence based off some arithmetic. Because really, this is the hardest part.
    1). First write down the sequence.
    2). Note the changes within the sequence.
        In this case, the changes observed were:
            Chronologically placed odd numbers in the denominator.
            The sequence begins with a positive number, and alternates with negative numbers.
    3). Next, understand how we can implement this in a kind of sequence, because really, everything else will be kept a constant, and therefore not manipulable.
    4). A key when trying to develope the formula for the changes is this: you have to understand that the formula must work hand-in-hand with a range function. Therefore, starting from any given interval, and moving consequtively beyond the limitations of range(x,y,z).
        An odd number could be obtained by: (i*2+1), because anything as a multiple of two plus 1 is automatically odd. Beginning with the range 1, we obtain 4.
        The alternations between positive and negative would be to to introduce a negative constant every iteration of i.
        The fact our main sequence is working with a total sum means that we would want to update our solution everytime. We solve this by adding the add = 0, and add = add in the for loop function. This is a popular method when dealing with sequence summations.
        Finally, we can compare our solution to pythons imported pi value by comparing their difference.    

No comments:

Post a Comment