4
$\begingroup$

I'm trying to reprocedue this plot with Mathematica and got some problems.

enter image description here

x[t_] := 4 + 3 Cos[\[Pi] t] + 2 Cos[2 \[Pi] t] + Cos[3 \[Pi] t];
xa[t_] := 5 + 5 Cos[\[Pi] t]; Plot[{x[t], xa[t]}, {t, 0, 5}, 
 GridLines -> Automatic, AxesOrigin -> {0, 0},
 PlotStyle -> {Automatic, Directive[Dashed]}, Mesh -> {{0}}, 
 MeshFunctions -> {x[#] - xa[#] &}, 
 MeshStyle -> Directive[PointSize[0.03], Red]]

enter image description here

  1. Why isn't a point at {0, 10}?
  2. How would you add ticks 0, T, 2T, 3T, etc as in the image?

I believe that I can solve for the coordinate of points and add the ticks but I'm wondering if there is a simple way or that is the way to go?

$\endgroup$
2
  • $\begingroup$ What is of interest is that Mesh didn't find all the intersections. $\endgroup$
    – Syed
    May 21 at 4:38
  • 3
    $\begingroup$ @Syed Mesh only work for cross-sectional intersection, that is it must change its sign. $\endgroup$
    – cvgmt
    May 21 at 9:22

1 Answer 1

6
$\begingroup$

Use Solve or NSolve to find all the intersection points and use Epilog to add all the lines and points and ticks.

x[t_] = 4 + 3 Cos[π t] + 2 Cos[2 π t] + Cos[3 π t];
xa[t_] = 5 + 5 Cos[π t];
sol = DeleteDuplicates[Solve[{x[t] == xa[t], 0 <= t <= 5}, t]]
T = 2/3;
Plot[{x[t], xa[t]}, {t, 0, 5}, GridLines -> Automatic, 
 AxesOrigin -> {0, 0}, PlotStyle -> {Automatic, Directive[Dashed]}, 
 Ticks -> None, 
 Epilog -> {Table[
    Text[Style[ToString[i] <> "T", Bold], {i*T, 0}, {0, 2}], {i, 1, 
     7}], {Red, AbsolutePointSize[8], Point[{t, x[t]} /. sol]}, Green,
    Line[{{t, x[t]}, {t, 0}}] /. sol}, PlotRangePadding -> {.1, .8}]

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.