To identify all the intersection points between the two function graphsy=sinx
and y=2sin(3x-Pi/6)
within the domain 0<=x<=2Pi
, my method is to solve the equation Sin[x] == 2 Sin[3 x - \[Pi]/6]
for all roots in this domain, and then use the Table function to label all intersection points and their coordinate values on the graph.
This method is feasible, but are there any better methods? Code that is more concise and efficient?
My code is as follows:
expr = {Sin[x], 2 Sin[3 x - \[Pi]/6]}
intersectionConditions =
Solve[{Sin[x] == 2 Sin[3 x - \[Pi]/6], 0 <= x <= 2 \[Pi]}, x,
Reals] // FullSimplify
intersectionValues =
If[intersectionConditions != {},
Table[{x, Sin[x]} /. intersectionConditions[[i]] //
FullSimplify, {i, 1, Length[intersectionConditions]}],
"intersection Does Not Exist"];
If[intersectionConditions != {}, {Table[{x, Sin[x]} /.
intersectionConditions[[i]] // FullSimplify // N, {i, 1,
Length[intersectionConditions]}]}]
Plot[expr, {x, 0, 2 \[Pi]}, PlotRange -> {{0, 2.5 \[Pi]}, Automatic},
AxesOrigin -> {0, 0}, Axes -> True, ImageSize -> 600, Epilog -> {
If[intersectionConditions != {}, {PointSize[Medium], Red,
Point[intersectionValues], Style[FontSize -> Tiny],
Table[Text[intersectionValues[[p]] // N,
Offset[{-10, -18}, intersectionValues[[p]]]], {p, 1,
Length[intersectionValues], 1}]}]}]
The effect achieved is as follows: