# Is Mathematica doing this integral of a wave form approximation correctly?

I am trying to integrate a square wave approximation I found in this answer by ybeltukov.

Nothing wrong with the answer but when I try to integrate it I run into trouble.

I modified the code from the answer and first wrote this:

Clear[squareWave, integratedSquareWave, x, coefficient, delta];
coefficient = 10000;
delta = 1000;
squareWave[x_] = 2 ArcTan[Sin[2 \[Pi] x]*coefficient]/\[Pi];
ListLinePlot[Table[squareWave[x], {x, 0, 2, 1/delta}],
DataRange -> {0, 2}, PlotStyle -> Thickness[0.01]]


This gives the nice plot:

as I wanted.

Then I do the numeric integral of the square wave above with this code:

ListLinePlot[
Accumulate[Table[squareWave[x], {x, 0, 2, 1/delta}]]/delta,
DataRange -> {0, 2}, PlotStyle -> Thickness[0.01]]


which gives the school example plot:

So far so good. But now I try to plot the symbolic integral of the square wave:

integratedSquareWave[x_] =
Integrate[2 ArcTan[Sin[2 \[Pi] x]*coefficient]/\[Pi], x];
ListLinePlot[Table[Re[integratedSquareWave[x]], {x, 0, 2, 1/delta}],
DataRange -> {0, 2}, PlotStyle -> Thickness[0.01]]


and then I get this:

Question:

Is this symbolic integral correct? The numeric integral looks so different from the symbolic integral.

The symbolic integral which correctness I am asking about can be found with this command:

Clear[x];
coefficient = 10000;
Integrate[2 ArcTan[Sin[2 \[Pi] x]*coefficient]/\[Pi], x]


Also I had to take the real part Re of the symbolic integral in order to be able to plot it.

All three plots in one block of code:

Clear[squareWave, integratedSquareWave, x, coefficient, delta];
coefficient = 10000;
delta = 1000;
squareWave[x_] = 2 ArcTan[Sin[2 \[Pi] x]*coefficient]/\[Pi];
ListLinePlot[Table[squareWave[x], {x, 0, 2, 1/delta}],
DataRange -> {0, 2}, PlotStyle -> Thickness[0.01]]
ListLinePlot[
Accumulate[Table[squareWave[x], {x, 0, 2, 1/delta}]]/delta,
DataRange -> {0, 2}, PlotStyle -> Thickness[0.01]]
integratedSquareWave[x_] =
Integrate[2 ArcTan[Sin[2 \[Pi] x]*10000]/\[Pi], x];
ListLinePlot[Table[Re[integratedSquareWave[x]], {x, 0, 2, 1/delta}],
DataRange -> {0, 2}, PlotStyle -> Thickness[0.01]]

• The symbolic integral is not entirely correct, but it would be correct if the discontinuities at integers and integer multiples of $\pi/4$ would be removed. Apparently, Integrate has problems determining the correct braches of some inverse trigonometric functions... Apr 2 '18 at 13:47
• Have you seen this? Apr 2 '18 at 14:18
• No I had not seen that question. Apr 2 '18 at 15:02