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
11
votes
2 answers

How to solve multivariate inequalities with python and sympy?

I'm quite new using python and Sympy... And got a problem to solve multivariate inequalities using sympy. Let's say I have a lot of functions in a file which look like this : cst**(sqrt(x)/2)/cst exp(sqrt(cst*x**(1/4))) log(log(sqrt(cst…
sloan
  • 319
  • 1
  • 3
  • 9
11
votes
2 answers

How to parse and simplify a string like '3cm/µs² + 4e-4 sqmiles/km/h**2' treating physical units correctly?

I'd like to split a string like 3cm/µs² + 4e-4 sqmiles/km/h**2 into its SI unit (in this case, m/s**2) and its magnitude (in multiples of that unit). Since sympy provides both a parsing module and many physical units and SI prefixes, I guess using…
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
11
votes
3 answers

Evaluating a function at a point in SymPy

I'm trying to code various optimisation methods, as a way of revising. I want to be able to use SymPy to evaluate a function with an arbitrary number of variables at a given point, where the co-ordinates of the point are stored in an array. For…
Tam Coton
  • 786
  • 1
  • 9
  • 20
11
votes
4 answers

Units conversion in Python

SymPy is a great tool for doing units conversions in Python: >>> from sympy.physics import units >>> 12. * units.inch / units.m 0.304800000000000 You can easily roll your own: >>> units.BTU = 1055.05585 * units.J >>>…
Paul
  • 42,322
  • 15
  • 106
  • 123
10
votes
2 answers

How to speed up symbolic derivatives of long functions using SymPy?

I am writing a program in Python to solve the Schrödinger equation using the Free ICI Method (well, SICI method right now... but Free ICI is what it will turn into). If this does not sound familiar, that is because there is very little information…
Shrodinger149
  • 123
  • 1
  • 7
10
votes
2 answers

Sympy - Rename part of an expression

Say I have defined the following expression: from sympy import * N, D, i, j, d = symbols("N D i j d", integer=True) beta, gamma = symbols(r'\beta \gamma') X = IndexedBase("X", shape=(N, D)) # r(i, j) = euclidian distance between X[i] and X[j] r =…
Bendik
  • 1,097
  • 1
  • 8
  • 27
10
votes
1 answer

sympy: how to simplify across multiple expressions

I have a set of sympy expressions like this (a few hundred of them): >>> foo = parse_expr('X | Y') >>> bar = parse_expr('(Z & X) | (Z & Y)') >>> baz = parse_expt('AAA & BBB') # not needed for this example; just filler I can simplify one in…
ajwood
  • 18,227
  • 15
  • 61
  • 104
10
votes
1 answer

Possible to add descriptions to symbols in sympy?

I seek a functionality in sympy that can provide descriptions to symbols when needed. This would be something along the lines of >>> x = symbols('x') >>> x.description.set('Distance (m)') >>> t = symbols('t') >>> t.description.set('Time (s)') >>>…
user32882
  • 5,094
  • 5
  • 43
  • 82
10
votes
1 answer

Use LaTeX symbols in sympy expressions

I would like to do some calculations and then have those plotted using sympy. I want to use consistent notation, so I need to define a symbol which will be printed as $\Delta_l^y$. What I have tried so far: delta__i_0 =…
laolux
  • 1,445
  • 1
  • 17
  • 28
10
votes
1 answer

Enforce custom ordering on Sympy print

SymPy does a wonderful work keeping track of all the operations I do to my symbolic expressions. But a the moment of printing the result for latex output I would like to enforce a certain ordering of the term. This is just for convention, and…
Titan-C
  • 101
  • 4
10
votes
1 answer

How to extract the eye/target/up from a view matrix using sympy?

We've tried to figure out for quite a while in the #python channel how to compute the eye/target/up vectors out of a view matrix using sympy. One possible way to do it could be: from sympy import * from pprint import pprint v1, v2, v3, v4 =…
BPL
  • 9,632
  • 9
  • 59
  • 117
10
votes
1 answer

Python SymPy: Error while solving inequality

Problem: I am trying to solve an inequality to obtain a variable coeff_rw, which is the value of the symbol rw satisfying the inequality. This value should be in terms of other symbols (variables) that are defined in the following code. I am first…
user238469
10
votes
1 answer

How to turn a system of sympy equations into matrix form

How do I turn a system of sympy equations into a matrix form? For example, how do I turn a system like this: equation_one = 4*a*x + 3*b*y equation_two = 2*b*x + 1*a*y Into a system like this: matrix_form = ([equation_one, equation_two], [x,…
Paul Terwilliger
  • 1,596
  • 1
  • 20
  • 45
10
votes
2 answers

Best way to isolate one coefficient of a multivariate polynomial in sympy

I have a multivariate polynomial (which in the general case many many variables) whose coefficients list some data that I need to read off, but it doesn't seem like sympy gives a good way to do this. The collect function seemed like the right idea,…
xanderflood
  • 826
  • 2
  • 12
  • 22
10
votes
2 answers

Spherical coordinates plot

R(teta, phi) = cos(phi^2), teta[0, 2*pi], phi[0,pi] How to draw a graph of this function (R(teta, phi)) in spherical coordinates with the help of matplotlib? The documentation I have not found Spherical coordinates.
Roman
  • 103
  • 1
  • 1
  • 6