sympy

sympy's solve() command for equations != 0

二次信任 提交于 2021-02-05 11:50:38
问题 As i've read in the sympy docs, the solve() command expects an equation to solve as being equal to zero. As the equations i would like to solve are not in that form and in fact solving them for 0 is my purpose in using a library like sympy, is there a way to get around this? 回答1: What the docs are saying is that if you do something like >>> solve(x**2 - 1, x) Then solve is implicitly assuming that x**2 - 1 is equal to 0 . If you wanted to solve x**2 - 1 = 2 , then you could either subtract 2

sympy's solve() command for equations != 0

我只是一个虾纸丫 提交于 2021-02-05 11:49:40
问题 As i've read in the sympy docs, the solve() command expects an equation to solve as being equal to zero. As the equations i would like to solve are not in that form and in fact solving them for 0 is my purpose in using a library like sympy, is there a way to get around this? 回答1: What the docs are saying is that if you do something like >>> solve(x**2 - 1, x) Then solve is implicitly assuming that x**2 - 1 is equal to 0 . If you wanted to solve x**2 - 1 = 2 , then you could either subtract 2

Sympy - Simplify expression within domain

痴心易碎 提交于 2021-02-05 10:50:50
问题 Can Sympy automatically simplify an expression that includes terms like this one: cos(x)/(cos(x)**2)**(1/2) which can be simplified to 1 in the domain that I am interested in 0 <= x <= pi/2 ? (Examples of other terms that could be simplified in that domain: acos(cos(x)); sqrt(sin(x)**2); sqrt(cos(2*x) + 1); etc.) 回答1: If you know the functions that are in your expression (such as sin , cos and tan ), you can do the following according to this stack overflow question: from sympy import * x =

Python sympy symbols

偶尔善良 提交于 2021-02-05 06:12:04
问题 When I use "x" and "z" as symbols, I have no problem with this code: from sympy import * x, z = symbols('x z') y = -6*x**2 + 2*x*z**0.5 + 50*x - z solve((diff(y, x), diff(y, z))) y.subs({x: 5, z: 25}) But when I use "q" and "a", solve does not give me any solution. q, a = symbols('q a') y = -6*q**2 + 2*q*a**0.5 + 50*q - a solve((diff(y, q), diff(y, a))) y.subs({q: 5, a: 25}) As you can see I use "subs" to check that there is no typo in the objective function. UPDATE: I used "Symbol" to set

Python sympy symbols

南楼画角 提交于 2021-02-05 06:11:14
问题 When I use "x" and "z" as symbols, I have no problem with this code: from sympy import * x, z = symbols('x z') y = -6*x**2 + 2*x*z**0.5 + 50*x - z solve((diff(y, x), diff(y, z))) y.subs({x: 5, z: 25}) But when I use "q" and "a", solve does not give me any solution. q, a = symbols('q a') y = -6*q**2 + 2*q*a**0.5 + 50*q - a solve((diff(y, q), diff(y, a))) y.subs({q: 5, a: 25}) As you can see I use "subs" to check that there is no typo in the objective function. UPDATE: I used "Symbol" to set

SymPy print only function name

自作多情 提交于 2021-02-04 21:10:45
问题 I'm trying to do some symbolic calculations in SymPy but I'm unable to use latex printing and get the graphical output I want. That has always troubled me and have spent several hours (perhaps days) trying to fine a way to customize how objects are printed (in LaTeX, in pprint representation it's well documented). However, in this case I'm trying to make symbolic calculations on an Undefined Function, psi, which depends on x, y, z. However, those calculations imply terms which have up to

SymPy print only function name

試著忘記壹切 提交于 2021-02-04 21:09:25
问题 I'm trying to do some symbolic calculations in SymPy but I'm unable to use latex printing and get the graphical output I want. That has always troubled me and have spent several hours (perhaps days) trying to fine a way to customize how objects are printed (in LaTeX, in pprint representation it's well documented). However, in this case I'm trying to make symbolic calculations on an Undefined Function, psi, which depends on x, y, z. However, those calculations imply terms which have up to

Plot a perfect sphere with equal axes by parametric plot in Sympy

有些话、适合烂在心里 提交于 2021-01-29 10:10:20
问题 I would like to know how using plot3d_parametric_surface in Sympy we can plot a perfect sphere. By perfect I mean with equal axes. The result with this function has an oval shape! from sympy import * from sympy.plotting.plot import plot3d_parametric_surface from sympy.abc import theta , phi plot3d_parametric_surface(sin(phi)*cos(theta) , sin(phi)*sin(theta), cos(phi), (phi,0,pi),(theta,0,2*pi)) I tried to implement the answers in the matplotlib (equal unit length): with 'equal' aspect ratio z

Python memory error in sympy.simplify

。_饼干妹妹 提交于 2021-01-28 18:46:12
问题 Using 64-bit Python 3.3.1 and 32GB RAM and this function to generate target expression 1+1/(2+1/(2+1/...)) : def sqrt2Expansion(limit): term = "1+1/2" for _ in range(limit): i = term.rfind('2') term = term[:i] + '(2+1/2)' + term[i+1:] return term I'm getting MemoryError when calling: simplify(sqrt2Expansion(100)) Shorter expressions work fine, e.g: simplify(sqrt2Expansion(50)) Is there a way to configure SymPy to complete this calculation? Below is the error message: MemoryError Traceback

How to change printed representation of function's derivative in sympy

孤街浪徒 提交于 2021-01-28 11:20:21
问题 In a dynamic system my base values are all functions of time, d(t) . I create the variable d using d = Function('d')(t) where t = S('t') Obviously it's very common to have derivatives of d (rates of change like velocity etc.). However the default printing of diff(d(t)) gives:- Derivative(d(t), t) and using pretty printing in ipython (for e.g.) gives a better looking version of:- d/dt (d(t)) The functions which include the derivatives of d(t) are fairly long in my problems however, and I'd