I am trying to plot a sum of multiple HeavisidePi functions. A typical example would be something like this:

Plot[HeavisidePi[1/10 (-595 + x)] + HeavisidePi[1/10 (-535 + x)] +

HeavisidePi[1/10 (-425 + x)] + HeavisidePi[1/10 (-365 + x)], {x,

300, 800}, Exclusions -> None]

In this interval in the code above, I can see all four of them. However, if I were to back out to an interval of {100,800}, for instance, only two of them show up for me (the one at 595 and 425). Any idea why this would be the case?

Any help would be greatly appreciated.

=================

=================

2 Answers

2

=================

There is another way to control the sample points which is effective in this case, where you know in advance where the interesting things happen. PlotPoints takes an optional second argument, which is a list of extra points to be added to the other sample points.

Since in this case we know where the function is nonzero, we can add a point from each region thus: PlotPoints -> {Automatic, {365, 425, 535, 595}}. In this way we can avoid adding unneeded sample points.

Plot[HeavisidePi[1/10 (-595 + x)] + HeavisidePi[1/10 (-535 + x)] +

HeavisidePi[1/10 (-425 + x)] + HeavisidePi[1/10 (-365 + x)],

{x, 100, 800}, Exclusions -> None,

PlotPoints -> {Automatic, {365, 425, 535, 595}}]

Interesting. This doesn’t seem to be documented. Where did you learn about this?

– Sjoerd C. de Vries

May 8 ’13 at 13:56

@SjoerdC.deVries I’m afraid I don’t recall precisely – I think a friend, who has worked with some of the developers at WRI. It’s the subject in this question.

– Michael E2

May 8 ’13 at 14:31

Thanks for the link. Hadn’t seen that one before.

– Sjoerd C. de Vries

May 8 ’13 at 15:06

This is an issue of sampling. You need to increase the number of initial sampling divisions (using the PlotPoints option) or Mathematica will not “explore” the area further as it appears to be uniformly zero.

Plot[HeavisidePi[1/10 (-595 + x)] + HeavisidePi[1/10 (-535 + x)] +

HeavisidePi[1/10 (-425 + x)] + HeavisidePi[1/10 (-365 + x)], {x, 100, 800},

Exclusions -> None, PlotPoints -> 250]

See the excellent StackOverflow posts linked in this answer: Problem with ParametricPlot

These will explain the sampling that Plot uses and some options to tune it.