2
$\begingroup$

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}]
$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – bbgodfrey
    May 4, 2015 at 4:22
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    May 4, 2015 at 10:30
  • $\begingroup$ 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}] $\endgroup$
    – LLlAMnYP
    May 4, 2015 at 11:40
  • $\begingroup$ @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. $\endgroup$
    – Trav
    May 4, 2015 at 19:02

1 Answer 1

1
$\begingroup$

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}] 
   ]]]
 ]

Dynamic levels

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

Lines

$\endgroup$
5
  • $\begingroup$ Thank you very much! That's exactly what I was looking for. $\endgroup$
    – Trav
    May 4, 2015 at 19:01
  • $\begingroup$ Question: Is it easy to modify this code in order to have the segments joining each point to {0,0} show in the picture ? $\endgroup$
    – Trav
    May 4, 2015 at 19:59
  • $\begingroup$ 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). $\endgroup$
    – LLlAMnYP
    May 4, 2015 at 20:35
  • $\begingroup$ Thanks. It seems that I'm not able to move the points in the picture anymore though. $\endgroup$
    – Trav
    May 4, 2015 at 21:17
  • $\begingroup$ Yeah, I've got a similar issue on v8. I'll look into it tomorrow. $\endgroup$
    – LLlAMnYP
    May 4, 2015 at 21:35

Your Answer

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

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