Solving polynomials with complex coefficients using sympy

ben_afobe

I'm very new to python so forgive me if this has a simple fix. I'm trying to solve polynomials with complex coefficients using sympy. I find that I get a blank output if k is 'too complicated'... I'm not quite sure how to define what that means just yet. As a first example consider this fourth order polynomial with complex coefficients,

In [424]: solve(k**4+ 2*I,k)
Out[424]: 
[-2**(1/4)*sqrt(-sqrt(2)/4 + 1/2) - 2**(1/4)*I*sqrt(sqrt(2)/4 + 1/2),
 2**(1/4)*sqrt(-sqrt(2)/4 + 1/2) + 2**(1/4)*I*sqrt(sqrt(2)/4 + 1/2),
 -2**(1/4)*sqrt(sqrt(2)/4 + 1/2) + 2**(1/4)*I*sqrt(-sqrt(2)/4 + 1/2),
 2**(1/4)*sqrt(sqrt(2)/4 + 1/2) - 2**(1/4)*I*sqrt(-sqrt(2)/4 + 1/2)]

there are no problems obtaining an output. I'm interested, though, in solving something like,

In [427]: solve(k**6 + 3*I*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1,k)
Out[427]: []

which is a lot more complicated and returns an empty list. I can, however, solve this using maple, for instance. Also, note that in removing the complex coefficients, there are no issues,

In [434]: solve(k**6 + 3*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1,k)
Out[434]: 
[CRootOf(k**6 + 3*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1, 0),
 CRootOf(k**6 + 3*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1, 1),
 CRootOf(k**6 + 3*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1, 2),
 CRootOf(k**6 + 3*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1, 3),
 CRootOf(k**6 + 3*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1, 4),
 CRootOf(k**6 + 3*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1, 5)]

The elements of the resulting array can be evaluated numerically.

So, is this a problem to do with complex coefficients? How can I solve equations like the one on line [427]?

I have tried to solve with nsolve() and factor the roots out one by one, though I've had no luck with this method either.

Cimbali

As per the comment of Stelios, you can use sympy.polys.polytools.nroots:

>>> from sympy import solve, nroots, I
>>> from sympy.abc import k
>>> solve(k**6 + 3*I*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1,k)
[]
>>> nroots(k**6 + 3*I*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1)
[-2.05972684672 - 0.930178254620881*I, -0.0901851681681614 + 0.433818575087712*I, -0.0734840785305346 - 0.434217215694685*I, 0.60726931721974 - 0.0485101438937812*I, 0.745127208196241 + 0.945593905069312*I, 0.870999568002712 - 2.96650686594768*I]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sympy polynomials with `mpfr` coefficients?

From Dev

SML - Multiplying Coefficients of Polynomials

From Dev

how to multiply Polynomials coefficients

From Dev

Coefficients of polynomials maxima

From Dev

Solving exponential equation using sympy?

From Dev

RuntimeError in solving equation using SymPy

From Dev

Factor to complex roots using sympy

From Dev

complex matrix in sympy using python

From Dev

complex matrix in sympy using python

From Dev

Sympy expression as ratio of polynomials

From Dev

Sympy expression as ratio of polynomials

From Dev

How to simplify an expression for a complex constant using sympy?

From Dev

Matching coefficients with sympy

From Dev

numpy fit coefficients to linear combination of polynomials

From Dev

How to extract all coefficients in sympy

From Dev

Factor sympy expression to matrix coefficients?

From Dev

sympy: Collect symbols for matrix coefficients?

From Dev

Sympy extract Fourier Series coefficients

From Dev

Factor sympy expression to matrix coefficients?

From Dev

Sympy extract Fourier Series coefficients

From Dev

Solving Differential Equation Sympy

From Dev

Solving list of expressions in sympy

From Dev

How to combine polynomials in matrix operations in Sympy?

From Dev

Why does sympy.diff not differentiate sympy polynomials as expected?

From Dev

Plot the multiplication of complex roots of fractional polynomials

From Dev

Comparing two polynomials with vector's coefficients C++

From Dev

Generate all polynomials with coefficients 0 or 1 given degree n

From Dev

construct sympy.poly from coefficients and monomials

From Dev

Basic algebra with sympy: keep coefficients and variables together

Related Related

HotTag

Archive