# Handling ± in a set of equations

First let me post the question that I am doing:

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:

Remove["Global*"]

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

-

y2[x_, t_, A2_, δk_] = A2 Sin[k2 (x + # v t)] & /@ {1, -1};

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
@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