Even Extensions of a function

the original function is defined on [0,L] with L=3:

Clear[f,L];
f[t_] := t /; 0 <= t < 1
f[t_] := (2 - t) /; 1 <= t <= 3
L=3;

Cosine series

calculate the Fourier cosine coefficients mechanically

For cosine series, we integrate f(t) cos(n pi t/L) on [0,L], divide by L, and double.  

This is equivalent to integrating the extended function fe(t) against cos(n pi t/L) on [-L ,L] and dividing by L.  We define fe below.  Notice that we do not really need fe at all.

a0 is calculated separately and involves integrating the function.  The first term in the Fourier Series is a0/2.

Clear[a];
a[0]=2/L((∫_0^1)t\[DifferentialD]t + (∫_1^3)(2-t)\[DifferentialD]t)

We calculate the other cosine coefficients...

a[n_]=2/L((∫_0^1)(t Cos[n π t/L])\[DifferentialD]t + (∫_1^3)((2-t)Cos[n π t/L])\[DifferentialD]t)

Together[%]

There does not seem to be a "nice" pattern for the coefficients...

Table[{n, a[n]},{n,1,8}]

The Fourier partial sums

Clear[PartialCosineSum,t,n,m]
PartialCosineSum[t_,m_]:= (1/3)/2 + Sum[a[n] Cos[n π t/L],{n,1,m}]

terms up to order 4

PartialCosineSum[t,4]

a graph on [0, L] of terms up to order 4

Plot[PartialCosineSum[t,4],{t,0,L}]

a graph on a wider interval of terms up to order 4

Plot[PartialCosineSum[t,4],{t,-10,10}]

the same thing with terms up to order 8.

PartialCosineSum[t,8]

Plot[PartialCosineSum[t,8],{t,-10,10}]

an even extension on [-L,L]

This portion might help us understand extensions of functions; it does not help us calculate Fourier series.  This is not periodic.

Clear[fe,p1,p2]

the original function

p1=Plot[f[t],{t,0,3},PlotStyle->{RGBColor[1,0,0],Thickness[0.01]}]

its even  extension

fe[t_]:=f[t]/;0≤t≤L
fe[t_]:=f[-t]/;-L≤t<0
p2=Plot[fe[t],{t,-L,L}]

See how the extension fits the original function on the original subinterval.  Here are a few ways to show the plots together...

Plot[{f[t], fe[t]},{t,-L,L},PlotStyle->{{Red,Thickness[0.01]},Blue}]

Show[p1,p2]

Show[{p1,p2},PlotRange->{-L,L}]

the Fourier cosine series fits the even extension

Plot[{PartialCosineSum[t,8],fe[t]},{t,-L,L}]

an even periodic extension

Clear[fEvenPeriodic,x];
fEvenPeriodic[x_]:= f[x] /;(0≤x<L)
fEvenPeriodic[x_]:=f[-x] /;(-L≤x < 0)
fEvenPeriodic[x_]:= fEvenPeriodic[x-2*L * Sign[x]]/; ((x <-L)||(x >L ))

Plot[fEvenPeriodic[t],{t,-2L,2L}]

Plot[fEvenPeriodic[t],{t,-5L,5L}]

Plot[{PartialCosineSum[t,8],fEvenPeriodic[t]},{t,-5L,5L}]

TO ACTIVATE THE CELL BELOW, change its style to "input".  I suggest you copy, paste, and change the copy.  Then you can delete the entire piece that is dynamic and retain the command form reference.

Manipulate[Plot[{fEvenPeriodic[t], PartialCosineSum[t, n]}, {t, -r*L, r*L}],
 {{n, 4, "number of series terms"}, 1, 10, 2},
 {{r, 1, "number of periods"}, 1, 3, 1}]