I am running the following code in Mathematica:

k = 40;
n = 6;
Plot[Sin[1/2*k*n (1 - Cos[θ])]^2/Sin[1/2*k*(1 - Cos[θ])]^2,
     {θ, -4 π, 4 π}, PlotRange -> Full]

The output is as follows:

enter image description here

The feature of the above plot in which the peaks decrease in height and then increase in height in cycles was somewhat unexpected. Interestingly though, upon plotting the function on just the range 0 to pi, I get this result:

enter image description here

The only thing that changed was the domain of the plot, but now all the peaks are of the same height, which is what I expected. The parameters can be changed to reduce or exaggerate the effect (larger k exaggerates the effect, for instance).

Why does this occur? Why would the plot change in such a systematically erroneous way just by zooming out by a factor < 10? This seems puzzling and concerning to me.


closed as off-topic by Bob Hanlon, march, m_goldberg, Henrik Schumacher, bbgodfrey Dec 24 '18 at 3:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, march, m_goldberg, Henrik Schumacher, bbgodfrey
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Increase your PlotPoints to something like PlotPoints -> 200. $\endgroup$ – march Dec 19 '18 at 19:13
  • 1
    $\begingroup$ Or use MaxRecursion -> 10 $\endgroup$ – Bob Hanlon Dec 19 '18 at 19:13
  • $\begingroup$ Both of these suggestions do address the problem - thanks! (Although PlotPoints -> 200 still leaves the effect noticeable; 400 will do it.) I am still wondering though why plotting less points results in the periodic 'wells' of peaks as shown above. It really looks like a feature of the function being plotted as opposed to some numerical shortcoming. $\endgroup$ – Grayscale Dec 19 '18 at 20:42
  • $\begingroup$ Mathematica is only a program with limited knowledge. The Plot command has deliberately limited the knowledge of the function and effort it uses to get that knowledge. If you need better plots you need to explicitly use options to get it to use more effort. For example, if the Plot command only uses two function evalutions, then the resulting plot will not be close to the function unless it was linear. Your particular functions requires a lot of effort to plot faithfully. $\endgroup$ – Somos Dec 20 '18 at 19:58

Browse other questions tagged or ask your own question.