3
$\begingroup$

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:

square wave

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:

numeric integral of square wave

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:

symbolic integral of square wave

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]] 
$\endgroup$
3
  • 2
    $\begingroup$ 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... $\endgroup$ – Henrik Schumacher Apr 2 '18 at 13:47
  • 1
    $\begingroup$ Have you seen this? $\endgroup$ – J. M.'s torpor Apr 2 '18 at 14:18
  • $\begingroup$ No I had not seen that question. $\endgroup$ – Mats Granvik Apr 2 '18 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.