16

I have plotted the overlapping area of the UnitBox and the triangle function as:

Plot[Evaluate[
  Integrate[
       Piecewise[{{1, -0.5 <= x < 0.5}, {0, Not[-0.5 <= x < 0.5]}}] 
       Piecewise[{{x + 1 - a, -1 + a <= x <= 0 + a}, {-x + 1 + a, 0 + a <= x <= 1 + a}}],
   {x, -Infinity, +Infinity}]], 
{a, -2, 2}, PlotRange -> All]

However, the result has gaps as you can see in the plot:

enter image description here

Why is this happening if the function is continuous?

Thanks for your time.

whuber
  • 20,544
  • 2
  • 59
  • 111

1 Answers1

14

Plot[] is excluding the discontinuities in the second derivative:

f[x_, a_] := Integrate[
                Piecewise[{{1, -0.5 <= x < 0.5}, {0, Not[-0.5 <= x < 0.5]}}] 
                Piecewise[{{x + 1 - a, -1 + a <= x <= 0 + a}, {-x + 1 + a, 0 + a <= x <= 1 + a}}],
             {x, -Infinity, +Infinity}]

Plot[Evaluate[D[f[x, a], a]], {a, -2, 2}]

Mathematica graphics

As @b,gatessucks mentioned in a comment, using Exclusions->None solves the issue:

Plot[Evaluate[f[x, a]], {a, -2, 2}, PlotRange -> All, Exclusions -> None]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453