Orthogonality of {sin(kx)}

Integrate[Sin[k x] Sin[l x],{x,-Pi,Pi}]

Simplify[%,Assumptions->{k∈Integers,l∈Integers}]

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

f[x_]=Piecewise[{{Pi^2/8(-2-2/Pi x),-Pi<x<-Pi/2},{Pi^2/8(2/Pi x),-Pi/2<x<Pi/2},{Pi^2/8(2-2/Pi x), Pi/2<x<Pi}}]

Plot[f[x],{x,-Pi,Pi},
Ticks->{Range[-Pi,Pi,Pi/2],Range[-Pi^2/8,Pi^2/8,Pi^2/8]}]

Manipulate[Plot[{f[x],a1*Sin[ x]+a2*Sin[2x]+a3*Sin[3x],a2*Sin[2x],a3*Sin[3x]},{x,-Pi,Pi},
PlotRange->{-1.5,1.5},
ImageSize->Medium],
{{a1,0},-2,2},
{{a2,0},-2,2},
{{a3,0},-2,2},
{{a5,0},-2,2}]

Plot[{f[x], Sin[x]-(1/9)*Sin[3x]+(1/25)*Sin[5x]-(1/49)Sin[7x]},{x,-Pi,Pi},ImageSize->Large]

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

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

fdotv=FullSimplify[fdotv,Assumptions->Element[k,Integers]]

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

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

a[k_]=fdotv/vdotv

a[1]

a[2]

a[3]

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

Table[Sum[a[k]Sin[k x],{k,1,n}],{n,1,9}]

Manipulate[
Plot[{f[x],Sum[a[k]Sin[k x],{k,1,n}],f[x]-Sum[a[k]Sin[k x],{k,1,n}]},{x,-Pi,Pi}, ImageSize->Medium],{n,1,101,2}]