Im trying to estimate pi, the first term in the series is correct the second is -1 instead of -4/3. then just zeros im sure my closed form for the sequence is right i just cant figure out where im going wrong...
#premise for this problem:
#working from the starting point of a tayler expansion of 1/(1-x)
#Start with 1/(1+w) = 1 - w + w2 - w3 + ...
#Now substitute x2 for w:
#1/(1+x2) = 1 - x2 + x4 - x6 + ...
#Then integrate both sides (from x=0 to x=y):
#arctan y = y - y3/3 + y5/5 - y7/7 +...
#and plug in y=1, to get
# Pi/4 = 1 - 1/3 + 1/5 - 1/7 + ...
from math import *
import numpy as np
n= 100 #define range
x= 1 #define range
series = [] # define our series expantion Pi/4 = 1 - 1/3 + 1/5 - 1/7 + ...
for u in range(0,n):
if ((u %2)==0): #if even r=positive
r=1
else:
r=-1 #else r=negitive
d= (1+(u*2))
value = ((4//d)*r)
series.append(value)
sumseries= sum(series) #sum the series
print (sumseries)
print 'error in pi is', (sumseries/pi)*100, '%'
print series