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

Octave dsolve SymPy Error: Python exception: AttributeError: 'list' object has no attribute 'subs'

(I tried posting this in Scientific Computing but they said to post it here; sorry if this is again off-topic.) I'm using dsolve on Octave for the first time (Thanks so much for including this feature, BTW; this SimPy connection is just great), and…
2
votes
2 answers

find out if trigonometric is been used and track symbol variable

I will have data which uses degrees for the trigonometric functions. I will use sympy and since it uses radians for the trigonometric functions, I want to be able to convert and use degrees. But, I will not know which symbol variable is been used as…
George
  • 5,808
  • 15
  • 83
  • 160
2
votes
2 answers

Set global settings for Latex Printing in sympy

I want to use the latex() command from sympy a lot in my code. However I want every multiplication to be printed with a dot, and I do this by adding mul_symbol= "dot" after the variable I want the latex form of. Can I make these setting global, so I…
kassio
  • 57
  • 1
  • 12
2
votes
1 answer

Sympy - Limit with parameter constraint

I try to calculate the limit of a function with a constraint on one of its parameters. Unfortunately, I got stuck with the parameter constraint. I used the following code where 0 < alpha < 1 should be assumed import…
Fabian
  • 103
  • 6
2
votes
3 answers

How to format complex number in Python

In my Python script for the line result = sp.solve(eqn) I get the following output in the format similar to result = 0.0100503358535014*I I gather this means the solution is a complex number. So in this case it could also be seen as result =…
Catherine
  • 727
  • 2
  • 11
  • 30
2
votes
1 answer

Assign Matrix slice in SymPy

I would like to replace the value of a slice of a Matrix in SymPy. Explicitly, it would be something like import sympy as sym A = sym.Matrix(4, 4, range(16)) A[0, :] = [-1, -2, -3, -4] But this returns an error ShapeError: The Matrix `value`…
nicoguaro
  • 3,629
  • 1
  • 32
  • 57
2
votes
1 answer

Check if a Sympy expression simplifies to a constant

Is there a way (within Sympy) to check if two expressions differ by a mere constant? In other words, is there something like a is_constant() function? My minimum working example: from sympy import symbols, simplify x,y = symbols('x y') expr1 =…
2
votes
1 answer

Sum with index as derivative order

I want to define a sum that contains derivatives of a function, where the summation index is the derivative order. Simple example: x, i = symbols("x i") f = Function("f")(x) Sum(diff(f,x,i), [i,1,3]) However, this only returns a sum of zeros. I…
Eskil
  • 3,385
  • 5
  • 28
  • 32
2
votes
0 answers

What is the correction definition of `sympy.vector.CoordSysCartesian.rotation_matrix`?

A rotation matrix can either be written in two ways. With row unit vectors, [ ex_0 ex_1 ex_2] [ ey_0 ey_1 ey_2] [ ez_0 ez_1 ez_2] Or with column unit vectors, [ ex_0 ey_0 ez_0] [ ex_1 ey_1 ez_1] [ ex_2 ey_2 ez_2] In the following code which…
Daniel Farrell
  • 9,316
  • 8
  • 39
  • 62
2
votes
0 answers

how to display a rendered latex output on sage math cloud

Is there a way to display a rendered LaTex output on the Sage Math cloud? I am looking for something along the lines of the sympy live shell, but with functionality for plotting.
Anon
  • 25
  • 2
2
votes
1 answer

SymPy: Taylor series using variable other than x?

I've been searching the docs, but I'm stuck: SymPy seems to be assuming a variable "x" even when I've only declared "t" and "y(t)". I asked it to give me a series for y(t), and this is what I get... >>> from sympy import * >>> var('t') t >>> y =…
sh37211
  • 1,411
  • 1
  • 17
  • 39
2
votes
1 answer

How do I use operations such as -, +, *, / on equations in sympy?

from sympy import * nx, ny, nz = symbols('nx ny nz') ax, ay, az = symbols('ax ay az') bx, by, bz = symbols('bx by bz') e1 = Eq(ax * nx + ay * ny + az * nz, 0) e2 = Eq(bx * nx + by * ny + bz * nz, 0) e3 = Eq(nx**2 + ny**2 + nz**2,…
Maik Klein
  • 15,548
  • 27
  • 101
  • 197
2
votes
2 answers

Evaluate Sympy boolean expression in python

I am using Python and Sympy. I have the following: x,y,z = Symbols('x,y,z') doc = {x : False, y : True, z: True} rule = Or(x, And(y,z)) I am looking for a function in Sympy that will return True on rule.eval(doc)? Edit: Currently I am using…
Shevach
  • 717
  • 9
  • 25
2
votes
2 answers

How do I print a sympy variable with its name in an IPython notebook?

Consider two variables defined using sympy in an IPython (Jupyter) notebook: R_g =Symbol(r'R_{g}') L_g =Symbol(r'L_{g}') Imagine I do some mathematical operations and then I end up with a complicated expression, whose features can be…
wander95
  • 1,298
  • 1
  • 15
  • 22
2
votes
2 answers

Why can't I evaluate a composition of implemented_functions in SymPy at a point?

The code is pretty self-explanatory: >>> from sympy.utilities.lambdify import implemented_function >>> f = implemented_function('f', lambda x: x ** 2) >>> g = implemented_function('g', lambda x: 2 * x) >>> print(f( 2 ).evalf()) 4.00000000000000 >>>…
user541686
  • 205,094
  • 128
  • 528
  • 886