Execute the following code to initialize the printing environment
import sympy as sp
sp.init_printing()
SymPy
as a calculatorevalf()
i = sp.Integer(24)
r = sp.Rational(1, 3)
f = sp.Float(3.53) + sp.Float(3)
sp.pi + sp.E
sp.oo > 99999
sp.sin(sp.pi/2)
Operator | Description | Documentation |
---|---|---|
sp.subs() |
Substitutes old for new in an expression after sympifying args. | link |
sp.evalf() |
Evaluate the given formula to an accuracy of n digits. | link |
sp.utilities.lambdify() |
subs() and evalf() are good if you want to do simple evaluation, but if you intend to evaluate an expression at many points, there are more efficient ways. This function provides convenient ways to transform SymPy expressions to Python expre |
link |
x = sp.Symbol('x') # the symbol you create has to be specified as a string
x,y = sp.symbols('x,y') # you can create multiple symbols at once using multiple assignment
SymPy
only automatically simplifies the most elementary expressions and requires the programmer to explicitly request further simplification. Therefore, several simplification functions available here
Operator | Description | Documentation |
---|---|---|
sp.expand() |
Given a polynomial, expand() will put it into a canonical form of a sum of monomials. |
link |
sp.simplify() |
It applies all the major simplification operations in SymPy , and uses heuristics to determine the simplest result. But “simplest” is not a well-defined term. |
link |
sp.factor() |
Takes a polynomial and factors it into irreducible factors over the rational numbers | link |
Several functions available here for finding roots of polynomials.
Also checkout here and here for solving equations.
Operator | Description | Documentation |
---|---|---|
sp.solve() |
General solving function which can find root | link |
sp.nroots() |
computes numerical approximations of the roots of any polynomial whose coefficients can be numerically evaluated, whether the coefficients are rational or irrational | link |
sp.nsolve() |
Solve a nonlinear equation system numerically. Only return one solution at a time | link |
SymPy
You can do basic calculus tasks such as derivatives, integrals, limits, and series expansions in SymPy
. See here.
Operator | Description | Documentation |
---|---|---|
sp.Limit() /sp.limit(e, z, z0, dir='+') |
Computes the limit of e(z) at the point z0. Limit is the unevaluated object |
link |
sp.Derivative() /sp.limit(e, z, z0, dir='+') |
Differentiate f with respect to symbols. Derivative is the unevaluated object |
link |
sp.Integral() /sp.integrate() |
Compute definite or indefinite integral of one or more variables. Integral is the unevaluated object |
link |
sp.series(expr,x,x0) |
Series expansion of expr around point x=x0. | link |
SymPy
You can find more information here
Operator | Description | Documentation |
---|---|---|
sp.Matrix() |
link |