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

Use Python to calculate P**n while n approach +oo and P is a matrix

The code is import sympy as sm import numpy as np k=sm.Symbol('k') p=np.matrix([[1./2,1./4,1./4],[1./2,0,1./2],[1./4,0,3./4]]) sm.limit(p**k,k,sm.oo) It indicates 'TypeError: exponent must be an integer'. But if I change the matrix to a constant…
Kai
  • 143
  • 2
  • 8
2
votes
1 answer

Trying to convert Matlab .m symbolic function file(s) to SymPy symbolic expression

I have computer generated .m files for electrical circuit transfer functions output by Sapwin 4.0 http://cirlab.dinfo.unifi.it/Sapwin4/ The .m files have fairly simple structure for my present interests: function…
f5r5e5d
  • 3,656
  • 3
  • 14
  • 18
2
votes
0 answers

How to solve this sum with sympy - Wolfram Alpha could do it

I have a pretty simple sum to solve: \sum_{k=1}^\infty p^k/k! * 1/(k + h) Wolfram Alpha does it. I tried to get there with sympy, but failed miserably. from sympy import * h, k, lam, p = symbols('h k lambda p') exprInner = Sum(p**k/factorial(k) *…
FooBar
  • 15,724
  • 19
  • 82
  • 171
2
votes
1 answer

sympy: Incorrect substitution results

I am unable to evaluate and plot a simple (known) function in sympy within Ipython notebook: y(x) = ( F / 6EI )( x^3 - 3Lx^2 ) where: F = 10^6 E = 200E9 I = (1/12)(0.5*1^3) L = 3 I define the expression using symbols() and substitute known…
OnStrike
  • 748
  • 1
  • 6
  • 22
2
votes
1 answer

How do you define the real/imaginary parts of long symbolic expression without evaluation?

I'm new to python and am having trouble with sympy. I define complex equations which are functions of the parameters a, b and use hold=true to save computation time. For example I have defined g in terms of other quantities A,B,C,D,E,F, as, In [92]:…
ben_afobe
  • 95
  • 4
2
votes
2 answers

How can one suppress evaluation while still being able to index?

I have two small but very complicated matrices that I want to multiply. I've done this using sympy: C=sympy.MatMul(A,B,hold=True) This gives me a MatMul object which saves a huge amount of time, and I'm not interested in a symbolic expression…
ben_afobe
  • 95
  • 4
2
votes
1 answer

Sympy coeff not consistent with as_independent

I have the following snippet of code import sympy a = sympy.symbols('a') b = sympy.symbols('b') c = sympy.symbols('c') print((a*b).coeff(c,0)) print((a*b).as_independent(c)[0]) I don't understand why the two print statements print different…
G. W.
  • 21
  • 2
2
votes
1 answer

Converting squared and cube terms into multiplication

I am trying to convert a big expression from sage into valid C code using ccode() from sympy. However, my expression has many squared and cube terms. As pow(x,2) is far slower than x*x, I'm trying to expand those terms in my expression before the…
Domino
  • 43
  • 4
2
votes
1 answer

Solving Non-Linear Differential Equation Sympy

This code only works for solving the differential equation v_equation if v(t) isn't squared. When I squared it it returned the error PolynomialDivisionFailed. Is there another way of doing this with Sympy or should I find a different python package…
Kklj8
  • 137
  • 2
  • 11
2
votes
2 answers

Evaluate sum of step functions

I have a fairly large number (around 1000) of step functions, each with only two intervals. I'd like to sum them up and then find the maximum value. What is the best way to do this? I've tried out sympy, with code as follows: from sympy import…
eagle34
  • 1,424
  • 1
  • 15
  • 19
2
votes
1 answer

Failure to scale in pyclipper - TypeError: 'Zero' object is not iterable

I've just come up against a TypeError I've not seen before and can't figure out why it's occurring. Googling for the error TypeError: 'Zero' object is not iterable returns no results. I've tested in python 2.7 and 3.5 and the error is the same in…
Jamie Bull
  • 12,889
  • 15
  • 77
  • 116
2
votes
2 answers

How does sympy simplify ln((exp(x)+1)/exp(x)) to log(1+exp(-x))?

If I use simplify() function in sympy, log((exp(x)+1)/exp(x)) does simplify to log(1+exp(-x)), however, as I read the doc, the simplify function is "can be unnecessarily slow", I tried other simplification methods, but non of them works, so I'm…
2
votes
1 answer

Sympy's latex printer, folding short fractions

I'm feeding sympy.latex a string involving fractions and I'd like to get its latex representation with fractions "folded", i.e., typeset as 3/2 rather than as \frac{3}{2}. I'm setting the fold_short_fractions keyword argument to True, but the…
fmg
  • 813
  • 8
  • 18
2
votes
1 answer

sympy.geometry Point class is working slow

I have a code which reads unstructured mesh. I wrote wrappers around geometric entities of sympy.geometry such as: class Point: def __init__(self, x, y, parent_mesh): self.shape = sympy.geometry.Point(x,y) self.parent_mesh =…
Shibli
  • 5,879
  • 13
  • 62
  • 126
2
votes
0 answers

Oriented bounding box in SymPy

I use SymPy's geometry module for geometric stuff. I need OBBs but so far I could not came across this feature in SymPy. Does SymPy really provide OBBs? If not is there a module to download as I do not want to re-code.
Shibli
  • 5,879
  • 13
  • 62
  • 126
1 2 3
99
100