Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
>>> x + y + x - y
2*x

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



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

...

SymPy has support for both indefinite and definite integration:.

Code Block
languagepy
>>> from sympy import *
>>> x, y = symbols('x y')

...

Code Block
languagepy
>>> from sympy import *
>>> x = Symbol('x')

>>> solve(x**2 - 1, x)
[-1, 1]

>>> solve([x + 5*y - 2, -3*x + 6*y - 15], [x, y])
{x: -3, y: 1}

>>> solve(Eq(x**4, 1), x)
[-1, 1, -I, I]

nsolve(function,[variables], x0) is a useful tool to solve nonlinear equation system numerically, where x0 is a starting vector close to the solution. If there is only one variable, the second argument may be left out.

Code Block
languagepy
>>> from sympy import *
>>> x = Symbol('x')

>>> nsolve(sin(x), x, 2)
3.14159265358979

>>> nsolve(sin(x), 2)
3.14159265358979

>>> nsolve(sin(x**2)/(pi - x), x, pi.evalf()/2)
1.77245385090552

...