sympy

SymPy: Factorization of polynomials over symbolic roots with combined square roots

╄→гoц情女王★ 提交于 2020-06-28 03:55:32
问题 SymPy factor function can factorize over symbolic roots, e.g. : In [1]: from sympy import * In [2]: init_printing(use_latex=False) In [3]: z, a, b = symbols('z a b') In [4]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [5]: poly Out[5]: 2 √a⋅√b - √a⋅z - √b⋅z + z In [6]: factor(poly, z) Out[6]: (-√a + z)⋅(-√b + z) but the factorization fails if b = a : In [10]: b = a In [11]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [12]: poly Out[12]: 2 -2⋅√a⋅z + a + z In [13]: factor(poly, z) Out

SymPy: Factorization of polynomials over symbolic roots with combined square roots

自作多情 提交于 2020-06-28 03:55:03
问题 SymPy factor function can factorize over symbolic roots, e.g. : In [1]: from sympy import * In [2]: init_printing(use_latex=False) In [3]: z, a, b = symbols('z a b') In [4]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [5]: poly Out[5]: 2 √a⋅√b - √a⋅z - √b⋅z + z In [6]: factor(poly, z) Out[6]: (-√a + z)⋅(-√b + z) but the factorization fails if b = a : In [10]: b = a In [11]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [12]: poly Out[12]: 2 -2⋅√a⋅z + a + z In [13]: factor(poly, z) Out

How to rewrite an expression in terms of an other expression in sympy

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-25 09:11:18
问题 EDIT: I am not asking how to solve an equation in terms of a given variable (as in this supposed duplicated question), but how to represent an expression in terms of an other one, as specified in the question. I believe it is the "duplicated" question to have a misleading title. I am very new with SymPy. I have an expression that, once expressed in terms to an other expression, should become very nice. The problem is that I don't know how to "force" to express the original expression in terms

How to rewrite an expression in terms of an other expression in sympy

让人想犯罪 __ 提交于 2020-06-25 09:10:58
问题 EDIT: I am not asking how to solve an equation in terms of a given variable (as in this supposed duplicated question), but how to represent an expression in terms of an other one, as specified in the question. I believe it is the "duplicated" question to have a misleading title. I am very new with SymPy. I have an expression that, once expressed in terms to an other expression, should become very nice. The problem is that I don't know how to "force" to express the original expression in terms

Full factorization of polynomials over complexes with SymPy

亡梦爱人 提交于 2020-06-17 09:33:12
问题 I want to fully factorize a polynom, thus factorize it over complexes. SymPy provide factor to do it, but I’m very surprised that factorization is done only over integer roots, e.g. : >>> from sympy import * >>> z = symbols('z') >>> factor(z**2 - 1, z) (z - 1)*(z + 1) >>> factor(z**2 + 1, z) z**2 + 1 or >>> factor(2*z - 1, z) 2*z - 1 >>> factor(2*z - 1, z, extension=[Integer(1)/2]) 2*(z - 1/2) An answered question already exists : Factor to complex roots using sympy, and the solution given by

Sympy: lambdify such that operations on arrays always result in arrays, also for constants?

半世苍凉 提交于 2020-06-16 08:31:09
问题 I need to evaluate the derivative of functions (f') given by the user in many points. The points are in a list (or numpy.array, pandas.Series...). I obtain the expected value when f' depends on a sympy variable, but not when f' is a constant: import sympy as sp f1 = sp.sympify('1') f2 = sp.sympify('t') lamb1 = sp.lambdify('t',f1) lamb2 = sp.lambdify('t',f2) print(lamb1([1,2,3])) print(lamb2([1,2,3])) I obtain: 1 [1, 2, 3] The second is alright, but I expected that the first would be a list of

detect if variable is of sympy type

浪子不回头ぞ 提交于 2020-06-15 04:30:21
问题 I have a variable which may or may not be a sympy class. I want to convert it to a float but I’m having trouble doing this in a general manner: $ python Python 2.7.3 (default, Dec 18 2014, 19:10:20) [GCC 4.6.3] on linux2 >>> import sympy >>> x = sympy.sqrt(2) >>> type(x) <class 'sympy.core.power.Pow'> >>> y = 1 + x >>> type(y) <class 'sympy.core.add.Add'> >>> z = 3 * x >>> type(z) <class 'sympy.core.mul.Mul'> >>> if isinstance(z, sympy.core): ... z = z.evalf(50) # 50 dp ... Traceback (most

disabling automatic simplification in sympy

半城伤御伤魂 提交于 2020-06-13 04:04:46
问题 i want to disable automatic simplification in sympy, for example solving the equation x*y-x i want to get x/x instead of 1 import sympy from sympy.abc import x,y,z expr = x*y-x sympy.solve(expr,y) => 1 # i want unsimplified x/x instead of 1 From the sympy manual, i found UnevaluatedExpr for this purpose, but it returns empty list for the example given from sympy import UnevaluatedExpr expr1 = UnevaluatedExpr(x)*UnevaluatedExpr(y)-UnevaluatedExpr(x) sympy.solve(expr1,y) => [] my question is

disabling automatic simplification in sympy

旧城冷巷雨未停 提交于 2020-06-13 04:04:10
问题 i want to disable automatic simplification in sympy, for example solving the equation x*y-x i want to get x/x instead of 1 import sympy from sympy.abc import x,y,z expr = x*y-x sympy.solve(expr,y) => 1 # i want unsimplified x/x instead of 1 From the sympy manual, i found UnevaluatedExpr for this purpose, but it returns empty list for the example given from sympy import UnevaluatedExpr expr1 = UnevaluatedExpr(x)*UnevaluatedExpr(y)-UnevaluatedExpr(x) sympy.solve(expr1,y) => [] my question is

Sympy - altering the range of the y axis for a plot

做~自己de王妃 提交于 2020-06-12 05:11:52
问题 Using Sympy how does one set the range for the y axis ? plot((x**2 + 2)) I wanted to have this so that the y axis would be from 0 to 7 回答1: When you plot you can use the kwargs xlim and ylim to set the axis limits. For example: >>> plot((x**2 + 2), xlim=[-3,3], ylim=[0,7]) 来源: https://stackoverflow.com/questions/33881624/sympy-altering-the-range-of-the-y-axis-for-a-plot