Take the 2-minute tour ×

First let me post the question that I am doing:

enter image description here

You see for wave equation y2, there is a ± sign. I know how to do + or - at one time. Of course, I can use copy, paste and do each case separately; yet, I don't think that would be smart. I am wondering is there a way to include the both Animation in two graphs? (Simple and efficient code)

The way I approach this problem is that first I define A1 as a constant, whose value is 1. Then I can vary the ratio of A2 versus A1. I would like apply Animate to variable A2 and δk, because in the problem we are asked to Animate different amplitude ratio and phase difference.

Here is my code for the + case:


k2 = k1 + δk;

y1[x_, t_] = A1 Sin[k1 (x - v t)];
y2[x_, t_, A2_, δk_] = A2 Sin[k2 (x + v t)];

yr[x_, t_, A2_, δk_] = y1[x, t] + y2[x, t, A2, δk];

k1 = 2 π;
A1 = 1;
v = 1;

xmax = 10;
tmax = 30;
range = {{0, xmax}, {-4, 9}};

pix1[t_] := Plot[y1[x, t] + 4, {x, 0, xmax}, PlotStyle -> Red]

pix2[t_, A2_, δk_] := Plot[y2[x, t, A2, δk] + 4, {x, 0, xmax}, PlotStyle -> Blue]

pixr[t_, A2_, δk_] := Plot[yr[x, t, A2, δk], {x, 0, xmax}, PlotStyle ->Black]

plot[t_, A2_, δk_] := 
  Show[{pix1[t], pix2[t, A2, δk], pixr[t, A2,δk]}, PlotRange -> range, AxesLabel -> {x, y}]

Animate[plot[t, A2, δk], {t, 0, tmax}, {A2, 1, 4, 1}, {δk, π/8, π, π/8}]
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Try this:

y2[x_, t_, A2_, δk_] = A2 Sin[k2 (x + # v t)] & /@ {1, -1};
share|improve this answer
Do you guys know how to change \[Theta] into math symbol when I ask questions on this website. I copy and paste my code from the MMA notebook, and those symbols just not change into the math form. –  Lawerance Jun 4 '14 at 2:16
Press Esc and then type th and then Press Esc again. you can use Mathematica Palettes (in the main toolbar) to type all symbols you want –  Algohi Jun 4 '14 at 2:23
I know that. What I mean is that the math symbols in my notebook do not automatically change into math symbols when I copy, paste them to the website from the notebook. –  Lawerance Jun 4 '14 at 2:32
@Lawerance Copy-paste as usual and then use this plugin –  The Toad Jun 4 '14 at 3:43
@Lawerance and Algohi, you don't need Map since the constituent functions are Listable; you need merely: A2 Sin[k2 (x + {1, -1} v t)] or even A2 Sin[k2 (x + {v, -v} t)] -- Mathematica will take care of the rest. –  Mr.Wizard Jun 4 '14 at 7:49

Your Answer


