May 20, 2010

P[1,x_] = 1/(Sqrt[2Pi])

Do[ P[2k,x_] = (1/Sqrt[Pi])Cos[k*x], {k,1,25}]

Do[ P[2k+1,x_] =(1/Sqrt[Pi])Sin[k*x],{k,1,25}]

Table[{k,P[k,x]},{k,1,51}]

Date[]

Table[ Integrate[ P[m,x]*P[n,x],{x,0,2Pi}],{m,1,25},{n,1,25}]  // TableForm

Date[]

The coefficients  (Subscript[a, k]) and (Subscript[b, k]) of the Fourier series expansion 
                   ((Subscript[a, 0])/2)+(∑_(k=1)^∞)( (Subscript[a, k])cos(k x) + (Subscript[b, k])sin(k x) )
for a function  f(x) defined on 0 ⩽ x ⩽ 2π    (with f(2π) = f(0) ) 
are given by 

             (Subscript[a, k])= (1/π)(∫_0^(2π))f(x)cos(k x)dx,     for  k ⩾ 0,
and 
             (Subscript[b, k])= (1/π)(∫_0^(2π))f(x)sin(k x)dx,     for  k ⩾ 1.

In terms of delayed evaluation for a function f(x) specified later, we introduce

a[k_] := (1/Pi)Integrate[f[x]*Cos[k*x], {x,0,2Pi}]

b[k_] := (1/Pi)Integrate[f[x]*Sin[k*x], {x,0,2Pi}]

S[n_,x_] := a[0]/2 + Sum[ (a[k]*Cos[k*x]+ b[k]*Sin[k*x]), {k,1,n} ]

?Mod

F[x_] := f[ Mod[ x,2Pi] ]

f[x_] := (x-Pi)^2 /; 0 ≤ x ≤ 2Pi

Plot[F[x],{x,-4Pi,4Pi}]

f[x_] := x(2Pi-x)  /; 0 ≤ x ≤ 2Pi

Plot[F[x],{x,-6Pi,6Pi}]

?Which

For instance,  the absolute value of x is given by

f[x_] := Which[ x < 0, -x, x≥ 0, x]

Plot[f[x],{x,-2,2}]

Example 1.

Clear[f]

f[x_] := Which[ x==0, 0, 0 < x < Pi, Pi/4, x == Pi, 0, Pi < x < 2Pi, -Pi/4, x== 2Pi,0]

Plot[f[x], {x,0,2Pi}]

{f[0], f[2], f[Pi], f[5],f[2Pi]}

g[x_] = S[15,x]

Plot[g[x],{x,0,2Pi}]

h[x_] = S[35,x]

Plot[{f[x],h[x]},{x,0,2Pi}]

Plot[ F[x],{x,-3Pi,3Pi}]

Plot[ h[x],{x,-3Pi,3Pi}]

Plot[{F[x],h[x]},{x,-3Pi,3Pi}]

Clear[f,g,h,F]

Example 2.

Clear[f,g,h]

f[x_] := Which[0 ≤x<Pi, x/2, x==Pi, 0 , Pi<x ≤2Pi,x/2-Pi]

Plot[f[x],{x,0,2Pi}]

g[x_] = S[10,x]

Plot[{f[x],g[x]},{x,0,2Pi}]

Plot[F[x],{x,-3Pi,3Pi}]

Plot[{F[x],g[x]},{x,-3Pi,3Pi}]

Exampls 3.

Clear[f,g,h]

f[x_] := Which[ 0 ≤ x ≤ Pi, Pi^2/8-Pi*x/4, Pi < x ≤ 2Pi, Pi*x/4-3Pi^2/8]

Plot[f[x],{x,0,2Pi}]

g[x_] = S[15,x]

h[x_] = S[3,x]

Plot[f[x],{x,0,2Pi}]

Plot[g[x],{x,0,2Pi}]

Plot[{f[x],h[x]},{x,0,2Pi}]

Plot[ {F[x],h[x]},{x,-3Pi,3Pi}]

Example 4.

Clear[f,g,h]

f[x_] := Which[x==0, 0, 0 < x <2Pi, (Pi-x)/2, x==2Pi, 0]

Plot[f[x],{x,0,2Pi}]

g[x_] = S[15,x]

Plot[{F[x], g[x]},{x,-3Pi,3Pi}]