Question:Why does my Fourier series summation have so many terms ?

Question:Why does my Fourier series summation have so many terms ?

Maple

I am trying to learn Maple and Fourier transform by calculating the coefficients and the resuting summation as follows:

```restart;

assume(n>0);

assume(N>0);

target_f := x -> piecewise(-Pi < x and x < 0, 0, 0 < x and x < Pi, x, Pi < x and x < 2*Pi, 0, 2*Pi < x and x < 3*Pi, x - 2*Pi)

a0 := simplify(int(target_f(x), x = -Pi .. Pi)/(2*Pi))

a_n := int(target_f(x)*cos(n . x), x = -Pi .. Pi)/Pi

b_n := int((target_f(x)) . (sin(n*x)), x = -Pi .. Pi)/Pi

fourier_f := N -> a0 + sum(a_n*cos(n*x) + b_n*sin(n . x), n = 1 .. N)```

I am making fourier_f as a function of N becasue I want to see the effect of increasing partial sums. The resulting output of the summation "fourier_f" has a lot of terms. The output looks like this:

```               /        /  N
|        |-----
|        | \
1         1    |   2    |  )   /
- Pi + ------- |4 N  Pi | /    |-
4            2 |        |----- |
4 Pi N  \        \n = 1 \

\
|
|
sin(n x) (cos(n Pi) n Pi - sin(n Pi))\|   /   2
-------------------------------------|| + \I N  Pi LerchPhi(
2                   ||
n  Pi                //

2
-exp(-I x), 1, N) - 2 N  LerchPhi(-exp(-I x), 2, N) - I N Pi

\
+ 2/ exp(I N (Pi - x))

- I N Pi (LerchPhi(-exp(I x), 1, N) N - 1) exp(I N (-Pi + x))

2
- I N  Pi LerchPhi(-exp(-I x), 1, N) exp(-I N (Pi + x))

/   2
+ I Pi N exp(-I N (Pi + x)) + \I N  Pi LerchPhi(-exp(I x), 1, N

2                                       \
) - 2 N  LerchPhi(-exp(I x), 2, N) - I N Pi + 2/ exp(I N (Pi

2
+ x)) + 2 exp(-I x N) N  LerchPhi(exp(-I x), 2, N)

2
+ 2 exp(I x N) N  LerchPhi(exp(I x), 2, N)

2                            2
- 2 N  polylog(2, exp(-I x)) - 2 N  polylog(2, exp(I x))

2                             2
+ 2 N  polylog(2, -exp(-I x)) + 2 N  polylog(2, -exp(I x))

\
|
|
|
- 2 exp(-I x N) - 2 exp(I x N)|
|
/
```

The target function is not that complicated. I am using the target function shown in this YouTube video: https://www.youtube.com/watch?v=praNtRezlkw&list=PLPBSZvbAshbxULtiBcygm1qh7BtsDv3DW&index=12

It gave me similar output when the target function was x2.  I am not sure what's going on because for a simple square wave, I was able to make this work correctly.

I am deliberately not using existing packages because I want to learn Maple syntax.

Can someone please tell me what's my mistake ?

﻿