# Solving for the roots of a huge polynomial with NSolve

I am new to Mathematica. I thought it was going to be the solution to all my problems. I very naively tried feeding a huge complex polynomial with exponential parts to NSolve. After running the code it does not seem to be computing; it does not return "no solutions"; nor a set of solutions for x.

For

NSolve[-1.0*x^10 + 2.27240187833694*^-8*I*x^9*Exp[10*I*x] +
7.68437888416966*I*x^9 + 1.73169574087938*^-7*x^8*Exp[10*I*x] +
23.4044813384511*x^8 - 5.20791054835238*^-7*I*x^7*Exp[10*I*x] -
36.0135696807004*I*x^7 - 7.85132730855641*^-7*x^6*Exp[10*I*x] -
29.5154618492716*x^6 + 6.20597585823453*^-7*I*x^5*Exp[10*I*x] +
12.3892478542342*I*x^5 + 2.4192289009764*^-7*x^4*Exp[10*I*x] +
2.37763308768566*x^4 - 3.85882723801709*^-8*I*x^3*Exp[10*I*x] -
0.220408659392789*I*x^3 - 2.54561372137026*^-9*x^2*Exp[10*I*x] -
0.0102441292522529*x^2 + 7.03100112140431*^-11*I*x*Exp[10*I*x] +
0.000227506852973307*I*x + 6.82223646304564*^-13*Exp[10*I*x] +
1.91620993166503*^-6 == 0 , x]


the output is just the same expression unevaluated with the terms in reverse order. Any help or suggestions on how to solve this equation would be heavenly. Also alternatives to NSolve if such exist.

• The lefthand side of your equation is not a polynomial since it contains transcendental terms. There is no guarantee such an equations has any zeros nor that Mathematica can find them if they exist without giving it some hint as to where the zeros are located. – m_goldberg Jan 23 '19 at 20:51
• Where did you get the expression you are trying to NSolve[]? – Somos Jan 24 '19 at 1:22
• @Somos determinant of a 10x10 jacobian of a bio population dynamics ode model – mpetric Feb 25 '19 at 16:16

You can use NSolve, you only have to restrict the solution range:

sol = NSolve[{eqn == 0, -3 < Re[x] < 3, -3 < Im[x] < 3}, x, Complex]
(*{{x -> -2.92574 - 1.88571 I}, {x -> -2.28599 - 1.86965 I},
{x -> -1.64163 - 1.85254 I}, {x -> -0.990534 -1.83619 I},
{x -> -0.331534 - 1.8251 I}, {x -> -3.99702*10^-7 +0.991696 I},
{x -> -4.57485*10^-9 + 0.026696 I}, {x -> 0. + 0.0577141 I},
{x -> 0. + 0.0638266 I}, {x ->0. + 0.142966 I}, {x -> 0. + 1.1697 I},
{x -> 0. + 2.1067 I}, {x ->0. + 2.1067 I},
{x -> 4.57485*10^-9 +0.026696 I}, {x ->3.99702*10^-7 + 0.991696 I},
{x -> 0.331534 - 1.8251 I}, {x -> 0.990534 - 1.83619 I},
{x -> 1.64163 - 1.85254 I}, {x -> 2.28599 - 1.86965 I}, {x -> 2.92574 -1.88571 I}}*)


verification of the solution:

zw = ComplexExpand[{Re[#], Im[#]} &[ eqn /. x -> rex + I imx],TargetFunctions -> {Re, Im}];

Show[{ContourPlot[{zw[[1]] == 0, zw[[2]] == 0} // Evaluate, {rex, -3,3}, {imx, -3, 3}, ContourStyle -> {Blue, Red}, MaxRecursion -> 4], Graphics[{Darker[Green], PointSize[.02],Point[{Re[x], Im[x]} /. sol]}]}, FrameLabel -> {Re[x], Im[x]}]


One way is to treat Exp[10 I x] as an independent variable u, solve for x as a polynomial equation, then substitute u back in and solve for x:

eqn = -1.0*x^10 + 2.27240187833694*^-8*I*x^9*Exp[10*I*x] +
7.68437888416966*I*x^9 + 1.73169574087938*^-7*x^8*Exp[10*I*x] +
23.4044813384511*x^8 - 5.20791054835238*^-7*I*x^7*Exp[10*I*x] -
36.0135696807004*I*x^7 - 7.85132730855641*^-7*x^6*Exp[10*I*x] -
29.5154618492716*x^6 + 6.20597585823453*^-7*I*x^5*Exp[10*I*x] +
12.3892478542342*I*x^5 + 2.4192289009764*^-7*x^4*Exp[10*I*x] +
2.37763308768566*x^4 - 3.85882723801709*^-8*I*x^3*Exp[10*I*x] -
0.220408659392789*I*x^3 - 2.54561372137026*^-9*x^2*Exp[10*I*x] -
0.0102441292522529*x^2 + 7.03100112140431*^-11*I*x*Exp[10*I*x] +
0.000227506852973307*I*x + 6.82223646304564*^-13*Exp[10*I*x] +
1.91620993166503*^-6 == 0;

sol = Solve[eqn /. Exp[10*I*x] -> u, x];
sols = Check[FindRoot[Equal @@@ # /. u -> Exp[10*I*x], {x, 1 + I}], Nothing] & /@ sol

sols = FindRoot[Equal @@@ # /. u -> Exp[10*I*x], {x, 5 + I}] & /@ sol
(*
{{x -> 0. + 0.026696 I}, {x -> 0. + 0.026696 I}, {x -> 0. + 0.0577141 I},
{x -> 0. + 0.0638266 I}, {x -> 0. + 0.142966 I}, {x -> -9.19269*10^-25 + 0.991696 I},
{x -> 0. + 0.991696 I}, {x -> 0. + 1.1697 I}, {x -> 0. + 2.1067 I}, {x -> 0. + 2.1067 I}}
*)


Check:

eqn /. Equal -> Subtract /. sols
(*
{1.2191*10^-20 + 0. I, 1.20619*10^-20 + 0. I, -8.47033*10^-22 + 0. I,
-1.01644*10^-20 + 0. I, -2.98156*10^-19 + 0. I, -2.84217*10^-14 + 2.35099*10^-38 I,
-2.13163*10^-14 + 0. I, -1.77636*10^-14 + 0. I, -7.95808*10^-13 + 0. I,
-1.13687*10^-13 + 0. I}
*)

• Your "trick" only evaluates imaginary solutions ... – Ulrich Neumann Jan 24 '19 at 8:54
• @UlrichNeumann FindRoot finds only one root, not necessarily imaginary, of each factor. The Exp[10 I x] means each factor will potentially have infinitely many. – Michael E2 Jan 24 '19 at 12:46
• @ MichaelE2 Thanks, I was wondering why FindRoot only finds solutions with vanishing realpart! – Ulrich Neumann Jan 24 '19 at 13:10