Help with sympy, please

Dick Moores rdm at rcblue.com
Sun Nov 18 16:02:01 EST 2007


from __future__ import division
Here's what I'm trying to do, but using sympy:
=============================
from math import e
n = 1
prod = 1
k = 0
while k < 1000:
     k += 1
     term = (e**(1.0/n))/(e**(1.0/(n+1)))
     prod *= term
     n += 2
print prod, term
================================
Output:
1.99950018746 1.00000025013  (the limit is 2)


============================
from sympy import *
from sympy import Rational as R
from sympy.numerics import *

prec = 50
Float.setdps(prec)
e = evalf(E)
n = 1
k = 0
prod = evalf(R(1,1))
while k < 1000:
     k += 1
     n = evalf(R(n,1))
     term = (e**(1/n))/(e**(1/(n+1)))
     prod *= term
     n += 2
print prod, term
===========================

This gets:
Traceback (most recent call last):
   File "E:\PythonWork\Untitled 5.py", line 20, in <module>
     term = (e**(1/n))/(e**(1/(n+1)))
TypeError: unsupported operand type(s) for /: 'int' and 'Float'

Thanks,

Dick Moores




More information about the Python-list mailing list