sympy

Given a matrix A, find all matrices such that AB = BA

若如初见. 提交于 2021-02-11 12:44:52
问题 Given a square matrix A, find all matrices X such that AX = XA. This is a particular case of a Sylvester equation (one of the form AX + XB = Q) when A = B and Q is the zero matrix. I know SciPy has a solver for this type of equations, however, since the zero matrix is always a solution to my equation, this solver just gives me this trivial solution. There are infinite solutions to the equation AX = XA, so I'm actually looking for a way to find a basis of the space of solutions. Here's my

Substitute in sympy wihout evaluating or simplifying the expression

拜拜、爱过 提交于 2021-02-10 18:04:04
问题 Consider the follwing example: from sympy import * x = Symbol('x') f = sqrt(3*x + 2) Now I want to substitute a number, say 5 for x and get a LaTeX represenation, in this case it should return \\sqrt(3\\cdot 5 + 2) How can I do this? I tried latex(f.subs(x,2,evaluate=False)) but this results just in \\sqrt(17) . 回答1: Use UnevaluatedExpr(5) instead of 5: >>> latex(f.subs(x, UnevaluatedExpr(5))) '\\sqrt{2 + 3 \\cdot 5}' This wrapper prevents the expression inside of it ("5") from interacting

How to propagate `\n` to sympy.latex()

僤鯓⒐⒋嵵緔 提交于 2021-02-10 15:59:52
问题 The Goal is to format a polynomial with more than 6 parameters into a plot title. Here is my polynomial parameter to string expression function, inspired by this answer, followed by sym.latex() : def func(p_list): str_expr = "" for i in range(len(p_list)-1,-1,-1): if (i%2 == 0 and i !=len(p_list)): str_expr =str_expr + " \n " if p_list[i]>0: sign = " +" else: sign = "" if i > 1: str_expr = str_expr+" + %s*x**%s"%(p_list[i],i) if i == 1: str_expr = str_expr+" + %s*x"%(p_list[i]) if i == 0: str

Python, Kivy, Buildozer: APK crashes with SymPy

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 15:44:02
问题 As the title says, I've made an .apk to run on my Android mobile. It runs perfectly on PC. As soon as I take out all SymPy commands, it runs on Android too. I've mentioned the "sympy" in the buildozer.spec file, and it's not giving any errors. But as soon, as the loading on my Android-screen is over, the App disappears. Does anyone know, if I have to do more, than mentioning the sympy in the .specs file? ADB-Logcat: "ImportError: No module named unittest" I don't know, what "unittest" ist,

Python, Kivy, Buildozer: APK crashes with SymPy

大城市里の小女人 提交于 2021-02-10 15:42:08
问题 As the title says, I've made an .apk to run on my Android mobile. It runs perfectly on PC. As soon as I take out all SymPy commands, it runs on Android too. I've mentioned the "sympy" in the buildozer.spec file, and it's not giving any errors. But as soon, as the loading on my Android-screen is over, the App disappears. Does anyone know, if I have to do more, than mentioning the sympy in the .specs file? ADB-Logcat: "ImportError: No module named unittest" I don't know, what "unittest" ist,

Solving a system of 2nd order differential equations from sympy

。_饼干妹妹 提交于 2021-02-10 14:50:39
问题 I am doing a multiple DOF dynamics problem, using 2nd order Lagrangian equations. I used sympy to get to the equations of motion. Now these equations after calculating the derivatives got quite long, seems though that sympy simplify cant simplify it further. My problem actually is how to solve this system of three 2nd order ode from here. I don't know how to get these equations converted so they can be used with scipy.odeint(). Substitution came to mind, but there are a lot of symbols. So Im

Summation over a sympy Array

[亡魂溺海] 提交于 2021-02-10 08:44:59
问题 I want to sum over a sympy Array (called arr ) using the two indices i and j . Summing over arr[i] results in an integer as In [4] below shows. However, summing over arr[j] does not give a number as result (see In [5] below). Why is that? In [1]: from sympy import * In [2]: i, j = symbols("i j", integer=True) In [3]: arr = Array([1, 2]) In [4]: summation( ...: arr[i], ...: (j, 0, i), (i, 0, len(arr)-1) ...: ) Out[4]: 5 In [5]: summation( ...: arr[j], ...: (j, 0, i), (i, 0, len(arr)-1) ...: )

Summation over a sympy Array

断了今生、忘了曾经 提交于 2021-02-10 08:44:05
问题 I want to sum over a sympy Array (called arr ) using the two indices i and j . Summing over arr[i] results in an integer as In [4] below shows. However, summing over arr[j] does not give a number as result (see In [5] below). Why is that? In [1]: from sympy import * In [2]: i, j = symbols("i j", integer=True) In [3]: arr = Array([1, 2]) In [4]: summation( ...: arr[i], ...: (j, 0, i), (i, 0, len(arr)-1) ...: ) Out[4]: 5 In [5]: summation( ...: arr[j], ...: (j, 0, i), (i, 0, len(arr)-1) ...: )

Summation over a sympy Array

穿精又带淫゛_ 提交于 2021-02-10 08:44:04
问题 I want to sum over a sympy Array (called arr ) using the two indices i and j . Summing over arr[i] results in an integer as In [4] below shows. However, summing over arr[j] does not give a number as result (see In [5] below). Why is that? In [1]: from sympy import * In [2]: i, j = symbols("i j", integer=True) In [3]: arr = Array([1, 2]) In [4]: summation( ...: arr[i], ...: (j, 0, i), (i, 0, len(arr)-1) ...: ) Out[4]: 5 In [5]: summation( ...: arr[j], ...: (j, 0, i), (i, 0, len(arr)-1) ...: )

How to avoid Sympify to drop parentheses automatically

血红的双手。 提交于 2021-02-09 10:59:12
问题 Let's say I have the following string str1 = "a*(-d*(b+d)+d*(e*f))" If I sympify it the result is a*(d*e*f - d*(b + d)) But I don't want that Sympy drop those parenthesis. I want the final expression to be a*(d*(e*f) - d*(b + d)) How can this be done? 回答1: That's a known bug. That same bug in the google code archive. If you follow the google code archive link, you'll find a patch that possibly fixes your issue. Other than that, there's not much you can do. The issue's status is still open