   ### 5.23.1  Fourier coefficients : fourier_an and fourier_bn or fourier_cn

Let f be a T-periodic continuous functions on ℝ except maybe at a finite number of points. One can prove that if f is continuous at x, then;

f(x)=
 a0 2
+
 +∞ ∑ n=1
an cos(
 2π nx T
)+bn sin(
 2π nx T
=
 +∞ ∑ n=−∞
cn e
 2iπ nx T

where the coefficients an, bn, nN, (or cn, nZ) are the Fourier coefficients of f. The commandsfourier_an and fourier_bn or fourier_cn compute these coefficients.

#### fourier_an

fourier_an takes four or five arguments : an expression expr depending on a variable, the name of this variable (for example x), the period T, an integer n and a real a (by default a=0).
fourier_an(expr,x,T,n,a) returns the Fourier coefficient an of a function f of variable x defined on [a,a+T) by f(x)=expr and such that f is periodic of period T:

an=
 2 T
 a+T a
f(x)cos(
 2π nx T
)dx

To simplify the computations, one should input assume(n,integer) before calling fourier_an to specify that n is an integer.
Example Let the function f, of period T=2, defined on [−1,1) by f(x)=x2.
Input, to have the coefficient a0 :

fourier_an(x`^`2,x,2,0,-1)

Output :

1/3

Input, to have the coefficient an (n≠ 0) :

assume(n,integer);fourier_an(x`^`2,x,2,n,-1)

Output :

4*(-1)`^`n/(pi`^`2*n`^`2)

#### fourier_bn

fourier_bn takes four or five arguments : an expression expr depending on a variable, the name of this variable (for example x), the period T, an integer n and a real a (by default a=0).
fourier_bn(expr,x,T,n,a) returns the Fourier coefficient bn of a function f of variable x defined on [a,a+T) by f(x)=expr and periodic of period T:

bn=
 2 T
 a+T a
f(x)sin(
 2π nx T
)dx

To simplify the computations, one should input assume(n,integer) before calling fourier_bn to specify that n is an integer.
Examples

• Let the function f, of period T=2, defined on [−1,1) by f(x)=x2.
Input, to have the coefficient bn (n≠ 0) :
assume(n,integer);fourier_bn(x`^`2,x,2,n,-1)
Output :
0
• Let the function f, of period T=2, defined on [−1,1) by f(x)=x3.
Input, to have the coefficient b1 :
fourier_bn(x`^`3,x,2,1,-1)
Output :
(2*pi`^`2-12)/pi`^`3

#### fourier_cn

fourier_cn takes four or five arguments : an expression expr depending of a variable, the name of this variable (for example x), the period T, an integer n and a real a (by default a=0).
fourier_cn(expr,x,T,n,a) returns the Fourier coefficient cn of a functionf of variable x defined on [a,a+T) by f(x)=expr and periodic of period T:

cn=
 1 T
 a+T a
f(x)e
 −2iπ nx T

dx

To simplify the computations, one should input assume(n,integer) before calling fourier_cn to specify that n is an integer.
Examples

• Find the Fourier coefficients cn of the periodic function f of period 2 and defined on [−1,1) by f(x)=x2.
Input, to have c0 :
fourier_cn(x`^`2,x,2,0,-1)
Output:
1/3
Input, to have cn :
assume(n,integer)
fourier_cn(x`^`2,x,2,n,-1)
Output:
2*(-1)`^`n/(pi`^`2*n`^`2)
• Find the Fourier coefficients cn of the periodic function f, of period 2, and defined on [0,2) by f(x)=x2.
Input, to have c0 :
fourier_cn(x`^`2,x,2,0)
Output:
4/3
Input, to have cn :
assume(n,integer)
fourier_cn(x`^`2,x,2,n)
Output:
((2*i)*pi*n+2)/(pi`^`2*n`^`2)
• Find the Fourier coefficients cn of the periodic function f of period 2π and defined on [0,2π) by f(x)=x2.
Input :
assume(n,integer)
fourier_cn(x`^`2,x,2*pi,n)
Output :
((2*i)*pi*n+2)/n`^`2
If you don’t specify assume(n,integer), the output will not be simplified :
((2*i)*pi`^`2*n`^`2*exp((-i)*n*2*pi)+2*pi*n*exp((-i)*n*2*pi)+
(-i)*exp((-i)*n*2*pi)+i)/(pi*n`^`3)
You might simplify this expression by replacing exp((-i)*n*2*pi) by 1, input :
subst(ans(),exp((-i)*n*2*pi)=1)
Output :
((2*i)*pi`^`2*n`^`2+2*pi*n+-i+i)/pi/n`^`3
This expression is then simplified with normal, the final output is :
((2*i)*pi*n+2)/n`^`2
Hence for n ≠ 0, cn=2inπ+2/n2. As shown in this example, it is better to input assume(n,integer) before calling fourier_cn.
We must also compute cn for n=0, input :
fourier_cn(x`^`2,x,2*pi,0)
Output :
4*pi`^`2/3
Hence for n= 0, c0=4π2/3.

Remarks :

• Input purge(n) to remove the hypothesis done on n.
• Input about(n) or assume(n), to know the hypothesis done on the variable n.   