2
$\begingroup$

For example, when solving the equation $$\sin(13x)+\sin(9x)=\cos(2x)$$ (by hand) you get the solutions $$ x= \begin{cases} \pm\tfrac{\pi}{4}+\pi n,\\ \tfrac{\pi}{66}+\tfrac{2}{11}\pi n,\\ \tfrac{5\pi}{66}+\tfrac{2}{11}\pi n, \end{cases} \qquad n\in\mathbb{Z}. $$

I can make a graphic illustration of the solutions with the following (primitive) code;

Clear[x1, x2, x3, x4, n]
x1[n_] := \[Pi]/66 + 2/11 \[Pi] n
x2[n_] := 5 \[Pi]/66 + 2/11 \[Pi] n
x3[n_] := -\[Pi]/4 + \[Pi] n
x4[n_] := \[Pi]/4 + \[Pi] n
p1 = Table[{Cos[x1[n]], Sin[x1[n]]}, {n, 0, 10}];
p2 = Table[{Cos[x2[n]], Sin[x2[n]]}, {n, 0, 10}];
p3 = Table[{Cos[x3[n]], Sin[x3[n]]}, {n, 0, 1}];
p4 = Table[{Cos[x4[n]], Sin[x4[n]]}, {n, 0, 1}];
Graphics[{Circle[{0, 0}, 1], Point[p1], Point[p2], Point[p3], Point[p4]}]

but is there a smarter/more efficient way to make the plot (and perhaps with a little more ‘fancy’ output)? TIA.

$\endgroup$
7
$\begingroup$
Clear["Global`*"]

eqn = Sin[13 x] + Sin[9 x] == Cos[2 x];

FunctionPeriod[#, x] & /@ (List @@ eqn)

(* {2 π, π} *)

x /. (sol = SortBy[Solve[{eqn, 0 <= x <= 2 Pi}, x] // FullSimplify, N])

(* {π/66, (5 π)/66, (13 π)/66, π/4, (17 π)/66, (
 25 π)/66, (29 π)/66, (37 π)/66, (41 π)/66, (49 π)/66, (
 3 π)/4, (53 π)/66, (61 π)/66, (65 π)/66, (73 π)/66, (
 7 π)/6, (5 π)/4, (85 π)/66, (89 π)/66, (97 π)/66, (
 101 π)/66, (109 π)/66, (113 π)/66, (7 π)/4, (11 π)/6, (
 125 π)/66} *)

Much faster:

x /. (sol2 = 
   NSolve[{eqn, 0 <= x <= 2 Pi}, x] /.
    r_Real :> Pi*RootApproximant[r/Pi])

(* {π/66, (5 π)/66, (13 π)/66, π/4, (17 π)/66, (
 25 π)/66, (29 π)/66, (37 π)/66, (41 π)/66, (49 π)/66, (
 3 π)/4, (53 π)/66, (61 π)/66, (65 π)/66, (73 π)/66, (
 7 π)/6, (5 π)/4, (85 π)/66, (89 π)/66, (97 π)/66, (
 101 π)/66, (109 π)/66, (113 π)/66, (7 π)/4, (11 π)/6, (
 125 π)/66} *)

% === %%

(* True *)

Plotting,

ParametricPlot[{Cos[x], Sin[x]}, {x, 0, 2 Pi},
 PlotStyle -> LightGray,
 Epilog -> {Red, AbsolutePointSize[4],
   Tooltip[Point[{Cos[x], Sin[x]}], x] /. sol}]

enter image description here

Plot[Evaluate[List @@ eqn], {x, 0, 2 Pi},
 Epilog -> {Red, AbsolutePointSize[4],
   Tooltip[Point[{x, Cos[2 x]}], {x, Cos[2 x]}] /. sol},
 PlotLegends -> "Expressions"]

enter image description here

Plot[Evaluate[Subtract @@ eqn], {x, 0, 2 Pi},
 Epilog -> {Red, AbsolutePointSize[4],
   Tooltip[Point[{x, 0}], x] /. sol},
 PlotLabel -> Style[Subtract @@ eqn, 14, Black]]

enter image description here

$\endgroup$
6
$\begingroup$

Perhaps this?:

SolveValues[Sin[13 x] + Sin[9 x] == Cos[2 x], x] /. C[1] -> 0 // 
  Exp[I #] & // ComplexListPlot
$\endgroup$
6
  • $\begingroup$ Very nice! Can I add the unit circle too? I tried a Circle command but it did not work as expected. $\endgroup$
    – mf67
    Nov 29 '21 at 1:42
  • 1
    $\begingroup$ @mf67 Show[<plot>, Graphics[{Circle[]}]] is one way. Also ComplexListPlot[SolveValues[...] /. C[1] -> 0 // Exp[I #] &, Prolog -> {Circle[]}] $\endgroup$
    – Michael E2
    Nov 29 '21 at 1:43
  • $\begingroup$ @mf67 ListPolarPlot[ [email protected][Sin[13 x] + Sin[9 x] == Cos[2 x], x] /. C[1] -> 0 // PadRight[#, {Automatic, 2}, 1] &, Prolog -> {Circle[]}] is another way. $\endgroup$
    – Michael E2
    Nov 29 '21 at 1:46
  • $\begingroup$ Michael E2, OK! I thought Circle[{0,0},1] would work, but it didn't. It seems the argument should be empty. (I don't understand why though.) $\endgroup$
    – mf67
    Nov 29 '21 at 1:47
  • $\begingroup$ @mf67 Circle[{0, 0}, 1] works, too, in both my example codes. It must be how you added it to the code. $\endgroup$
    – Michael E2
    Nov 29 '21 at 1:50
5
$\begingroup$

Edit

ParametricPlot[{Cos[x], Sin[x]}, {x, 0, 2 π}, Mesh -> {{0}}, 
 MeshFunctions -> {Sin[13 #3] + Sin[9 #3] - Cos[2 #3] &}, 
 MeshStyle -> {PointSize[Medium], Red}]

enter image description here

Original

sol = NSolve[Sin[13 x] + Sin[9 x] == Cos[2 x] && 0 <= x <= 2 π, x,
   Reals]
Graphics[{Circle[], {PointSize[Medium], Red, 
   Point[AngleVector /@ (x /. sol)]}}]

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.