Third example in (L^2)[-π,π]

f[x_]=Exp[x]

Plot[f[x],{x,-Pi,Pi},
Ticks->{Range[-Pi,Pi,Pi/2],Range[-1,30,5]}]

Manipulate[
Plot[{f[x],a0+a1*Cos[x]+b1*Sin[ x]+a2*Cos[2x]+b2*Sin[2x]},{x,-Pi,Pi},
PlotRange->{-5,25},
ImageSize->Medium],
{{a0,0},-5,25},
{{a1,0},-5,5},
{{b1,0},-5,5},
{{a2,0},-5,5},
{{b2,0},-5,5}]

fdotone=Integrate[f[x] ,{x,-Pi,Pi}]

onedotone=Integrate[1^2,{x,-Pi,Pi}]

a[0]=fdotone/onedotone

N[a[0]]

fdotcos=Integrate[f[x] Cos[k x],{x,-Pi,Pi}]

fdotcos=Simplify[fdotcos,Assumptions->Element[k,Integers]]

cosdotcos=Integrate[ Cos[k x]^2,{x,-Pi,Pi}]

cosdotcos=Simplify[cosdotcos,Assumptions->Element[k,Integers]]

a[k_]=fdotcos/cosdotcos

Table[a[k],{k,1,9}]

N[%]

fdotsin=Integrate[f[x] Sin[k x],{x,-Pi,Pi}]

fdotsin=Simplify[fdotsin,Assumptions->Element[k,Integers]]

sindotsin=Integrate[ Sin[k x]^2,{x,-Pi,Pi}]

sindotsin=Simplify[sindotsin,Assumptions->Element[k,Integers]]

b[k_]=fdotsin/sindotsin

Table[b[k],{k,1,9}]

N[%]

Manipulate[
Plot[{f[x],a[0]+Sum[a[k]Cos[k x],{k,1,n}]+Sum[b[k]Sin[k x],{k,1,n}]},{x,-Pi,Pi},
PlotRange->{-2,25},
 ImageSize->Large],{n,1,201,2}]