3
$\begingroup$

I have a Table of 6 plots of polynomials of increasing degree, using ComplexPlot3D:

Clear["Global`*"]; 
poly[z_] := Sum[k*z^k, {k, 1, n}]; 
Table[ComplexPlot3D[poly[z], {z, -1.5 - 1.5*I, 1.5 + 1.5*I}], {n, 1, 6}]

enter image description here

I would like to add a black vertical line passing through each root of the polynomials. You can kind of see where they are from the plots, but lines would be a helpful visualisation aid.

I can obtain the roots easily enough:

Table[{poly[z], Roots[poly[z] == 0, z]}, {n, 1, 6}]

But how do I convert the data provided by Roots into vertical lines? Ultimately, I want to be able to do this for polynomials of arbitrary degree, so a 'manual' solution isn't much help.

Thanks in advance, and stay safe.

$\endgroup$

1 Answer 1

4
$\begingroup$

First, let's modify your definition for poly[]:

poly[n_, z_] := Sum[k*z^k, {k, 1, n}]

In general, it's a good idea to make all parameters of an expression the arguments of the corresponding function.

With that,

Table[Show[ComplexPlot3D[poly[n, z], {z, -1.5 - 1.5 I, 1.5 + 1.5 I}], 
           Graphics3D[InfiniteLine[#, {0, 0, 1}] & /@ 
                      PadRight[ReIm[z /. NSolve[poly[n, z], z]], {Automatic, 3}]]],
      {n, 1, 6}]

complex plots of polynomials

$\endgroup$
3
  • $\begingroup$ Many thanks @J.M., this works. Just FYI, the reason I didn't include n as a variable is that this is a table of 6 different polynomials in z. The table uses n to tell poly the order of the polynomial in each case. But the line issue is sorted, thank you. $\endgroup$ Commented Dec 30, 2020 at 22:56
  • 1
    $\begingroup$ It's still not a good idea to have n be global. What if you had assigned n to e.g. 6.1 many inputs ago and then forgot? $\endgroup$ Commented Dec 31, 2020 at 0:17
  • 1
    $\begingroup$ Or to use the function inside a Manipulate you need explicit arguments, e.g., Manipulate[ Show[ ComplexPlot3D[poly[n, z], {z, -1.5 - 1.5 I, 1.5 + 1.5 I}, ClippingStyle -> None], Graphics3D[{Thick, InfiniteLine[#, {0, 0, 1}] & /@ PadRight[ReIm[z /. NSolve[poly[n, z], z]], {Automatic, 3}]}]], {{n, 3}, Range[6]}] $\endgroup$
    – Bob Hanlon
    Commented Dec 31, 2020 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.