1
$\begingroup$

How do I draw the dashed lines that that forms the envelope of my plotted function?

enter image description here

My code:

ω1 = 1;
k1 = 8;
ω0 = 1;
k0 = 7;
f1[x_, t_] := Cos[ω1*t - k1*x]
f0[x_, t_] := Cos[ω0*t - k0*x]
f[x_, t_] := f1[x, t] + f0[x, t]

Plot[f[x, 2], {x, 0, 15}]

enter image description here

$\endgroup$
  • $\begingroup$ You are looking for the envelope of your function. In addition to the exact method showcased below, which is based on extracting an analytical form of the envelope, interpolation-based methods have also been proposed. See e.g. (Andrew Moylan's)[mathematica.stackexchange.com/a/27854/27951] and others. $\endgroup$ – MarcoB Apr 27 '18 at 17:15
3
$\begingroup$

Your function f[x,2] is a cosine function modulated by another one:

TrigFactor[f1[x, 2] + f0[x, 2]];

$$2\cos\left(2 - \frac{15x}{2}\right)\cos\left(\frac{x}{2}\right)$$

By using plot it is easy your request:

Plot[{2 Cos[2 - (15 x)/2] Cos[x/2], 2 Cos[x/2], -2 Cos[x/2]}, {x, 0, 15},
PlotStyle -> {Black, {Black, Dashed}, {Black, Dashed}}]

enter image description here

Or:

Plot[{2 Cos[2 - (15 x)/2] Cos[x/2], 2 Cos[x/2], -2 Cos[x/2]}, {x, 0, 15},
Frame -> {{True, False}, {True, False}}, Axes -> False, 
PlotStyle -> {Black, {Black, Dashed}, {Black, Dashed}}, AspectRatio -> 1/4, 
ImageSize -> 500]

enter image description here

$\endgroup$

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