Solving polynomials with complex coefficients using sympy
<p>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,</p>

<pre><code>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)]
</code></pre>

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

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

<p>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,</p>

<pre><code>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)]
</code></pre>

<p>The elements of the resulting array can be evaluated numerically. </p>

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

<p>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.</p>

<p>As per the <a href="https://stackoverflow.com/questions/39254827/solving-polynomials-with-complex-coefficients-using-sympy/40092834#comment65851348_39254827">comment</a> of <a href="https://stackoverflow.com/users/6212875/stelios">Stelios</a>, you can use <a href="http://docs.sympy.org/0.7.1/modules/polys/reference.html#sympy.polys.polytools.nroots" rel="nofollow">sympy.polys.polytools.nroots</a>:</p>

<pre><code>&gt;&gt;&gt; from sympy import solve, nroots, I
&gt;&gt;&gt; from sympy.abc import k
&gt;&gt;&gt; solve(k**6 + 3*I*k**5 - 2*k**4 + 9*k**3 - 4*k**2 + k - 1,k)
[]
&gt;&gt;&gt; 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]
</code></pre>

python numpy math sympy polynomials