Message Boards Message Boards

1
|
6689 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

[?] Put 2 different plots inside a manipulation?

Posted 7 years ago

I would like to have a notebook with 2 different kinds of plots inside a manipulation, in which the control for the manipulation uses locators linked to one of the plots. A simple example of something close to what I desire that will work is shown in the code below, but only one of the plots is inside the manipulate. The example plots a pair of sinusoids where the amplitudes and phases are controlled with the mouse by moving a variable around the complex plane.

Dynamic[Plot[{Sqrt[w[[1, 1]]^2 + w[[1, 2]]^2] Sin[
     2 \[Pi] t + ArcTan[w[[1, 2]]/w[[1, 1]]]], 
   Sqrt[w[[2, 1]]^2 + w[[2, 2]]^2] Sin[
     2 \[Pi] t + ArcTan[w[[2, 2]]/w[[2, 1]]]]}, {t, 0, 1}, 
  PlotRange -> {{0, 1}, {-3, 3}}]]

Manipulate[w = p; 
 ListPlot[p, 
  PlotRange -> {{-2, 2}, {-2, 2}}], {{p, {{-1, -1}, {1, 1}}}, 
  Locator}]

But what I would really prefer is to do the same calculations with something like the following, which does not work. Is there anything similar to this second approach that does work?

Manipulate[w = p; 
 GraphicsRow[{Plot[{Sqrt[w[[1, 1]]^2 + w[[1, 2]]^2] Sin[
       2 \[Pi] t + ArcTan[w[[1, 2]]/w[[1, 1]]]], 
     Sqrt[w[[2, 1]]^2 + w[[2, 2]]^2] Sin[
       2 \[Pi] t + ArcTan[w[[2, 2]]/w[[2, 1]]]]}, {t, 0, 1}, 
    PlotRange -> {{0, 1}, {-3, 3}}], 
   ListPlot[p, 
    PlotRange -> {{-2, 2}, {-2, 2}}]}], {{p, {{-1, -1}, {1, 1}}}, 
  Locator}]
POSTED BY: Mike Luntz
3 Replies

I made my share of mistakes with my first attempt. This may be more like what you want, with two distinct controls and correct syntax for ArcTan:

Manipulate[
 Row[{Plot[{Norm[p] Sin[2 \[Pi] t + ArcTan @@ p], 
     Norm[q] Sin[2 \[Pi] t + ArcTan @@ q]}, {t, 0, 1}, 
    PlotRange -> {{0, 1}, {-3, 3}}, PlotStyle -> {Red, Blue}, 
    ImageSize -> Medium],
   Spacer[20], 
   Graphics[{Locator[Dynamic@p, Background -> Red], 
     Locator[Dynamic@q, Background -> Blue]}, PlotRange -> 2, 
    Frame -> True]}],
 {{p, {1, 1}}, {-2, -2}, {2, 2}, ControlType -> None},
 {{q, -{1, 1}}, {-2, -2}, {2, 2}, ControlType -> None}]
POSTED BY: Gianluca Gorni
Posted 7 years ago

Gianluca,

Thanks for the suggestion. That has given me some things to think about. I guess I don't really understand your solution so maybe you can explain it some. When I ran your suggestion I only ended up with a single control, but in spite of that the single slider seemed to control both sinusoids in some unexplained way. I expected to have a pair of controls, each controlling its own sinusoid. Just to let you know, this is just a simplifying example for my real problem. What I am really trying to do is to manually move around pole/zero pairs of an all-pass filter to see their effect on compensating group delay of another filter. There will likely be several pole/zero pairs needed to compensate the filter, thus multiple controls required.

BTW, thanks for cleaning up my original code. I was so focused on the problem of controls that I wasn't even thinking about the example function I wanted to plot.

Mike

POSTED BY: Mike Luntz

For this particular example a 2D slider works quite well:

Manipulate[
 Plot[{Norm[p] Sin[2 \[Pi] t + ArcTan[p]], 
   Norm[p] Sin[2 \[Pi] t + ArcTan[p]]}, {t, 0, 1}, 
  PlotRange -> {{0, 1}, {-3, 3}}],
 {{p, {0, 0}}, {-2, -2}, {2, 2}}]

A variation:

Manipulate[
 Row[{Plot[{Norm[p] Sin[2 \[Pi] t + ArcTan[p]], 
     Norm[p] Sin[2 \[Pi] t + ArcTan[p]]}, {t, 0, 1}, 
    PlotRange -> {{0, 1}, {-3, 3}}],
   Graphics[Locator[Dynamic@p], PlotRange -> 2, Frame -> True]}],
 {{p, {0, 0}}, {-2, -2}, {2, 2}, ControlType -> None}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract