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
2
votes
1 answer

How make sympy.printing.latex use Newton's notation for time derivatives

While in qtconsole, I can import init_vprinting from sympy.physics.mechanics and then use dynamicsymbols to acquire dotted derivatives. But when I use latex printer, I get 'da/dt' instead. a = dynamicsymbols('a') a.diff(t) In:…
Eugene
  • 656
  • 8
  • 20
2
votes
1 answer

Replace ** with Math.pow in SymPy

I have a SymPy expression in Python and I would like to copy and paste it into a Java source code. Problem is that there’s a different notation for exponentiation: Java uses Math.pow(a,b); Python uses a**b. So my question is: Is there a way how to…
Josef Ondrej
  • 159
  • 8
2
votes
1 answer

Convert from sympy.core.add.Add to numpy complex number

I have this list of solutions from Sympy solver: In [49]: sol Out[49]: [-1.20258344291917 - 0.e-23*I, -0.835217129314554 + 0.e-23*I, 0.497800572233726 - 0.e-21*I] In [50]: type(sol) Out[50]: list In [51]: type(sol[0]) Out[51]:…
Ohm
  • 2,312
  • 4
  • 36
  • 75
2
votes
3 answers

How to solve multivariate equation systems programmatically?

I am trying to solve a system of multivariate equations, which are the result of some Java code. Neither the form, nor the number of variables is known before runtime. An example would be (I) (e-a*d*e-b*d*e+2*b*d*f+2*b*d*e*g)/(-1+a*d+b*d)+f ==…
2
votes
1 answer

Lambdify'ed expression raises TypeError when used with arrays, if the expression contained a sympy object

I'm using sympy to create an expression that is then displayed as latex with sympy.init_printing(). The expression is used in calculations after being lambdified to a function named f. However, when using an array or a Series object as an argument…
user
  • 5,370
  • 8
  • 47
  • 75
2
votes
2 answers

Python/Sympy: solve equations with different values

I'm trying to solve these three equations: a1 + a2 = b1 a2 + a3 = b2 b1 + b2 = c1 I generate values for three variables that are chosen randomly (disallowing the combination b1, b2, and c1), so I might have a1 = 5, a3 = 10, and c1 = 100, so I can…
2
votes
1 answer

solve() execution aborted

I'm having trouble using Sympy to solve an equation. When I run the code, for example: print(correction(10)) I expect it to print a number which is f. Instead it gives me ERROR: execution aborted. def correction(r): from sympy import cosh,…
Emma Smith
  • 381
  • 1
  • 4
  • 9
2
votes
1 answer

How to display a percent character using SymPy and LaTeX

I have been playing around with equations for electric systems using Sympy, and have already manage quite a lot so that equation look nice and decent : all values hold units which are following them even trough combinations of equations. That's…
Mr Buisson
  • 127
  • 7
2
votes
2 answers

Using numpy arrays of sympy numbers

Is it advisable, while working with arrays of symbolic expresions, to use numpy arrays? Something like u0=numpy.array([Number(1.0), Number(1.0), Number(1.0)]) I mean, is it faster to use numpy arrays instead of python lists? If so, certain…
D1X
  • 5,025
  • 5
  • 21
  • 36
2
votes
1 answer

Python-Calculating the roots of a simple non-linear equation system

As title says, here is my system: [;Acos(\phi)=1;] [;-0.5Asin(\phi)=0;] The obvious solutions are A=1 and [;\phi=n\pi , n\in \mathbb{Z};], I tried using sympy..nsolve(doesn't work) and scipy..fsolve(gives an error "Result from function call is not…
zivo
  • 120
  • 8
2
votes
2 answers

Trying to produce monospaced output in pyqt browser

I have modified a short piece of pyqt code to produce real-time rendering of a user's expression. I have used sympy's pretty-printing function for this, however the output does not appear correctly as the QTextBrowser uses a proportional rather than…
Geddes
  • 1,191
  • 2
  • 11
  • 25
2
votes
1 answer

Algorithm to detect if a list of circles at rest intersect with another circle moving from start point to end point along straight line in same plane

I have a circle ( Striker in my game ) which moves along my 2d plane from one point to another point along a straight line. I have some other circles in the same plane which are not moving. What is the best algorithm to find the list of circles…
Bill Goldberg
  • 1,699
  • 5
  • 26
  • 50
2
votes
1 answer

How do I ufuncify a function that contains LaTeX symbols?

This code from sympy import symbols from sympy.utilities.autowrap import ufuncify a = symbols(r'\alpha') phi = a**2 phi_f = ufuncify(a, phi) throws the errors below, which are clearly coming from the \alpha in the Python/C code. Unfortunately, it's…
Michael A
  • 4,391
  • 8
  • 34
  • 61
2
votes
1 answer

sympy: simplify a larger expression with Binomial formula and quadratic complement

I get some eigenvalues of the matrix import sys import mpmath from sympy import * X,Y,Z = symbols("X,Y,Z") Rxy,Rxz, Ry,Ryx,Ryz, Rz,Rzy,Rzz = symbols("Rxy,Rxz, Ry,Ryx,Ryz, Rz,Rzy,Rzz") J = Matrix([ [ -1, 0, 0], […
2
votes
3 answers

Why does Sympy substitute values incorrectly?

I have a simple equation like (f(t) * g(t))^a, where a is a parameter and f and g are functions of t. The method I'm trying to replicate is Differentiate the expression with respect to t, which should be an expression with f(t), g(t), f'(t), and…
Michael A
  • 4,391
  • 8
  • 34
  • 61