Ask Your Question

sgruenwald's profile - activity

2014-11-22 06:45:08 +0200 answered a question Continued fraction of pi by hand

I changed your code slightly to use in Python with sympy and get the right continued fraction for pi up to term 1000. It can be easily extended to higher numbers. Calculation time is a little over 2 seconds on my machine. Here is the code:

import sympy as sp

p=sp.N(sp.pi, 5000)

n=2000
x=range(n+1)
a=range(n)
x[0]=p
for i in xrange(n):
    a[i] = int(x[i])
    x[i+1]=1/(x[i]-a[i])
    print(a[i]),