Closure or Completeness

n[1] = 1/Sqrt[2] {1, 0, -1}

n[2] = 1/Sqrt[3] {1, 1, 1}

n[3] = 1/Sqrt[6] {1, -2,  1}

Outer[Times, n[1], n[1]] // MatrixForm

Outer[Times, n[2], n[2]] // MatrixForm

Outer[Times, n[3], n[3]] // MatrixForm

Sum[Outer[Times, n[i], n[i]], {i, 1, 3}] // MatrixForm

Triangle wave

f[t_]  =  If[t < 1, t, If[t < 3, 2 - t, t - 4]];

Plot[f[t], {t, 0, 4}];

\(T = 4; 
w\  = \ 2\ Pi/T; \)

b[n_]  =  2/T Integrate[f[t] Sin[n w t], {t, 0, 4}];

b[n_] =  
      2/T (
              Integrate[t Sin[n w t], {t, 0, 1}] + 
                Integrate[(2 - t) Sin[n w t], {t, 1, 3}] + 
                Integrate[(t - 4) Sin[n w t], {t, 3, 4}]) // Simplify
           // TrigReduce

b[n_]  =  
      4*(1 - (-1)^n) 
        (-1)^((n - 1)/2)/(n^2 * Pi^2)

Table[{n, b[n]}, {n, 1, 10}] // TableForm

Plot[Sum[b[n] Sin[n w t], {n, 1, 7}], {t, 0, 4}];

Plot[Sum[b[n] Sin[n w t], {n, 1, 100}], {t, 0, 4}];

Square wave

f[t_]  =  If[t < 2, 1, 0];

Plot[f[t], {t, 0, 4}];

\(T = 4; 
w\  = \ 2\ Pi/T; \)

a0 = 1;

b[n_]  =  2/T Integrate[f[t] Sin[n w t], {t, 0, 4}]

b[n_] = (1  -  (-1)^(n))/(n *Pi)

Table[{n, b[n]}, {n, 1, 10}] // TableForm

Plot[a0/2 + Sum[b[n] Sin[n w t], {n, 1, 7}], {t, 0, 4}];

Plot[a0/2 + Sum[b[n] Sin[n w t], {n, 1, 30}], {t, 0, 4}];

Plot[a0/2 + Sum[b[n] Sin[n w t], {n, 1, 200}], {t, 0, 4}];

Sine Wave

Plot[Sin[t], {t, 0, 2  Pi}];

To expand this in a cosine series, we need to make the function even (and double the period).

f[t_] = Sin[Abs[t]];

Plot[f[t], {t, -2 Pi, 2  Pi}];

\(T = 4\ Pi; 
w\  = \ 2\ Pi/T; \)

a[n_]  =  
      2/T Integrate[f[t] Cos[n w t], {t, -2 Pi, 2  Pi}];

a[n_]  =  
      2/T Integrate[-Sin[t] Cos[n w t], {t, -2 Pi, 0}] + 
          2/T Integrate[Sin[t] Cos[n w t], {t, 0, 2  Pi}] // Simplify

We need to treat the n=2 case separately

a[2] = 
      2/T Integrate[-Sin[t] Cos[t], {t, -2 Pi, 0}] + 
          2/T Integrate[Sin[t] Cos[t], {t, 0, 2  Pi}] // Simplify

a[n_] = 4 (-1 + (-1)^n)/((n^2 - 4)*Pi)

Table[{n, a[n]}, {n, 1, 10}] // TableForm

Plot[Sum[a[n] Cos[n w t], {n, 1, 7}], {t, 0, 2  Pi}];

Plot[Sum[a[n] Cos[n w t], {n, 1, 30}], {t, 0, 2  Pi}];