I'm plotting something trivial; the solution to an underdamped harmonic oscilator: $$x(t) = A_{0} \cos(\omega t) e^{-t/\tau}$$ In MM speak I say: xOft[A0_, v_, T_, t_] = A0 Cos[2 Pi v t] Exp[-t/T]

Plotting with: Plot[xOft[1.4*10^-8, 29616123, 441, t],{t,0,1000}] produces, enter image description here

Can anyone explain why MM produces such a strange plot for such a simple function? In the example above I scaled the $y$-axis with $10^{8}$ to check if it was a scaling issue...seemingly not. I want to make sure that this model is stable in MM before I do other things to it.

So I'd like to check:

  • If this is just a plot issue, why and how can we get rid of it?
  • If it is a real representation of the function, why is MM producing this result?


  • $\begingroup$ Moiré-effect. Increase PlotPoints. $\endgroup$ Feb 10, 2019 at 20:44
  • 1
    $\begingroup$ And MaxRecursion option: MaxRecursion -> 12, PlotPoints -> 100 $\endgroup$
    – Bob Hanlon
    Feb 10, 2019 at 22:22
  • $\begingroup$ Thanks for both answers! If you have time could one of you add an answer with a short explanation so I can accept and assign credit? $\endgroup$
    – N.B.
    Feb 10, 2019 at 22:24
  • $\begingroup$ It is acceptable on this forum to answer your own questions. $\endgroup$
    – Bob Hanlon
    Feb 10, 2019 at 22:31

1 Answer 1

xOft[A0_, v_, T_, t_] = A0 Cos[2 Pi v t] Exp[-t/T];

The artifacts that you observed are due to the function being under-sampled in the Plot. You can increase the sampling by increasing the number of initial sampling points (PlotPoints) and increasing the maximum number of recursive subdivisions that can be used (MaxRecursions). These increases will naturally slow down the plotting.

Plot[xOft[1.4*10^-8, 29616123, 441, t], {t, 0, 1000}, 
  MaxRecursion -> 12, PlotPoints -> 100]

enter image description here

Or interactively,

 Plot[xOft[1.4*10^-8, 29616123, 441, t], {t, 0, 1000},
  MaxRecursion -> mr, PlotPoints -> pp],
 {{pp, 100, PlotPoints},
  {Automatic, 25, 50, 100, 150, 200, 500}},
 {{mr, 12, MaxRecursion},
  {Automatic, Range[5, 15]} // Flatten}]

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.