## Interactive level sets of polynomials

2

1

I'm new to Mathematica and I need some help with the following problem. I would like given some positive integer n, to have mathematica plot the level sets of a (say monic) polynomial of degree n, p(z), with roots z_j in the unit disk. The trick is that I want to be able to change the position of z_j in an interactive way (e.g dragging them around inside the unit disk or choose the roots in advance by clicking at some points in the plane and then have Mathematica read that input and draw the level set of the corresponding polynomial). For example, I've tried something like the following piece of code (for n=2) but it's not exactly what I need. Any help is appreciated. Thank you!

 Manipulate[
Show[ContourPlot[
Abs[(x + I*y - x1 - I*y1) (x + I*y - x2 - I*y2)] ==
Abs[(x1 + I*y1) (x2 + I*y2)], {x, -15, 15}, {y, -15, 15}]],
{{x1, {-5, 5}}, Locator}, {{y1, {-5, 5}}, Locator},
{{x2, {-5, 5}}, Locator}, {{y2, {-5, 5}}, Locator}]


Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise.

– bbgodfrey – 2015-05-04T04:22:15.063

What exactly do you need? It seems to work in the way you describe. Is the problem with the equation Abs[(x + I*y - x1 - I*y1) (x + I*y - x2 - I*y2)] == Abs[(x1 + I*y1) (x2 + I*y2)]? You could plot the real and imaginary parts, but I don't know if that would be what you want. – Michael E2 – 2015-05-04T10:30:53.637

For a start I can suggest this: Manipulate[Show[ContourPlot[Abs[(x + I*y - Complex @@ x1) (x + I*y - Complex @@ x2)] == Abs[(Complex @@ x1) (Complex @@ x2)], {x, -15, 15}, {y, -15, 15}]], {{x1, {-5, 5}}, Locator}, {{x2, {-5, 5}}, Locator}] – LLlAMnYP – 2015-05-04T11:40:14.457

@MichaelE2 My problem with my code was that I did not want to have to move the points by real and imaginary part separately but rather than complex numbers on the plane. – Trav – 2015-05-04T19:02:16.363

1

I hate fiddly held expressions! But I managed to get this Dynamic construct to work.

n = 4;
left[x_, y_, z__] := Abs@Product[x + I y - Complex @@ zz, {zz, {z}}]
right[z__] := Abs@Product[Complex @@ zz, {zz, {z}}]
DynamicModule[{z = RandomReal[{-5, 5}, {n, 2}]},
Dynamic[Show[
ContourPlot[
left[x, y, Sequence @@ z] == right[Sequence @@ z],
{x, -15, 15}, {y, -15, 15}, ImageSize -> Large],
Graphics[
Evaluate@Table[With[{i = i}, Locator[Dynamic[z[[i]]]]], {i, n}]
]]]
]


I'm not sure of the best way to limit the locators to within the unit circle... in fact I hardly understand my own code :-)

But at least you now have an easy way to set up an arbitrary number of poles.

Update

On Mathematica v8 dragging one locator drags them all together. Don't know why. The requested feature in the comments requires the following replacement: change the Graphics[...] to

Graphics[(Evaluate@
Table[With[{i = i}, Line[{{0, 0}, z[[i]]}]], {i, n}])~Join~
(Evaluate@
Table[With[{i = i}, Locator[Dynamic[z[[i]]]]], {i, n}])
]


Works as normal on my machine with M.v.10

Thank you very much! That's exactly what I was looking for. – Trav – 2015-05-04T19:01:14.150

Question: Is it easy to modify this code in order to have the segments joining each point to {0,0} show in the picture ? – Trav – 2015-05-04T19:59:23.260

Yes. Immediately after Graphics[ insert Line[{{0, 0}, #}] & /@ z, I can't do any rigorous testing right now, as it seems, my code doesn't work on Mathematica v8 (I wrote it using v10). – LLlAMnYP – 2015-05-04T20:35:31.973

Thanks. It seems that I'm not able to move the points in the picture anymore though. – Trav – 2015-05-04T21:17:32.717

Yeah, I've got a similar issue on v8. I'll look into it tomorrow. – LLlAMnYP – 2015-05-04T21:35:18.993