Monday, 14 January 2008

Symbols computing in Python

Symbols computing in Python, ( from http://code.google.com/p/sympy)

In contrast to other Computer Algebra Systems, in SymPy you have to declare symbolic variables explicitly:

>>> from sympy import *
>>> x = Symbol('x')
>>> y = Symbol('y')

Then you can play with them:

>>> x+y+x-y
2*x

>>> (x+y)**2
(x+y)**2

>>> ((x+y)**2).expand()
2*x*y+x**2+y**2

>>> c=x**2-3*x+2 # 因式分解
>>> factor(c)
(1 - x)*(2 - x)

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter