>>>从sympy导入*>>>z =符号('z')>>>因子(z ** 2-1-z)(z-1)*(z +1)>>>因子(z ** 2 + 1,z)z ** 2 + 1 或 >>>因子(2 * z-1,z)2 * z-1>>>因子(2 * z-1,z,扩展名= [整数(1)/2])2 *(z-1/2) 已经存在一个已回答的问题:使用sympy的复杂根因子,以及 asmeurer 作品: >>>因子(z ** 2 + 1,z,扩展= [I])(z-I)*(z + I) ,但是您需要指定非整数根的每个除数,例如 : >>>因子(z ** 2 + 2,z,扩展= [I])z ** 2 + 2>>>因子(z ** 2 + 2,z,扩展= [I,sqrt(2)])(z-sqrt(2)* I)*(z + sqrt(2)* I) 我的问题是:如何完全分解一个多项式(从而超过复数),而无需给每个除数赋予扩展? asmeurer 提供了解决方案: >>>多边形= z ** 2 + 2>>>r =根(poly,z)>>>LC(poly,z)* Mul(* [(z-a)** r [a] for a in r])/___ \/___ \\ z-\/2 * I/* \ z + \/2 * I/ 但是它应该存在一种本地方法,不是吗?像 factor(poly,z,complex = True)之类的东西.我在 factor 的文档,但是我什么都没找到.此外, factor 可以将 domain 用作可选参数,我认为允许指定进行分解的集合,而 >>>因子(z ** 2 + 2,z,domain ='Z')2个z + 2>>>因子(z ** 2 + 2,z,domain ='R')/2 \2.0 * \ 0.5 * z + 1.0/>>>因子(z ** 2 + 2,z,domain ='C')2个1.0 * z + 2.0 解决方案 domain参数应该起作用,在高斯有理情况下,您也可以使用 gaussian = True 等效于extension = I : 在[24]中:factor(z ** 2 + 1,gaussian = True)输出[24] :( z-ⅈ)⋅(z +ⅈ) 这在您的情况下不起作用,因为分解需要超过 QQ(I,sqrt(2)),而不是 QQ(I).域'R'和'C'无法按预期工作的原因是,它们是不精确的浮点域,而不是表示形式中实数或复数的域纯粹的数学意义和因式分解是以上方法可以结合使用 在[28]中:e = z ** 2 + 2在[29]中:factor(e,extension = roots(e))Out [29] :( z-√2⋅ⅈ)⋅(z +√2⋅ⅈ) 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 + 1or>>> 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 asmeurer works :>>> factor(z**2 + 1, z, extension=[I])(z - I)*(z + I)but you need to specify every divisor of non-integer roots, e.g. :>>> factor(z**2 + 2, z, extension=[I])z**2 + 2>>> factor(z**2 + 2, z, extension=[I, sqrt(2)])(z - sqrt(2)*I)*(z + sqrt(2)*I)My question is : how to fully factorize a polynom (thus over complexes), without needing to give every divisor to extension ?asmeurer gives a solution to do this :>>> poly = z**2 + 2>>> r = roots(poly, z)>>> LC(poly, z)*Mul(*[(z - a)**r[a] for a in r])/ ___ \ / ___ \\z - \/ 2 *I/*\z + \/ 2 *I/But it should exists a native way to do it, no ?Someting like factor(poly, z, complex=True).I looked for in the documentation of factor, but I did not find anything.Futhermore, factor can take domain as optional argument that I believed allows to specified the set on which the factorization is made, but not >>> factor(z**2 + 2, z, domain='Z') 2z + 2>>> factor(z**2 + 2, z, domain='R') / 2 \2.0*\0.5*z + 1.0/>>> factor(z**2 + 2, z, domain='C') 21.0*z + 2.0 解决方案 The domain argument should work and in the case of Gaussian rationals you can also use gaussian=True which is equivalent to extension=I:In [24]: factor(z**2 + 1, gaussian=True)Out[24]: (z - ⅈ)⋅(z + ⅈ)That doesn't work in your case though because the factorisation needs to be over QQ(I, sqrt(2)) rather than QQ(I). The reason that domains 'R' and 'C' don't work as expected is because they are inexact floating point domains rather than domains representing the real or complex numbers in the pure mathematical sense and factorisation isThe approaches above can be combined though withIn [28]: e = z**2 + 2In [29]: factor(e, extension=roots(e))Out[29]: (z - √2⋅ⅈ)⋅(z + √2⋅ⅈ) 这篇关于使用SymPy对复合物的多项式进行完全因式分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 02:07