Questions tagged [sympy]

SymPy is an open source Python library for symbolic mathematics.

SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external libraries.

Some examples of usage can be found here.

SymPy includes features ranging from basic symbolic arithmetic to calculus, algebra, discrete mathematics, quantum physics. It is capable of formatting the result of the computations as LaTeX code.

Some Core capabilities:

  • Basic arithmetic: *, /, +, -, **
  • Simplification
  • Expansion
  • Functions: trigonometric, hyperbolic, exponential, roots, logarithms, absolute value, spherical harmonics, factorials and gamma functions, zeta functions, polynomials, hypergeometric, special functions, ...
  • Substitution
  • Arbitrary precision integers, rational and floats
  • Non-commutative symbols
  • Pattern matching
  • Polynomials
  • Basic arithmetic: division, gcd, ...
  • Factorization
  • Square-free factorization
  • Calculus
  • Limits
  • Differentiation
  • Pretty-printing: ASCII/Unicode pretty-printing, LaTeX
  • Code generation: C, Fortran, Python
5602 questions
32
votes
8 answers

plus/minus operator for python ±

I am looking for a way to do a plus/minus operation in python 2 or 3. I do not know the command or operator, and I cannot find a command or operator to do this. Am I missing something?
Whitequill Riclo
  • 788
  • 2
  • 8
  • 19
28
votes
3 answers

Is there any way to get the step-by-step solution in SymPy?

Is there any way to get the step-by-step solution in SymPy? For example: x**2-5 = 4 step 1 x**2-5+5=4+5 step 2 : x**2=9 step 3 :x = 3 or x= -3
Xyz-47
  • 343
  • 3
  • 5
25
votes
5 answers

How to calculate expression using sympy in python

I need a calculate below expression using sympy in python? exp = '(a+b)*40-(c-a)/0.5' In a=6, b=5, c=2 this case how to calculate expression using sympy in python? Please help me.
Zeck
  • 6,433
  • 21
  • 71
  • 111
25
votes
2 answers

Any way to solve a system of coupled differential equations in python?

I've been working with sympy and scipy, but can't find or figure out how to solve a system of coupled differential equations (non-linear, first-order). So is there any way to solve coupled differential equations? The equations are of the…
bynx
  • 760
  • 2
  • 8
  • 19
23
votes
3 answers

How to check the current version of sympy and upgrade to the latest version?

How to check the current version of SymPy and upgrade to the latest version? I am using macOS. The way I installed my current version is using pip install sympy.
MAS
  • 4,503
  • 7
  • 32
  • 55
21
votes
3 answers

Convert a LaTex formula to a type that can be used inside SymPy

I want to parse LaTeX formulas and directly use them as SymPy expressions. In other words, what I need is something similar to sympify: from sympy import sympify f = sympify('x^2 + sin(y) + 1/2') print f but that can take LaTeX expressions…
user2243748
  • 235
  • 1
  • 2
  • 7
20
votes
2 answers

Using Sympy Equations for Plotting

What is the best way to create a Sympy equation, do something like take the derivative, and then plot the results of that equation? I have my symbolic equation, but can't figure out how to make an array of values for plotting. Here's my code: …
MANA624
  • 986
  • 4
  • 10
  • 34
19
votes
2 answers

Using "from __future__ import division" in my program, but it isn't loaded with my program

I wrote the following program in Python 2 to do Newton's method computations for my math problem set, and while it works perfectly, for reasons unbeknownst to me, when I initially load it in ipython with %run -i NewtonsMethodMultivariate.py, the…
Sara Fauzia
  • 193
  • 1
  • 1
  • 9
19
votes
2 answers

Inverse of a matrix in SymPy?

I was wondering how to create a matrix and compute its inverse using SymPy in Python? For example, for this symbolic matrix:
Tim
  • 1
  • 141
  • 372
  • 590
19
votes
2 answers

Representing rings of algebraic integers

I'm trying to represent the ring; where theta is the root of a monic irreducible polynomial f with integer coefficients of degree d. This ring is a subring of the algebraic integers, which itself is a subring of the field; I can represent this…
Kevin Johnson
  • 820
  • 11
  • 24
18
votes
2 answers

Convert sympy expressions to function of numpy arrays

I have a system of ODEs written in sympy: from sympy.parsing.sympy_parser import parse_expr xs = symbols('x1 x2') ks = symbols('k1 k2') strs = ['-k1 * x1**2 + k2 * x2', 'k1 * x1**2 - k2 * x2'] syms = [parse_expr(item) for item in strs] I would…
drhagen
  • 8,331
  • 8
  • 53
  • 82
18
votes
3 answers

Calculate curl of a vector field in Python and plot it with matplotlib

I need to calculate the curl of a vector field and plot it with matplotlib. A simple example of what I am looking for could be put like that: How can I calculate and plot the curl of the vector field in the quiver3d_demo.py in the matplotlib…
celestos
  • 311
  • 1
  • 3
  • 6
18
votes
1 answer

Dealing with piecewise equations returned by sympy integrate

In sympy I have an integral which returns a Piecewise object, e.g. In [2]: from sympy.abc import x,y,z In [3]: test = exp(-x**2/z**2) In [4]: itest = integrate(test,(x,0,oo)) In [5]: itest Out[5]: ⎧ ___ …
17
votes
3 answers

How to get the Gradient and Hessian | Sympy

Here is the situation: I have a symbolic function lamb which is function of the elements of the variable z and the functions elements of the variable h. Here is an image of the lamb symbolic function . Now I would like the compute the Gradient and…
Randerson
  • 775
  • 1
  • 5
  • 19
17
votes
5 answers

Evaluating a mathematical expression (function) for a large number of input values fast

The following questions Evaluating a mathematical expression in a string Equation parsing in Python Safe way to parse user-supplied mathematical formula in Python Evaluate math equations from unsafe user input in Python and their respective…
s-m-e
  • 3,433
  • 2
  • 34
  • 71