Skip to main content
How are we doing? Please help us improve Stack Overflow. Take our short survey
Filter by
Sorted by
Tagged with
0 votes
1 answer
36 views

How can I repeatedly update a variable in my sympy summation?

I have a sympy summation in python, and I am currently using a variable that is repeatedly updated each time I say it. It's called result. In my summation, I want to be able to perform this action ...
user27394478's user avatar
1 vote
0 answers
48 views

How to solve the derivative of the expression with respect to D?

The integral is Where the variables follow the following distribution: Thus, the integral becomes: Now, my code in python is to integrate the expression with \(W_{1:3}\) being \(1,2,3\) ...
Mea12's user avatar
  • 59
0 votes
2 answers
73 views

solve Sympy functions in Scipy (optimize.root)

I'm trying to find the roots with the root function in Scipy for functions/variables created in Sympy. sympy: AllEquations = [x1 - 5, y1 - 5, z1 - 5, ((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)**0.5 -...
Achaibou Karim's user avatar
-1 votes
0 answers
63 views

How can I make one variable in my summation do even numbers and the other do odd numbers? [closed]

I'm coding in python and I want to use my variables i and j for even numbers or odd numbers. I tried asking ChatGPT and it gave me a result that I'm not sure is working. This result will be in the ...
Ryan Pflum's user avatar
0 votes
1 answer
27 views

How can I use the values in my sympy summation in my piecewise properly?

I have a sympy summation in python and I want to add the summation value that my sympy symbol is currently to a variable in python so it can use numbers to run non symbolic functions. The code I'm ...
user27394478's user avatar
0 votes
0 answers
27 views

Validating SymPy mechanics

I am new to using SymPy mechanics and hope to use it extensively for my work. However, I am having trouble understanding some of the basics of the notation. Therefore, I have tried to create a simple ...
Nick's user avatar
  • 31
3 votes
0 answers
57 views

Latex formulas common parts detector

I have a task to make an anti-plagiarism of formulas. It is necessary for it to highlight similar places in two formulas (example in the photo). But there is a problem, after I found these similar ...
Дмитрий Дашкин's user avatar
0 votes
0 answers
43 views

Sympy avoid incorrect output when simplifying sum of Kronecker delta with Piecewise

from sympy.abc import x, i, j, n from sympy import * x = IndexedBase('x') U = -Sum(Piecewise((KroneckerDelta(i, j, (1, n)), x[i] > 0), (0, True)), (i, 1, n)) print(simplify(U)) # Output: Piecewise(...
causative's user avatar
  • 101
0 votes
1 answer
42 views

Sympy simplify sum of Kronecker delta with Piecewise

from sympy.abc import i, j, n from sympy import * from sympy.concrete.delta import _simplify_delta x = IndexedBase('x') U = Sum(KroneckerDelta(i, j, (1, n)) * (x[i] + 1), (i, 1, n)) U1 = Sum(...
causative's user avatar
  • 101
0 votes
2 answers
34 views

Solve a transcendental equation with sympy

I have trouble solving the following simple equation with sympy. Sympy seems to take way too much time to produce a result. import sympy as sp sp.solve(sp.Eq(1000/(sp.exp(log(39) - 1000*k) + 1), 100), ...
Dimitrios ANAGNOSTOU's user avatar
0 votes
1 answer
95 views

Sympy running without providing solution given initial conditions

I have 2 differential equations I am trying to solve. Running the code below takes about an hour on my computer before it outputs a very long equation if i do not include the initial conditions. I ...
noah rivas's user avatar
2 votes
2 answers
81 views

Numerically integrate function with parameters

I have an integrand function f(x) that depends on x and several other parameters, a1, a2, a3, etc. This function could be hard or impossible to integrate symbolically via SymPy; that's why I want to ...
AlexGenesis's user avatar
0 votes
1 answer
26 views

sympy.polys.polyerrors.PolynomialError: non-commutative expressions are not supported

I hit the following error using sympy.groebner: "sympy.polys.polyerrors.PolynomialError: non-commutative expressions are not supported". In the real case, I have a very diffcult expression ...
fghoussen's user avatar
  • 555
0 votes
3 answers
67 views

TypeError: 'Piecewise' object is not iterable when trying to sum over sympy.Piecewise result

I'm coding using sympy in python and I'm trying to make some calculations on tuples but everytime I try to use the previous result in the next result it's giving me the error: TypeError: 'Piecewise' ...
RuthChris's user avatar
0 votes
1 answer
37 views

Is there a way to convert from instances of sympy.core.numbers classes to python's native classes

When using sympy.solve(x,x), the output is always a sympy class, rather than being a native python class. Context: I am implementing the concept of Infinite Sets (like the set of integers, rationals ...
TVMaths's user avatar
0 votes
0 answers
31 views

Simplify expected value expression in Simpy

Is there a way to simplify an equation with expected values without explicitly calculating them? For example, let X, Y be two dependent random variables. My equation is: from sympy.stats import E E(X ...
Aleksandra's user avatar
0 votes
1 answer
69 views

Sum of random variables in Sympy

I want to evalute the expectation value and variance of sums over random variables with sympy. Let's say x is Poisson distributed with some lambda > 0. I have a sum over n samples from x_i. My ...
WhyNoPython's user avatar
1 vote
0 answers
18 views

Time dependant ODE parameters / varaibles in PyMC and Sunode

I have an ODE function ode(y,t,theta, influent) where influent is an array of values at different times (experimental data for input to system). I have this in my main ode function (not as important): ...
Rvdb's user avatar
  • 11
0 votes
1 answer
41 views

Lambdify doesn't work on the derivative of a conjugate

I have very ugly symbolic functions on which I would like to do some operations, then lambdify them. Among others, I need to take the derivative of the conjugate. My issue: the derivative and the ...
Reflets de Lune's user avatar
0 votes
2 answers
93 views

Sympy - return Real solution

I'm using the GeoSolver package to solve 3D constraints.link to GeoSolver - PyPI. When I solve a parallel constraint I get a complex solution while a Real solution exist. Is it possible to get only ...
Achaibou Karim's user avatar
0 votes
1 answer
53 views

Matplotlib cannot plot function created with lamdify

I am trying to plot a function created from a string with implemented_function and lambdify. The function works for calculating single values, but not for plotting. I get an error, which states "...
Hendrik's user avatar
0 votes
1 answer
40 views

Octave can't import sympy

I am on Mac M1 and I installed Octave with homebrew and need the Symbolic package. The Symbolic package depends on sympy. I installed sympy with pipx and my .zshrc file is this: export PATH="$...
malligator's user avatar
4 votes
1 answer
95 views

Why does sympy.perfect_power(-64) return False?

The documentation for sympy.perfect_power says: Return (b, e) such that n == b**e if n is a unique perfect power with e > 1, else False (e.g. 1 is not a perfect power). A ValueError is raised if n ...
William Hu's user avatar
0 votes
0 answers
52 views

Why does SymPy give eigenvectors for a degenerate subspace that dont form valid projection operators?

I am trying to use SymPy to symbolically calculate each set of projection operators corresponding to the eigen subspaces of each of the matrices defined in the list An: import numpy as np import sympy ...
Riemann's user avatar
0 votes
2 answers
72 views

Using python/sympy to find quadratic form of a matrix

I want to find the quadratic form of A, but what I get from $P^TAP$ is not in quadratic form: A = Matrix([[4,4,0,-3], [4,4,3,0], [0,3,4,4], [-3,0,4,4]]) eigen_data = A.eigenvects() eigenvectors = [...
JackOfAllTrades's user avatar
1 vote
2 answers
71 views

How can I rewrite the complex number z = 5^i into standard form z=cos(log(5)) + i * sin(log(5)) with SymPy?

I would like to write complex numbers z into the standard form z = a + i b with a and b real numbers. For most of my cases, the sympy construct z.expand(complex=True) does what I am expecting but not ...
terben's user avatar
  • 70
2 votes
1 answer
76 views

How to calculate transfer function with Iout/Iin instead for parallel rlc tank?

I am trying to calculate the RLC tank transfer function using LCAPY. I know what the answer should be but I want to do it with code. The issue is there isn't a current() or voltage() function in LCAPY ...
coder's user avatar
  • 123
0 votes
0 answers
54 views

Does not calculate normalization expressions, basic modes, sympy

I'm trying to calculate normalization expressions for poloidal velocity modes from sympy import sqrt, integrate, symbols, diff C1_, C2_, C3_, C4_, r, z = symbols("C1_, C2_, C3_, C4_, r, z", ...
SssSssS's user avatar
3 votes
2 answers
80 views

Formatting Nested Square Roots in SymPy

I'm working with sympy to obtain symbolic solutions of equation. This is my code: import sympy as sp # Define the symbolic variable x = sp.symbols('x') # Define f(x) f = ((x**2 - 2)**2 - 2)**2 - 2 #...
Mark's user avatar
  • 1,759
0 votes
1 answer
57 views

How to get all solutions of a nonlinear system equations

I am trying to obtain the steady state points of the following ODE system for a SIR model (steady state points are the solutions when the equations of the system equal zero): import sympy as sp S, I, ...
YoshiroVilchez's user avatar
0 votes
1 answer
43 views

Problem in sympy with limit of an expression at infinity

The following code give the answer : nan instead of -pi/4 Could you tell me where the problem is ? import sympy as sp # sympy.org sp.init_printing(use_unicode=True) x= sp.Symbol('x', real=True) ...
PCA's user avatar
  • 1
1 vote
2 answers
224 views

Trying to import latex2sympy2 and ERROR "ModuleNotFoundError: No module named 'typing.io'; 'typing' is not a package"

I followed step by step installation for the Latex Sympy Calculator from this page : https://github.com/OrangeX4/Latex-Sympy-Calculator/blob/main/README.md But when trying, on VS Code, import ...
guiné's user avatar
  • 133
0 votes
0 answers
64 views

Importing sympy leads to a recursion error

I am running Python 3.12.7 built from source on a Raspberry Pi 5 8GB Model B Rev 1.0 (default 64-bit Raspbian based on Debian 12/bookworm). When importing sympy (literally import sympy), I get the ...
Danry Bir's user avatar
0 votes
2 answers
64 views

sympy simplify expression with power-reduction formula

I have the following sympy expression >>> a ⎛2⋅π⋅(x - y)⎞ 2 - 2⋅cos ─────────── ⎝ P ⎠ which I would like to simplify to 2 ⎛π⋅(x - y)⎞ 4⋅sin ───────── ...
joaoFaria's user avatar
  • 125
1 vote
0 answers
68 views

In my sympy piecewise expression how do i specify the value of what x is everytime in my function?

I'm coding in python and I have a sympy summation that is almost complete with the formula that I want to use. I want to add the current value of x to the c value in my function so that it will print ...
RuthChris's user avatar
0 votes
0 answers
65 views

Skipping certain values

I have some Python code that looks for perfect squares. But I know values it can skip, namely values of \$r\$, \$a\$ and \$b\$ that can be written in the following form (where \$n\$ is a postive ...
Jan Eerland's user avatar
0 votes
0 answers
58 views

How do I use the next value in my counter in hex() while also using sympy in python?

I'm coding in python and I have a small problem. I have a class that increments up by 1 each time it's used. In sympy summations, when a different number is used for the formula, I want to calculate ...
RuthChris's user avatar
0 votes
0 answers
88 views

"RecursionError: maximum recursion depth exceeded while calling a Python object" we calculating phase angle of transfer funciton

I am calculating the transfer function and want to come up with a general equation for the angle of the numerator and denominator. The code for the angle of the denominator causes an error that says &...
coder's user avatar
  • 123
0 votes
1 answer
51 views

Why isn't the following sympy code recognizing s?

I am writing code to calculate the transfer function of an RC circuit. It is supposed to result in an equation with a numerator and denominator where the denominator contains an s term. The latex ...
coder's user avatar
  • 123
1 vote
2 answers
89 views

Render LATEX math in Excel using Python in Excel

I'd like to use Python in Excel to display some LATEX math formulas in cells. Creating these images is easy when just using the sympy library, but one has to have latex installed. Python in Excel runs ...
Rick's user avatar
  • 45.1k
1 vote
1 answer
63 views

SymPy TR8 Trigonometric Linearization Not Working as Expected

I'm using SymPy version 1.13.3 to integrate an expression involving trigonometric functions. My goal is to linearize trigonometric products using the TR8 function from sympy.simplify.fu. However, the ...
Thomas Guegamian's user avatar
0 votes
1 answer
58 views

sympy.solve never returns for certain coefficients

The form of the expression (corresponding the the variable called 'expression' below) whose critical points I'm trying to solve for is identical in all cases since the only thing that is changing ...
user11629's user avatar
  • 113
0 votes
1 answer
53 views

Expression replacement with Wildcard variable only works in isolation

I am trying to replace a subexpression. There are many questions on this topic, but I've found that using a wildcard variable as a multiplier seems to work in isolation but not when there are extra ...
jared's user avatar
  • 8,791
0 votes
0 answers
35 views

Issue using Sympy to simplify piecewise functions

I've spent one week doing math research based on a computation that turned out to be incorrect due to an error in Sympy's simplification of piecewise functions. Does anyone know why this mistake ...
Thomas Guegamian's user avatar
1 vote
1 answer
48 views

Error when trying to apply a conditional statement to sympy

I'm trying to set a conditional statmeent in sympy so that when the iterable is not equal to a certain number (30) in this case, it returns 0. My code is: def formula(address): address0 = 30 ...
user27394478's user avatar
0 votes
0 answers
42 views

Is there a MatrixSymbol version of complex=True?

In order to solve equations like (x+conjugate(x)=0), Sympy needs you to tell it that x is a complex variable, e.g. x = symbols('x', complex=True) solve((x-conjugate(x)).as_real_imag(),x) The output ...
Joshua Ruiter's user avatar
0 votes
2 answers
51 views

Solving equations involving complex conjugates

I am trying to solve a system of equations using the Sympy solve() method, and my equations involve complex conjugates of the variables. This results in solve() sometimes not finding a solution which ...
Joshua Ruiter's user avatar
1 vote
2 answers
95 views

How to use jax.custom_vjp with functions that take non-JAX types (e.g., SymPy expressions) as inputs?

I'm trying to use JAX's custom_vjp to define custom gradient computations for a function that takes a SymPy expression as an input. However, I'm encountering errors because JAX doesn't support non-JAX ...
James Yong's user avatar
1 vote
0 answers
45 views

Composition of user-defined functions in SymPy

I am expecting achieve function composition. The output for laplace defined as composition is different to symmetric This is my tried. from sympy import Function, Symbol from sympy.printing import ...
Oromion's user avatar
  • 129
2 votes
1 answer
144 views

How can I create parameterized matrices and generate the final matrix on demand with the parameters in Python?

I am in a situation where I need to work with parameterized matrices. For e.g., say I start with two matrices A and B, A = [1 2] B = [a b] [3 4] [5 6] Here matrix B is parameterized ...
smi's user avatar
  • 23

1
2 3 4 5
120