6
$\begingroup$

I need to combine two plots on the same graph to highlight the intersection of the two while being able to manipulate various parameters that are common to both functions. I need to have the slider simultaneously change the parameters for each function and continue to plot on the same graph. Here's my code:

Manipulate[
 right = Plot[Cos[2*Pi*b*n/\[Lambda]], {n, 0, 2}], {{a, 25, 
   "x-separation"}, 20, 30}, {{b, 25, "z-separation"}, 20, 
  30}, {{r, 1, "Rod Radius"}, .1, 
  10}, {{\[Lambda], 100, "Wavelength"}, 50, 200}]

Manipulate[
 left = Plot[
   Cos[2*Pi*
      b/\[Lambda]] + (\[Lambda]*Sin[2*Pi*b/\[Lambda]])/(2 a*
       Log[a/(2*Pi*r)]), {n, 0, 2}], {{a, 25, "x-separation"}, 20, 
  30}, {{b, 25, "z-separation"}, 20, 30}, {{r, 1, "Rod Radius"}, .1, 
  10}, {{\[Lambda], 100, "Wavelength"}, 50, 200}]

Show[right, left] // Dynamic

Any help is much appreciated!

$\endgroup$

2 Answers 2

8
$\begingroup$
Manipulate[
 Plot[{Cos[2*Pi*b/λ] + (λ*Sin[2*Pi*b/λ])/(2 a*Log[a/(2*Pi*r)]), 
       Cos[2*Pi*b*n/λ]}, {n, 0, 2}], 
{{a, 25, "x-separation"}, 20, 30}, {{b, 25, "z-separation"}, 20, 30}, 
{{r, 1, "Rod Radius"}, .1, 10}, {{λ, 100, "Wavelength"}, 50, 200}]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thanks for your help! I wasn't thinking to put the two functions inside Plot but this works much more efficiently than the other routes I've tried. $\endgroup$
    – FreqShow
    Dec 9, 2013 at 5:51
  • $\begingroup$ Thank you -- this is really helpful! I was trying to combine Manipulate with the Show commands and it simply wasn't working. This is very effective. $\endgroup$
    – G. Khanna
    Apr 13 at 16:33
0
$\begingroup$

Here is another simpler example that can compare how amplitude, frequency, and phase shift can impact the shape of a Sine function.

Manipulate[
Plot[{Sin[x], a Sin[k x + phi]}, {x, 0, 2 Pi}],
{k, .1, 4},{a, 1, 2}, {phi, 0, 2 Pi}
 ]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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