MGM.11 Function spaces and Root-Mean Square Approximation
 BASICS

Needs["LinearAlgebra`MatrixManipulation`"];
Needs["LinearAlgebra`Orthogonalization`"];
Needs["Calculus`Master`"];
Off[Unique::"usym"];
Needs["Graphics`Colors`"];
Off[General::"spell"];
Off[General::"spell1"];
Off[ParametricPlot3D::"ppcom"];
Off[ParametricPlot::"ppcom"];
Off[Plot::"plnr"];
SetOptions[Limit, Analytic -> True];
$Pre = Chop;

CMView = {2.7, 1.6, 1.2};

Vector Drawer

\(\(\( (*\ \(\(:\)\(Date : \ \ Copyright\ 2001\)\), \ 
      Math\ Everywhere, \ \(\(Inc\)\(.\)\)\ 
*) \)\(
\)\( (*
Original\ Conception\ to\ create\ a\ vector\ drawer\ is\ due\ to\ Bill\ Davis . 
Current\ code\ is\ by\ Bruce\ \(\(Carpenter\)\(.\)\)
*) \)\(
\)\( (*\ \ \(\(\(:\)\(Drawbacks : \ \ Since\ the\ vectors\ are\ drawn\ out\ of\)\)\ 

      \ \ \ \ \ context\), \ 
      the\ shapes\ of\ the\ arrowheads\ are\ only\ 
\ \ \ \ \ correct\ with\ AspectRatio\ set\ to\ \(\(Automatic\)\(.\)\)
*) \)\)\)

BeginPackage["Vector3D`","Graphics`Colors`"];

Axes3D::usage = "Axes3D[a, b] creates a Graphics3D object of cartesian axes with x, y, and z running from -a/3 to a, and with axes labels b units beyond the tips of the axes.  Axes3D[a] is Axes3D[a, a/8].";

Perpend::usage = "Perpend[a] returns a unit vector which is perpendicular to the vector a.";

Arrow::usage = "Arrow[a] produces a 2 or 3 dimensional vector from the origin to a. Arrow[a, Tail -> tail] gives a vector from tail to a.";
	
Vector::usage = "Vector[a, b] gives a 2D or 3D vector from a to b.";

ArrowHead::usage = "ArrowHead[a, vec] produces an arrowhead with its tip placed at the point a, pointing in the direction of the vector vec.";

Tail::usage = "Tail -> point puts the tail of the vector at point.";

Norm::usage = "Norm[vec] returns the Euclidean length of vec.";

Normalize::usage = "Normalize[vec] returns a unit vector in the direction of vec, provided vec is nonzero.";

Aperture::usage = "Aperture is the ratio of the radius of the base to the length of the head of a vector.";

TipSize::usage = "TipSize specifies an absolute size for the inner tip length of the head of a vector.";

TipRatio::usage = "TipRatio is the ratio of the inner length of the arrowhead to the length of the shaft of a vector.";

HeadRatio::usage = "HeadRatio is the ratio of the outer length of the arrowhead to the length of the shaft of a vector.";

HeadSize::usage = "HeadSize specifies an absolute size for the head of a vector.";

ScaleFactor::usage = "ScaleFactor specifies the amount to scale a vector in length and may be either a number or a pure function.";

ZeroVectorPointSize::usage = "ZeroVectorPointSize is the size of the point used to represent a zero vector.";

Options[Vector] = Options[Arrow] = Options[ArrowHead] =
{HeadRatio -> 0.18, TipRatio -> 0.14, Aperture -> 0.3, ScaleFactor -> 1, HeadType -> Polygon, ShaftQ -> True, EdgesQ -> True, VectorColor -> RGBColor[0,0,1], ShaftWidth -> 0.005, ZeroVectorPointSize -> 0.01};
		
Begin["`Private`"];

SetOptions[ParametricPlot,AspectRatio -> Automatic];
SetOptions[Plot,AspectRatio -> Automatic];
SetOptions[Graphics,AspectRatio -> Automatic];

Axes3D[u_,v_] := 
      Graphics3D[{
            {Blue,Line[{{-u/3,0,0},{u,0,0}}]},
                    Text["x",{u + v,0,0}],
            {Blue,Line[{{0,-u/3,0},{0,u,0}}]},
                    Text["y",{0, u + v,0}],
            {Blue,Line[{{0,0,-u/3},{0,0,u}}]},
                    Text["z",{0,0,u + v}]}]; 
Axes3D[u_] := Axes3D[u,u/8];
				
Norm[a_?VectorQ] := N[Sqrt[a.a]];

Normalize[a_?VectorQ] := If[a.a == 0, a, a/Norm[a]];

Perpend[a_?VectorQ] := Normalize[{a[[2]],-a[[1]]}]/;Length[a]==2;

Perpend[a_?VectorQ]:=
    Normalize[If[a[[1]]==0,{1,0,0},{a[[2]],-a[[1]],0}]]/;
      Length[a]==3;
      
Base3D = Table[{Cos[2 k Pi/8.], Sin[2 k Pi/8.]},{k,0,8}]; 

Vector[from_?VectorQ, to_?VectorQ, opts___] := Module[
   {sq, sw, ht, hs, hr, tr, ap, sf, vc, zvps, diff = to - from, tip},
   {sq, sw, ht, hs, hr, ts, tr, ap, sf, vc, zvps} = {ShaftQ, ShaftWidth, HeadType, HeadSize, HeadRatio, TipSize, TipRatio, Aperture, ScaleFactor, VectorColor, ZeroVectorPointSize} /. {opts} /. Options[Vector];
   If[from==to, Return[Graphics[{PointSize[zvps],vc,Point[from]}]]];
   diff = If[NumberQ[N[sf]], sf diff, sf[diff]];
   tip = from + diff;
   If[NumberQ[hs], hr = hs/Norm[diff]; tr = 0.75 hr];
   If[NumberQ[ts], tr = ts/Norm[diff]];
   Graphics[{If[sq,{vc,Thickness[sw],Line[{from,tip - tr diff}]},{}],
      With[{trans = ap hr Norm[diff] Perpend[diff]},
      {vc, Thickness[sw], ht[{tip,
                   (tip - hr diff + trans),
                   (tip - tr diff),
                   (tip - hr diff - trans),tip}]}]}]
] /; Length[from]==Length[to]==2

Vector[from_?VectorQ, to_?VectorQ, opts___] := Module[
   {sq, eq, sw, hs, hr, tr,ap, sf, vc, zvps, diff = to - from, tip},
   {sq, eq, sw, hs, hr, ap, sf, vc, zvps} = {ShaftQ, EdgesQ, ShaftWidth, HeadSize, HeadRatio, Aperture, ScaleFactor, VectorColor, ZeroVectorPointSize} /. {opts} /. Options[Vector];
   If[from==to, Return[Graphics3D[{PointSize[zvps],vc,Point[from]}]]];
   diff = If[NumberQ[N[sf]], sf diff, sf[diff]];
   tip = from + diff;
   If[NumberQ[hs], hr = hs/Norm[diff]];
   tr = hr/2;
   Graphics3D[{If[sq,{vc,Thickness[sw],Line[{from,tip-tr diff}]},{}], If[eq, {}, EdgeForm[]], {SurfaceColor[vc],
      With[{temp = Perpend[diff]},
      Polygon[Append[#,tip]]& /@ Partition[(tip - hr diff + #)&/@((ap hr Norm[diff] Base3D) . {temp,Normalize[Cross[temp,diff]]}),2,1]]}}]
] /; Length[from]==Length[to]==3


Arrow[a_, Tail->b_, opts___] := Vector[b,a+b,opts]

Arrow[a_, opts___] := Vector[Table[0,{Length[a]}],a,opts]

ArrowHead[a_, b_, opts___] := Vector[a-b,a,ShaftQ->False,opts];

End[];

EndPackage[];
Null

Graphics`Colors`GosiaGreen = 
        RGBColor[0,  0.392187,  0];

ThreeAxes[u,v]

ThreeAxes[u_, v_] := 
        Graphics3D[{{Blue, Line[{{-u, 0, 0}, {u, 0, 0}}]}, 
            Text["x", {u + v, 0, 0}], {Blue, 
              Line[{{0, -u, 0}, {0, u, 0}}]}, 
            Text["y", {0, u + v, 0}], {Blue, 
              Line[{{0, 0, 0}, {0, 0, u}}]}, 
            Text["z", {0, 0, u + v}]}];
ThreeAxes[u_] := ThreeAxes[u, (u/8)];
ThreeAxes::"usage" = "ThreeAxes[a,b] makes a standard cartesian \
axis graphics object with x, y, and z running from -a to a, and with axis \
labels b units beyond the tips of the axes.  ThreeAxes[a] is \
ThreeAxes[a,a/8].";

Needs["Statistics`ContinuousDistributions`"];

Clear[matrixplucker];
matrixplucker[expr_, 
        vars_] := Simplify[
          Outer[D, {expr}, 
            vars]][[1]]

B.1) The root-mean-square distance between two functions f[t] and g[t] on [a,b] is \(\@\(∫\_a\%b\(\((f[t] - g[t])\)\^2\) dt\)\)
 The Dot product f•g of two functions on  [a,b] is (∫_a^b) f[t] g[t] dt.
 Component of one function in the direction of another

B.1.a) Distance between two functions on an interval.

Here are two functions f[t] and g[t]  on [a,b] with  a = 0 and b = 2.5:

a = 0; 
b = 4;
Clear[f, g, t];
f[t_] = Cos[t]^2;
g[t_] = Sin[t];
Plot[{f[t], g[t]}, {t, a, b}, 
        PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
              NavyBlue}}, AxesLabel -> {"t", ""}];

How do folks measure the root-mean-square distance between f[t] and g[t] on [a,b]?

Folks plot (((f[t] - g[t]))^2) on [a,b] and shade between the curve and the t - axis:

\(\(\(rmsplot\  = \ 
        Plot[\((f[t] - g[t])\)^2, {t, a, b}, 
          PlotStyle -> {{Thickness[0.01], Red}}, 
          AxesLabel -> {"t", "(f[t] - g[t])^2"}, 
          Epilog -> \ Table[{Blue, Thickness[0.01], 
                Line[{{t, 0}, {t, \((f[t] - g[t])\)^2}}]}, {t, a, 
                b, \((b\  - \ a)\)/24}]];\)\(
\)\)\)

They calculate the area measurement of the shaded region and then they say that the root-mean -square distance between f[t] and g[t] on [a,b] is the square root of the area measurement.
In short, the root mean square distance between f[t] and g[t] on [a,b] is   
       (Sqrt[(∫_a^b)(((f[t] - g[t]))^2) dt])

(Sqrt[NIntegrate])[(((f[t] - g[t]))^2), {t, a, b}]

Try it for two new functions f[t] and g[t] on a new interval [a,b]:

a  =  -1;
b  =  1;
Clear[f, g, t];
f[t_]  =  5 t - 20 (t^3) + 16 (t^5);
g[t_]  =  1 - 8 (t^2) + 8 (t^4);
Plot[{f[t], g[t]}, {t, a, b}, 
      PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
            NavyBlue}}, AxesLabel -> {"t", ""}]

\(\(rmsplot = 
        Plot[\((f[t] - g[t])\)\^2, {t, a, b}, 
          PlotStyle -> {{Thickness[0.01], Red}}, 
          AxesLabel -> {"t", \*""(f[t]- g[t\!\(\(]\^2\)\))""}, 
          AspectRatio -> 1\/GoldenRatio, 
          Epilog -> 
            Table[{NavyBlue, Thickness[0.01], 
                Line[{{t, 0}, {t, \((f[t] - g[t])\)\^2}}]}, {t, a, 
                b, \(b - a\)\/24}]];\)\)

The root mean square distance between f[t] and g[t] on [a,b] is   
       \(\@\(∫\_a\%b\(\((f[t] - g[t])\)\^2\) dt\)\):

(Sqrt[NIntegrate])[(((f[t] - g[t]))^2), {t, a, b}]

B.1.b) The dot product f•g  of two functions f[t] and g[t] on an interval [a,b]

Here are two functions f[t] and g[t]  on [a,b] with  a = 0 and b = Pi:

a = 0; 
b = π
Clear[f, g, t]; 
f[t_] = (E^(-0.2 t)) Cos[2 t]; 
g[t_] = -Sin[2 t]; 
Plot[{f[t], g[t]}, {t, a, b}, 
        PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
              NavyBlue}}, AxesLabel -> {"t", ""}];

How do folks measure calculate dot product  f•g   of f[t] and g[t] on [a,b]?

Folks plot f[t] g[t] on [a,b] and shade between the curve and the t - axis:

\(\(\(dotplot\  = \ 
        Plot[f[t]\ g[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], Red}}, 
          AxesLabel -> {"t", "f[t] g[t]"}, 
          Epilog -> \ Table[{If[f[t]\ g[t]\  > 0, Blue, DarkOrange], 
                Thickness[0.01], Line[{{t, 0}, {t, f[t]\ g[t]}}]}, {t, a, 
                b, \((b\  - \ a)\)/24}]];\)\(
\)\)\)

They put f•g equal the signed area measurement of the shaded region (subtracting the orange from the blue). 
This is the same as 
              f•g  = 
        (∫_a^b) f[t] g[t] dt:

NIntegrate[f[t] g[t] , {t,  a, b}]

Try it for two new functions f[t] and g[t] on a new interval [a,b]:

a  =  -1;
b  =  1;
Clear[f, g, t];
f[t_]  = 0.3  - 7 t + 56 (t^3) - 112 (t^5) + 64 (t^7);
g[t_]  = -1.2 + 18  (t^2) - 48 (t^4) + 32 (t^6);
Plot[{f[t], g[t]}, {t, a, b}, 
        PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
              Blue}}, AspectRatio -> (1/GoldenRatio), 
        AxesLabel -> {"t", ""}];

\(\(\(dotplot\  = \ 
        Plot[f[t]\ g[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], Red}}, 
          AxesLabel -> {"t", "f[t] g[t]"}, 
          Epilog -> \ Table[{If[f[t]\ g[t]\  > 0, Blue, DarkOrange], 
                Thickness[0.01], Line[{{t, 0}, {t, f[t]\ g[t]}}]}, {t, a, 
                b, \((b\  - \ a)\)/24}]];\)\(
\)\)\)

f•g  = 
        (∫_a^b) f[t] g[t] dt:

NIntegrate[f[t] g[t] , {t,  a, b}]

These two functions are close to being perpendicular.

B.1.c.i) The component of one function in the direction of another on an interval

Here are two functions f[t] and g[t]  on [a,b] with  a = 0 and b = π:

a = 0; 
b = π; 
Clear[f, g, t]; 
f[t_] = 2 (E^(-0.4 t)); 
g[t_] = 2 Sin[t]; 
Plot[{f[t], g[t]}, {t, a, b}, 
      PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
            Blue}}, AxesLabel -> {"t", ""}, 
      Epilog -> {Text["f[t]", {a + 1, f[a + 1]}], 
          Text["g[t]", {a + 1, g[a + 1]}]}];

How do folks come up with the component of f[t] in the direction of g[t] on the plotted interval?

They do it just the way you do it with vectors in kD:
             (Subscript[comp, g]) f[t]   =f•(g/g)•g  g[t]
where
            f•g = (∫_a^b) f[t] g[t] dt  and g•g = (∫_a^b) g[t] g[t] dt.
See  its formula:

f•g  =  NIntegrate[f[t] g[t], {t, a, b}];
g•g  =  NIntegrate[g[t] g[t], {t, a, b}];
Clear[compfg];
\(	compfg[t_]\ \ \  = f•g\/g•g\ \ g[t]\)

\(\(\(compplot\ \  = \ 
        Plot[{f[t], g[t], compfg[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
                Blue}, {Thickness[0.01], Red}}, 
          AxesLabel -> {"t", ""}, 
          Epilog -> {Text["f[t]", {a\  + \ 1, f[a\  + \ 1]}], 
              Text["g[t]", {a\  + \ 1, 
                  g[a\  + \ 1]}], 
			Text["compfg[t]", {b\  - 1, 
                  compfg[b - 1]}]}];\)\(\ \)\(
\)\)\)

Try it for two new functions f[t] and g[t]  on a new interval [a,b]

a = -π; 
b = π; 
Clear[f, g, t]; 
f[t_] = (3/(1 + 2 (((t  +  1))^2))); 
g[t_] = Cos[t]; 
Plot[{f[t], g[t]}, {t, a, b}, 
      PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
            Blue}}, AxesLabel -> {"t", ""}, 
      Epilog -> {Text["f[t]", {a + 1, f[a + 1]}], 
          Text["g[t]", {a + 1, g[a + 1]}]}];

f•g  =  NIntegrate[f[t] g[t], {t, a, b}];
g•g  =  NIntegrate[g[t] g[t], {t, a, b}];
Clear[compfg];
\(	compfg[t_]\ \ \  = f•g\/g•g\ \ g[t]\)

\(\(\(compplot\ \  = \ 
        Plot[{f[t], g[t], compfg[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.01], DarkOrange}, {Thickness[0.01], 
                Blue}, {Thickness[0.01], Red}}, 
          AxesLabel -> {"t", ""}, 
          Epilog -> {Text["f[t]", {a\  + \ 1, f[a\  + \ 1]}], 
              Text["g[t]", {a\  + \ 1, 
                  g[a\  + \ 1]}], 
			Text["compfg[t]", {b\  - 1, 
                  compfg[b - 1]}]}];\)\(\ \)\(
\)\)\)

The component of f[x] in the direction of g[t] is a multiple of g[t].

B.1.c.ii) Explanation of where the formula     (Subscript[comp, g]) f[t]   = f•(g/g)•g  g[t] comes from

Explain where the formula 
\(TextForm\`	
    compfg[t]\ \ \  = f•g\/g•g\ \ g[t]\)
comes from.

The root mean square distance between f[t] and  c g[t] on the interval [a,b] is
          rmssquared[c] = (∫_a^b)(((f[t]-c g[t]))^2)dt
Differentiate with respect to c:
            rmssquared'[c]  = (∫_a^b) (∂_c)(((f[t]-c g[t]))^2)dt
                                   = (∫_a^b) 2(f[t]-c g[t])(-g[t]) dt
                                   = -2 (∫_a^b)g[t] (f[t]-c g[t])dt
                                   = -2 (∫_a^b)g[t] f[t]dt  + 2c(∫_a^b) g[t] g[t] dt)
                                   = -2 (f• g  - c g• g)

So:
                      rmssquared'[c] =0 for c=((f• g)/(g• g.))
 The upshot:
  c=((f• g)/(g• g)) minimizes the root-mean-square distance between f[t] and c g[t] on [a,b] .
  
In other words, the component of f[t] in the direction of g[t] is the multiple of g[t] that is closest to f[t].

B.2) Orthogonal sets of functions:
The Sine system on [0,π]
The Cosine system on [0,π]
The Sine -Cosine system on [-π,π]
The Sine -Cosine system on [0,2π]
The Legendre Polynomial system on [-1,1]

Function spaces spanned by orthogonal sets of functions

B.2.a.i)  Orthogonal families of functions

Folks like to say that a given set of non-zero functions 
         {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t],  . . .}
defined on an interval [a,b] are orthogonal (mutually perpendicular) on [a,b] 
if
       (Subscript[s, p]) • (Subscript[s, q]) = (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt = 0     when p ≠ q.
and
         (∫_a^b) (Subscript[s, p])[t]^2 dt > 0 for all the p's.
Give some examples of orthogonal sets all the pros know:

Here you go:

▪ Sine system on [0, π]:

The set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t],  . . .}
for
         (Subscript[s, k])[t]  =  Sin[k t] 
is an orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = π.
Here are plots of the first five.

Clear[s, Subscript, k, t];
(Subscript[s, k])_[t_]  :=  
      Sin[k t]
a  =  0;
b  = π;
Plot[{(Subscript[s, 1])[t],(Subscript[s, 2])[t],(Subscript[s, 3])[t],(Subscript[s, 4])[t],(Subscript[s, 5])[t]},{t, a, b},PlotStyle -> {{Black}, {Blue}, {Magenta}, {Red}, {Green}},
PlotLabel -> Sines on [a, b]];

To illustrate the fact that this set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
is an orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = π,
here is a calculation of
            (Subscript[s, p]) •(Subscript[s, q])  =   (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt
for random positive integers p and q with p ≠q

q = Random[Integer, {1, 6}]; 
p = Random[Integer, {q + 1, 3 q}]; 
(∫_a^b) (Subscript[s, q])[t] (Subscript[s, p])[t] \[DifferentialD]t

▪ Cosine system on [0, π]:

The set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
for
         (Subscript[s, k])[t]  =  Cos[(k  -  1) t] 
is an orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = π.
Here are plots of the first five.

Clear[Subscript, s, k, t];
(Subscript[s, k])_[t_] := Cos[(k - 1) t]
a = 0;
b = π;
Plot[{(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t]}, {t, a, b}, 
        PlotStyle -> {{Black}, {Blue}, {Magenta}, {Red}, {Green}}, 
        PlotLabel -> Cosines on[a, b]];

To illustrate the fact that this set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
is an orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = π,
here is a calculation of
            (Subscript[s, p]) •(Subscript[s, q])  =   (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt
for random positive integers p and q with p ≠q

q = Random[Integer, {1, 6}]; 
p = Random[Integer, {q + 1, 3 q}]; 
(∫_a^b) (Subscript[s, q])[t] (Subscript[s, p])[t] \[DifferentialD]t

▪ Sine-Cosine system on [-π, π]:

This set of functions 
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .  }  
       = {1, Sin[t], Cos[t], Sin[2 t], Cos[2 t], Sin[3 t], Cos[3 t], 
         .   .   . }
is an orthogonal set on the interval a ≤ t ≤ b with a = -π and b = π.
Here are formulas for the first 13.

Clear[s, Subscript, k, t];
(Subscript[s, k])_[t_] := 
        If[EvenQ[k], Sin[((k t)/2)], 
          Cos[(1/2) (k - 1) t]];
Table[(Subscript[s, k])[t], {k, 1, 13}]

And plots of the first seven:

a = -π; 
b = π; 
Plot[{(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t], (Subscript[s, 6])[t], 
          (Subscript[s, 7])[t]}, {t, a, b}, 
        PlotStyle -> {{NavyBlue}, {Red}, {NavyBlue}, {Red}, {NavyBlue}, {Red}, {NavyBlue}}, PlotLabel -> SinesCosines on[a, b]];

To illustrate the fact that this set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
is an orthogonal set on the interval a ≤ t ≤ b with a = -π and b = π,
here is a calculation of
            (Subscript[s, p]) •(Subscript[s, q])  =   (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt
for random positive integers p and q with p ≠q

q = Random[Integer, {1, 6}]; 
p = Random[Integer, {q + 1, 3 q}]; 
(∫_a^b) (Subscript[s, q])[t] (Subscript[s, p])[t] \[DifferentialD]t

▪ Sine-Cosine system on [0, 2π]:

This set of functions 
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . }  
       = {1, Sin[t], Cos[t], Sin[2 t], Cos[2 t], Sin[3 t], 
        Cos[3 t], . . .}
is also orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = 2  π.
Here are formulas for the first 15.

Clear[s, Subscript, k, t]; 
(Subscript[s, k])_[t_] := 
      If[EvenQ[k], Sin[((k t)/2)], Cos[(1/2) (k - 1) t]]; 
Table[(Subscript[s, k])[t], {k, 1, 15}]

And plots of the first seven:

a = 0;
b = 2 π;
Plot[{(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t], (Subscript[s, 6])[t], 
          (Subscript[s, 7])[t]}, {t, a, b}, 
        PlotStyle -> {{NavyBlue}, {Red}, {NavyBlue}, {Red}, {NavyBlue}, {Red}, {NavyBlue}}, 
        PlotLabel -> SinesandCosines on[a, b]];

To illustrate the fact that this set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
is an orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = 2  π,
here is a calculation of
            (Subscript[s, p]) •(Subscript[s, q])  =   (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt
for random positive integers p and q with p ≠q

q  =  Random[Integer, {1, 6}];
p  = Random[Integer, {q  +  1, 3  q}];
Integrate[(Subscript[s, q])[t] (Subscript[s, p])[t], {t, a, b}]

▪ Legendre polynomial system on [-1,1]:

The set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
for
         (Subscript[s, k])[t]  =  LegendreP[k - 1,  t] 
is an orthogonal set on the interval a ≤ t ≤ b with a = -1 and b = 1.
Here are the formulas for the first six:

Clear[k];
ColumnForm[Table[LegendreP[k  - 1,  t], {k, 1, 6}]]

Here are plots of the first six:

Clear[s, Subscript, k, t]; 
(Subscript[s, k])_[t_] := LegendreP[k - 1, t]; 
a = -1; 
b = 1; 
Plot[{(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t], (Subscript[s, 6])[t]}, {t, a, b}, 
      PlotStyle -> {{Black}, {Blue}, {Magenta}, {Red}, {Green}, {CadmiumOrange}}, 
      PlotLabel -> Legendre Polynomials on[a, b]];

To illustrate the fact that this set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
is an orthogonal set on the interval a ≤ t ≤ b with a = -1 and b = 1,
here is a calculation of
            (Subscript[s, p]) •(Subscript[s, q])  =   (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt
for random positive integers p and q with p ≠q

q  =  Random[Integer, {1, 6}];
p  = Random[Integer, {q  +  1, 3  q}];
Integrate[(Subscript[s, q])[t] (Subscript[s, p])[t], {t, a, b}]

B.2.a.ii) Using orthogonal families to make function spaces

How do you use orthogonal sets of functions to make function spaces?

Very easily.
You with a finite set of functions 
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t]}
 orthogonal on the interval a ≤ t ≤ b (so that   (Subscript[s, p]) • (Subscript[s, q]) = (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt = 0     when p ≠ q) and then you make the function space S[a,b] spanned by
         {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t]}.
This function space consists of all functions that are linear combinations of the spanning set
         {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t]}.
In other words, S[a,b] consists of all functions f[t] of the form.
           f[t] = (∑_(j = 1)^k) (Subscript[c, j]) (Subscript[s, j])[t]  with  a ≤ t ≤ b.

Here is a random member f[t] of the function space S[0, π] spanned by
           {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  (Subscript[s, 4])[t], (Subscript[s, 5])[t]}
for
         (Subscript[s, k])[t]  =  Sin[k t]

dim = 5;
Clear[f, s, g, k, t];
(Subscript[s, k])_[t_] := Sin[k t];
a = 0;
b = π;
(Subscript[c, k])_ := Random[Real, {-2, 2}]
f[t_] = (∑_(k = 1)^dim) (Subscript[c, k]) (Subscript[s, k])[t]

And its plot:

Plot[f[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], Magenta}}, 
        AxesLabel -> {"t", "f[t]"}, 
        AspectRatio -> (1/GoldenRatio), 
        PlotLabel -> "Member of the function space on [0,Pi] \n     \
spanned by sines"];

See some more functions in this function space::

dim = 5;
Clear[f, s, g, k, t];
(Subscript[s, k])_[t_] := Sin[k t];
a = 0;
b = π;
(Subscript[c, k])_ := Random[Real, {-2, 2}];
f[t_] = (∑_(k = 1)^dim) (Subscript[c, k]) (Subscript[s, k])[t]
Plot[f[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], Magenta}}, 
        AxesLabel -> {"t", "f[t]"}, 
        AspectRatio -> (1/GoldenRatio), 
        PlotLabel -> "Member of the function space on [0,π] \n     \
spanned by sines"];

Here is a random member of the function space S[0, π] spanned by
           {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  (Subscript[s, 4])[t], (Subscript[s, 5])[t], (Subscript[s, 6])[t]}
for
         (Subscript[s, k])[t]  =  Cos[(k  -  1) t] .

dim = 6;
Clear[f, s, g, k, t];
(Subscript[s, k])_[t_] := Cos[(k - 1) t]
a = 0;
b = π;
(Subscript[c, k])_ := Random[Real, {-2, 2}]
f[t_] = (∑_(k = 1)^dim) (Subscript[c, k]) (Subscript[s, k])[t]

And a plot:

Plot[f[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], Red}}, 
        AxesLabel -> {"t", "f[t]"}, 
        AspectRatio -> (1/GoldenRatio), 
        PlotLabel -> "Member of the function space on [0,π] \n    \
spanned by cosines"];

See some more functions in this function space::

dim = 6;
Clear[f, s, g, k, t];
(Subscript[s, k])_[t_] := Cos[(k - 1) t]
a = 0;
b = π;
(Subscript[c, k])_ := Random[Real, {-2, 2}]
f[t_] = (∑_(k = 1)^dim) (Subscript[c, k]) (Subscript[s, k])[t]
Plot[f[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], Red}}, 
        AxesLabel -> {"t", "f[t]"}, 
        AspectRatio -> (1/GoldenRatio), 
        PlotLabel -> "Member of the function space on [0,π] \n    \
spanned by cosines"];

Here is a random member of the function space S[-1, 1] spanned by
           {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  (Subscript[s, 4])[t]}
for
         (Subscript[s, k])[t]  =  LegendreP[k - 1,  t] .

dim = 4;
Clear[f, s, g, k, t];
(Subscript[s, k])_[t_] := LegendreP[k - 1, t]
a = -1;
b = 1;
(Subscript[c, k])_ := Random[Real, {-1, 2}]
f[t_] = (∑_(k = 1)^dim) (Subscript[c, k]) (Subscript[s, k])[t]

And its plot:

Plot[f[t], {t, a, b}, 
      PlotStyle -> {{Thickness[0.01], DarkOrange}}, 
      AxesLabel -> {"t", "f[t]"}, 
      AspectRatio -> (1/GoldenRatio), 
      PlotLabel -> "Member of the function space on [-1,1] \n   \
spanned by Legendre Polynomials"];

See more:

dim = 4;
Clear[f, s, g, k, t];
(Subscript[s, k])_[t_] := LegendreP[k - 1, t]
a = -1;
b = 1;
(Subscript[c, k])_ := Random[Real, {-1, 2}]
f[t_] = (∑_(k = 1)^dim) (Subscript[c, k]) (Subscript[s, k])[t]
Plot[f[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], DarkOrange}}, 
        AxesLabel -> {"t", "f[t]"}, AspectRatio -> 1/GoldenRatio, 
        PlotLabel -> "Member of the function space on [-1,1] \n   spanned \
by Legendre Polynomials"];

B.2.a.iii) Reading the dimension of a function space

To make a function space S[a,b], you go with a finite set of functions 
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t]}
 orthogonal on the interval a ≤ t ≤ b  and then you make the function space S[a,b] spanned by
         {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t]}.
This function space consists of all functions f[t] of the form.
           f[t] = (∑_(j = 1)^k) (Subscript[c, j]) (Subscript[s, j])[t]  with  a ≤ t ≤ b.
 How do you read off the dimension of S[a,b]?

The functions f[t] = (∑_(j = 1)^k) (Subscript[c, j]) (Subscript[s, j])[t] in S[a,b] allow freedom for k constants
              {(Subscript[c, 1, ])(Subscript[c, 2]),(Subscript[c, 3]),. . .,(Subscript[c, k])}.
 So the dimension of S[a,b] is k.

B.3)  Fourier Approximations: Best root-mean-square approximation of a function by a member of a function space

B.3.a.i) Coming up with the member of a function space that is closest to a given function

Here's  a function f[t] plotted on [0, π]:

Clear[f, t];
f[t_] = (6.2/(1.3 + (E^(-t))))
fplot = 
        Plot[f[t], {t, 0, π}, 
          PlotStyle -> {{Thickness[0.015], NavyBlue}}, 
          AxesLabel -> {"t", "f[t]"}];

The set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
for
         (Subscript[s, k])[t]  =  Cos[(k  -  1) t] 
is an orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = π.
Here are plots of the first five.

Clear[s, Subscript, k, t]; 
(Subscript[s, k])_[t_] := Cos[(k - 1) t]
a = 0; 
b = π; 
Plot[{(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t]}, {t, a, b}, 
      PlotStyle -> {{Black}, {Blue}, {Magenta}, {Red}, {Green}}, 
      PlotLabel -> Cosines on[a, b]];

Go with the function space S[a,b] spanned by:

khigh  =  3;
Table[ (Subscript[s, k])[t], {k, 1, khigh}]

Come up with the function Sclosest[t] in  S[0,Pi]  so that
the root-mean-square distance between f[t] and Sclosest[t] is as small as possible

It's not bad at all.
For each k, you take the component of f[t] in the direction of (Subscript[s, k])[t]:
           f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k]))) (Subscript[s, k])[t]
and then you add them up to get
           Sclosest[t]=(∑_(k = 1)^khigh) f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k])))(Subscript[s, k])[t]:

Clear[fouriercoeff, Sclosest, k];
fouriercoeff[k_] := fouriercoeff[k] = 
          NIntegrate[f[t] (Subscript[s, k])[t], {t, a, b}]/NIntegrate[(Subscript[s, k])[t] (Subscript[s, k])[t], {t, a, b}];
Sclosest[
        t_] = (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[t]

See the quality of the approximation of  f[t] by Sclosest[t]:

fitplot  =  
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.015], NavyBlue}, {Thickness[0.01], 
                Red}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{NavyBlue, 
                Text["f[t]", {a  +  1, f[a  +  1]}]}, {Red, 
                Text["Sclosest[t]", {b  -  1, 
                    Sclosest[b - 1]}]}}];

Not bad.
The root-mean-square distance between f[t] and Sclosest[t] is:

(Sqrt[NIntegrate])[(((f[t] - Sclosest[t]))^2), {t, a, b}]

B.3.a.ii) Increasing the quality of the approximation

Stay with the same set up as above.
What can you do to increase the quality of the approximation of f[t] by a combination of Cosines?

Do the same thing but use more cosines, by raising khigh from 3 (as it was above ) to 5 (or any other integer bigger than 3).

The function in the function space S[a,b] spanned by

khigh  =  8;
Table[ (Subscript[s, k])[t], {k, 1, khigh}]

that is closest to f[t] is

Sclosest[t]=(∑_(k = 1)^khigh) f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k])))(Subscript[s, k])[t]
See the formula:

Clear[fouriercoeff, Sclosest, k];
fouriercoeff[k_] := fouriercoeff[k] = 
          NIntegrate[f[t] (Subscript[s, k])[t], {t, a, b}]/NIntegrate[(Subscript[s, k])[t] (Subscript[s, k])[t], {t, a, b}];
Sclosest[
        t_] = (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[t]

See the quality of the approximation of  f[t] by Sclosest[t]:

fitplot  =  
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.015], NavyBlue}, {Thickness[0.01], 
                Red}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{NavyBlue, 
                Text["f[t]", {a  +  1, f[a  +  1]}]}, {Red, 
                Text["Sclosest[t]", {b  -  1, 
                    Sclosest[b - 1]}]}}];

Sharing lots of ink.
That's very good.
You can do even better if you use more cosines by raising khigh:

The function in the function space S[a,b] spanned by

khigh  = 15;
Table[ (Subscript[s, k])[t], {k, 1, khigh}]

that is closest to f[t] is

Sclosest[t]=(∑_(k = 1)^khigh) f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k])))(Subscript[s, k])[t]:

Clear[fouriercoeff, Sclosest, k];
fouriercoeff[k_] := fouriercoeff[k] = 
          NIntegrate[f[t] (Subscript[s, k])[t], {t, a, b}]/NIntegrate[(Subscript[s, k])[t] (Subscript[s, k])[t], {t, a, b}];
Sclosest[
        t_] = (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[t]

See the quality of the approximation of  f[t] by Sclosest[t]:

fitplot  =  
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.015], NavyBlue}, {Thickness[0.01], 
                Red}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{NavyBlue, 
                Text["f[t]", {a  +  1, f[a  +  1]}]}, {Red, 
                Text["Sclosest[t]", {b  -  1, 
                    Sclosest[b - 1]}]}}];

Very,very good.

Cool fit.
Sharing ink almost all the way.
The root-mean-square distance between f[t] and Sclosest[t] is:

(Sqrt[NIntegrate])[(((f[t] - Sclosest[t]))^2), {t, a, b}]

B.3.a.iii) Legendre

Here is a function f[t] plotted on [-1,1]:

Clear[f, t];
f[
          t_] = ((3.29 (Sin[2 t] + Cos[t]))/(1.3 + (E^(3.8 (t^2)))));
fplot = 
        Plot[f[t], {t, -1, 1}, 
          PlotStyle -> {{Thickness[0.01], Blue}}, 
          AxesLabel -> {"t", "f[t]"}];

The set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t],  .   .   . , (Subscript[s, k])[t],  
         .   .   . }
for
         (Subscript[s, k])[t]  =  LegendreP[k - 1,  t] 
is an orthogonal set on the interval a ≤ t ≤ b with a = -1 and b = 1.
Here are the formulas for the first six:

Clear[k];
ColumnForm[Table[LegendreP[k  - 1,  t], {k, 1, 6}]]

Here are plots of the first six:

Clear[s, g, k, t]; (Subscript[s, k])_[t_] := LegendreP[k - 1, t]; a = -1; b = 1; 
    Plot[{(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t], (Subscript[s, 6])[t]}, {t, a, b}, 
      PlotStyle -> {{Black}, {Blue}, {Magenta}, {Red}, {Green}, {CadmiumOrange}}, 
      PlotLabel -> Legendre Polynomials on[a, b]];

Go with the function space S[a,b] spanned by:

khigh  =  9;
Table[ (Subscript[s, k])[t], {k, 1, khigh}]

Come up with the function Sclosest[t] in  S[a,b]  so that
the root-mean-square distance between f[t] and Sclosest[t] is as small as possible

You do it the same way you did it with Cosines in part i).
For each k you take the component of f[t] in the direction of (Subscript[s, k])[t]:
           f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k]))) (Subscript[s, k])[t]
and then you add them up to get
           Sclosest[t]=(∑_(k = 1)^khigh) f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k])))(Subscript[s, k])[t]:

Clear[fouriercoeff, Sclosest, k];
fouriercoeff[k_] := fouriercoeff[k] = 
          NIntegrate[f[t] (Subscript[s, k])[t], {t, a, b}]/NIntegrate[(Subscript[s, k])[t] (Subscript[s, k])[t], {t, a, b}];
Sclosest[
        t_] = (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[t]

See the quality of the approximation of  f[t] by Sclosest[t]:

fitplot  =  
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.015], NavyBlue}, {Thickness[0.01], 
                Red}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{NavyBlue, 
                Text["f[t]", {a  +  1, f[a  +  1]}]}, {Red, 
                Text["Sclosest[t]", {b  -  1, 
                    Sclosest[b - 1]}]}}];

Lookin' good and feeling good.

The root-mean-square distance between f[t] and closest[t] is:

(Sqrt[NIntegrate])[(((f[t] - Sclosest[t]))^2), {t, a, b}]

B.3.a.iv) Other orthogonal families

Does the same technique work for all function spaces S[a,b] spanned by an orthogonal set on [a,b]?

Sure does.

B.3.a.v) Why it works

Why does this technique work for all function spaces S[a,b] spanned by an orthogonal set on[a,b]?

Perpendicularity explanation

Put  Sclosest[t] = \(∑\+\(k = 1\)\%n\(\(\ \ \)\(f•s\_k\/\(s\_k\ •s\_k\)\ s\_k[t]\ \ 

                  and\ take\ p\ with\ 1\)\)\  ≤ \ 
                p\  ≤ \ n\ and\ look\ at\)
                 (f  -  Sclosest) •(Subscript[s, p]) = \(f•s\_p - \ \ s•s\_\(\(p\)\(\ \)\)\ \ 
		\ \ \ \ \ \ \ \ \ \ \  = \ \ \(f•s\_p - \ ∑\+\(k = 1\)\%n\ \ f•s\_k\/\(s\_k\ •s\_k\)\ s\_k\ •s\_\(\(p\)\(\ \)\)\ 
			\ \ \ \ \ \ \ \ \ \ \  = \ \ \(f•s\_p - \ 
                f•s\_p\/\(s\_p\ •s\_p\)\ s\_p\ •s\_\(\(p\)\(\ \)\)\ \ \ \ \ \ \ \ \ \ \((because\ s\_k\ •s\_\(\(p\)\(\ \)\) = \ 0\ for\ k ≠ \ 
                        p)\)
			\ \ \ \ \ \ \ \ \ \ 	 = \ \(f•s\_p - \ f•s\_p\ \  = \ 0. \)\)\)\)

This little manipulation reveals that 
              (f[t] - Sclosest[[t]) 
is perpendicular to each of the functions 
           {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, n])[t]} 
and so (f[t] - Sclosest[t]) is perpendicular to every function 
             g[
          t]  =  (∑_(k = 1)^n)  (Subscript[c, k]) (Subscript[s, k])[
              t]  
in the function space S spanned by {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, n])[t]}.
And because perpendicular distance is the shortest distance, 
         \(TextForm\`\(\(\ \)\(Sclosest[
          t]\  = \ \(\(∑\+\(k = 
                1\)\%n\)\(\(\ \ \)\(f•s\_k\/\(s\_k\ •s\_k\)\ s\_k[t]\)\)\(\ \)\)\)\)\)
is the function in  S closest to f[t].

Calculus explanation

Agree that
              g[t] = (∑_(k = 1)^n)  (Subscript[c, k]) (Subscript[s, k])[t]  
is the generic member of the  function space S spanned by {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, n])[t]}.

Look at the square of the root-mean-square distance from f to g:
         \(\(\(\(||\)\(f\  - g\)\)\( || \^2\)\)\) = (f - g) • (f - g) =   f • f  -  2 f • g  +  
          g• g)
 This is the same as
        \(\(\(\(||\)\(f\  - g\)\)\( || \^2\)\)\) = f • f -  2  f• (∑_(k = 1)^n)(Subscript[c, k]) (Subscript[s, k]) + (∑_(k = 1)^n)(Subscript[c, k]) (Subscript[s, k])• (∑_(k = 1)^n)(Subscript[c, k]) (Subscript[s, k]) .
This is the same as
        \(\(\(\(||\)\(f\  - g\)\)\( || \^2\)\)\) = f • f  - 2 f• (∑_(k = 1)^n)(Subscript[c, k]) (Subscript[s, k]) + (∑_(k = 1)^n)(Subscript[c, k]) (Subscript[s, k])• (∑_(k = 1)^n)(Subscript[c, p]) (Subscript[s, p]) .
This is the same as
         \(\(\(\(||\)\(f\  - g\)\)\( || \^2\)\)\) = f • f  - 2(∑_(k = 1)^n)(Subscript[c, k]) f•(Subscript[s, k]) + (∑_(k = 1)^n)(((Subscript[c, k ]))^2) (Subscript[s, k]) •(Subscript[s, k])        because \(TextForm\`\(\(s\_k\ •s\_\(\(p\)\(\ \)\)\)\(=\)\(\ \)\(0\)\(\ \)\)\) for k ≠ p.
         
Now remember that   g[
          t]  =  (∑_(k = 1)^n)  (Subscript[c, k]) (Subscript[s, k])[
              t]  .
To see what   (Subscript[c, k])'s make \(\(\(\(||\)\(f\  - g\)\)\( || \^2\)\)\) as small as possible, 
differentiate \(\(\(\(||\)\(f\  - g\)\)\( || \^2\)\)\) with respect to one of the (Subscript[c, k])'s - say (Subscript[c, p])- with 1 ≤ p ≤ n and set the result equal to 0. 

This gives
          (∂_((Subscript[c, p])))\(\(\(\(||\)\(f\  - g\)\)\( || \^2\)\)\) =  0-2 f•(Subscript[s, p])+2 (Subscript[c, p]) (Subscript[s, p]) •(Subscript[s, p])=0.
          
 Clean this up to get
            (Subscript[c, p ])   = f•((Subscript[s, p])/((Subscript[s, p]) •(Subscript[s, p]))) 
This tells you that the minimizing (Subscript[c,  k ])' s are given by
            (Subscript[c, k ])   = f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k]))) .
          
And this says that in no uncertain terms that the function g[t] in the function space S spanned by {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, n])[t]}  closest to f[t] is
             \(TextForm\`Sclosest[
          t]\  = \ ∑\+\(k = 1\)\%n\ \ \(\(f•s\_k\/\(\(s\_k\) •s\_k\)\)\(\ \)\(s\_k[t]\)\(\ \ \)\)\)

B.4) Complete orthogonal sets of functions

B.4.a.i) Complete orthogonal families

What do folks mean when they say that a given orthogonal family is complete?

Folks say that a given orthogonal family
  
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t],  . . .}
on the interval a ≤ t ≤ b is complete if you are guaranteed that you can get great root-mean-square approximations on [a,b] of any function f[t] on [a,b] with (∫_a^b) f[t]^2 dt < Infinity via the approximations
             (∑_(k = 1)^khigh) f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k])))(Subscript[s, k])[t]
 for large khigh.


This is the same as saying that the root mean-square distance on [a,b] between 
          (∑_(k = 1)^khigh) f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k])))(Subscript[s, k])[t] and f[t] goes to 0 as khigh gets large.
In other words.
           \(\@\(∫\_a\%b\(\((∑\+\(k = 1\)\%khigh\( f•s\_k\ s\_k[t]\)\/\(s\_k\ •s\_k\) - f[t])\)\^2\) dt\) -> 
        0\) as khigh gets large.
 In this case, folks like to say that the Fourier series
            (∑_(k = 1)^∞) f•((Subscript[s, k])/((Subscript[s, k]) •(Subscript[s, k])))(Subscript[s, k])[t] 
 converges to f[t] in the sense of root-mean-square distance on the interval [a,b].

B.4.a.ii) Examples of complete orthogonal families

Give some examples of orthogonal systems that are known to be complete.

Some examples:
The Sine system on [0,π]
The Cosine system on [0,π]
The Sine -Cosine system on [-π,π]
The Sine -Cosine system on [0,2π]
The Legendre Polynomial system on [-1,1]

Proofs of the completeness of these systems are given in graduate level math courses.

B.4.a.iii) Sometimes the approximation breaks down in isolated spots

Here is a function f[t] plotted on [0, π]:

a  =  0;
b  = π;
Clear[f, t];
f[t_]  =  0.6 ( t  -  1);
fplot  =  
        Plot[f[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], Blue}}, 
          AxesLabel -> {"t", "f[t]"}];

The set of functions   
        {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t],  . . .}
for
         (Subscript[s, k])[t]  =  Sin[k t] 
is a complete orthogonal set on the interval a ≤ t ≤ b with a = 0 and b = π.
Look at these attempts to approximate f[t] in terms of these sines:

khigh  =  7;
Clear[s, k, t];
\(\(s\_k_[t_]\  := \ Sin[k\ t];\)
\)
Clear[fouriercoeff, Sclosest, k];
fouriercoeff[k_]  :=  
        NIntegrate[f[t] (Subscript[s, k])[t], {t, a, b}]/NIntegrate[(Subscript[s, k])[t] (Subscript[s, k])[t], {t, a, b}];
Sclosest[
          t_]   =  (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[
              t];
fitplot  =  
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.01], 
                CadmiumOrange}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{Blue, 
                Text["f[t]", {a  +  1, f[a  +  1]}]}, {Red, 
                Text["Sclosest[t]", {b  -  0.1, Sclosest[b - 0.1]}]}}, 
          PlotRange -> All, 
          PlotLabel -> khigh "= khigh"];

Sclosest[t]

Use more sines:

\(\(khigh\  = \ 15;\)
\)
Sclosest[
          t_]   =  (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[
              t];
fitplot  =  
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.01], 
                CadmiumOrange}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{Blue, 
                Text["f[t]", {a  +  1, f[a  +  1]}]}, {Red, 
                Text["Sclosest[t]", {b  -  0.1, Sclosest[b - 0.1]}]}}, 
          PlotRange -> All, PlotLabel -> khigh "= khigh"];
Sclosest[t]

Use a helluva lot of sines:

\(\(khigh\  = \ 100;\)
\)
Sclosest[
          t_]   =  (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[
              t];
\(\(fitplot\  = \ 
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.015], Blue}, {Thickness[0.01], 
                CadmiumOrange}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{Blue, 
                Text["f[t]", {a\  + \ 1, f[a\  + \ 1]}]}, {Red, 
                Text["Sclosest[t]", {b\  - \ 0.1, Sclosest[b - 0.1]}]}}, 
          PlotRange -> All, 
          PlotLabel -> khigh\ "= khigh"];\)
\)
Sclosest[t]

\(The\ approximation\ is\ great\ except\ at\ the\ endpoints . \ 

          Does\ this\ fly\ in\ the\ face\ of\ the\ fact\ that\)
            {Sin[t], Sin[2 t], 
              Sin[3 t], Sin[4 t], .. .} 
is a complete orthogonal family on [
            0, π]?

Not at all.
Look again:

Show[fitplot];

The root-mean-square distance between f[t] and Sclosest[t] is very small:

(Sqrt[NIntegrate])[(((f[t] - Sclosest[t]))^2), {t, a, b}]

The point here is that the root mean square distance between f[t] and Sclosest[t]
           \(\@\(∫\_a\%b\(\((f[t] - Sclosest[t])\)\^2\) dt\)\)
can be very small without having the plots of f[t] and Sclosest[t] sharing ink the whole way across the interval. 
But when the root mean square distance between f[t] and Sclosest[t]
           \(\@\(∫\_a\%b\(\((f[t] - Sclosest[t])\)\^2\) dt\)\)
 is very small ,  
 the plots of f[t] and Sclosest[t] do have to share lots of ink except at some at some isolated parts of [a,b].

B.5) Linear independence and linear dependence for sets of functions
Orthogonal families are guaranteed to be linearly independent.
The determinant test for linear independence or linear dependence

B.5.a.i)  Definitions of linear independence and linear dependence for sets of functions

What do folks mean when they say that a given set of functions is linearly independent?
What do the same folks mean when they say that a given set of functions is linearly dependent?

Here's the inside scoop:
▪ A set of functions { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t], . . .,(Subscript[f, n])[t]} is linearly independent on an interval [a,b] if none of the functions in this set are in the function space spanned by the others.

▪ A set of functions { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t], . . .,(Subscript[f, n])[t]} is linearly dependent on an interval [a,b] at least one of functions in this set are in the function space spanned by the others.

B.5.a.ii) Orthogonal families are linearly independent

A given set of non-zero functions 
         {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t]}
defined on an interval [a,b] are orthogonal (mutually perpendicular) on [a,b] 
if
       (Subscript[s, p]) • (Subscript[s, q]) = (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt = 0     when p ≠ q.
and
         (∫_a^b) (Subscript[s, p])[t]^2 dt > 0 for all the p's.
Explain this:
If {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t]} are orthogonal on [a,b], then {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t]} is linearly independent on [a,b].

This will be an explanation by contradiction.
Assume {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], . . ., 
        (Subscript[s, k])[t]} are orthogonal on [a,b] but not linearly independent on [a,b]. 

This tells you that one of the functions is in the function space spanned by the others, Relabel the set so that this one function is (Subscript[s, 1])[t]. And because (Subscript[s, 1])[t]. is in the function space spanned by the others, you know that

(Subscript[s, 1])[t]. = (∑_(j = 2)^k) (Subscript[c, j]) (Subscript[s, j])[t]. for certain numbers {(Subscript[c, 2]), (Subscript[c, 3]), . . ., (Subscript[c, k])}.

Multiply through by (Subscript[s, 1])[t]. to get

(Subscript[s, 1])[t]^2. = (∑_(j  =  2)^k) (Subscript[c, j]) (Subscript[s, 1])[t] .  (Subscript[s, j])[t].

Integrate from a to b to get:

(∫_a^b) (Subscript[s, 1])[t]^2 dt = (∑_(j  =  2)^k) (Subscript[c, j]) (∫_a^b) (Subscript[s, 1])[t]  (Subscript[s, j])[
                t] dt

This gives

(∫_a^b) (Subscript[s, 1])[t]^2 dt = (∑_(j  =  2)^k) (Subscript[c, j]) 0  = 0.

because  (Subscript[s, p]) • (Subscript[s, q]) = (∫_a^b) (Subscript[s, p])[t] (Subscript[s, q])[t] dt = 0     when p ≠ q.

This leads to the conclusion that (∫_a^b) (Subscript[s, 1])[t]^2 dt = 0, which is a contradiction because
                (∫_a^b) (Subscript[s, p])[t]^2 dt > 0 for all the p's.

B.5.b.i)  The determinant test for linear independence or dependence

What is the determinant test for linear independence and linear dependence?
And how do you use it?

▪Saying a set of three functions { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t]} is linearly dependent on an interval [a,b] is the same as saying

Det[ (({{(Subscript[f, 1])[(Subscript[t, 1])], (Subscript[f, 2])[(Subscript[t, 1])], (Subscript[f, 3])[(Subscript[t, 1])]}, {(Subscript[f, 1])[(Subscript[t, 2])], (Subscript[f, 2])[(Subscript[t, 2])], (Subscript[f, 3])[(Subscript[t, 2])]}, {(Subscript[f, 1])[(Subscript[t, 3])], (Subscript[f, 2])[(Subscript[t, 3])], (Subscript[f, 3])[(Subscript[t, 3])]}}))] = 0 no matter what (Subscript[t, 1]),(Subscript[t, 2]) and (Subscript[t, 3]) in [a,b] are.

▪Saying a set of three functions { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t]} is linearly independent on an interval [a,b] is the same as saying

Det[ (({{(Subscript[f, 1])[(Subscript[t, 1])], (Subscript[f, 2])[(Subscript[t, 1])], (Subscript[f, 3])[(Subscript[t, 1])]}, {(Subscript[f, 1])[(Subscript[t, 2])], (Subscript[f, 2])[(Subscript[t, 2])], (Subscript[f, 3])[(Subscript[t, 2])]}, {(Subscript[f, 1])[(Subscript[t, 3])], (Subscript[f, 2])[(Subscript[t, 3])], (Subscript[f, 3])[(Subscript[t, 3])]}}))] ≠ 0 for at least one choice of (Subscript[t, 1]),(Subscript[t, 2]) and (Subscript[t, 3]) in [a,b].

Here's how you use it  on the sample case
            { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t]} ={(e^t),(e^(-t)),Sinh[t]} on [a,b] = [-2,2]

Make the test matrix:

Clear[s, f, Subscript, k, t];
{(Subscript[f, 1])[t_], (Subscript[f, 2])[t_], (Subscript[f, 3])[t_]}={(E^t),(E^(-t)),Sinh[t]};
testmatrix = 
        Table[(Subscript[f, j])[(Subscript[t, i])], {i, 1, 3}, {j, 1, 
            3}];
MatrixForm[
      testmatrix]

Evaluate the determinant of the test matrix at some random selections of (Subscript[t, 1]),(Subscript[t, 2]) and (Subscript[t, 3]) in [-2,2]:

{a, b}  =  {-2, 2};
Det[testmatrix]/.{(Subscript[t, 1])->Random[Real, {a, b}],(Subscript[t, 2])->Random[Real, {a, b}],(Subscript[t, 3])->Random[Real, {a, b}]}

Zero every time.
All indications are that { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t]} is a linearly dependent set.

Give it the acid test by calculating Det[testmatrix] and letting Mathematica try to simplify:

Simplify[Det[testmatrix]]

Zero.
The call:      
          { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t]} ={(e^t),(e^(-t)),Sinh[t]}: is linearly dependent on any interval [a,b].

Here's how you use it  on the sample case
            { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t]} ={(e^t),t,(e^(-t))} and [a,b] = [-1,1]

Make the test matrix:

Clear[s, f, Subscript, k, t];
{(Subscript[f, 1])[t_], (Subscript[f, 2])[t_], (Subscript[f, 3])[t_]}={(E^t),(t^2),(E^(-t))};
testmatrix = 
        Table[(Subscript[f, j])[(Subscript[t, i])], {i, 1, 3}, {j, 1, 
            3}];
MatrixForm[
      testmatrix]

Evaluate the determinant of the test matrix at some random selections of (Subscript[t, 1]),(Subscript[t, 2]) and (Subscript[t, 3]) in [-1,1]:

{a, b}  =  {-1, 1};
Det[testmatrix]/.{(Subscript[t, 1])->Random[Real, {a, b}],(Subscript[t, 2])->Random[Real, {a, b}],(Subscript[t, 3])->Random[Real, {a, b}]}

Not zero.  
The call:    
          { (Subscript[f, 1])[t],(Subscript[f, 2])[t],(Subscript[f, 3])[t]} ={(e^t),(t^2),(e^(-t))}: is linearly independent on any interval [a,b] that contains [-1,1].

B.5.b.ii)  The determinant test works for families of two or more functions

Does the determinant test for linear dependence or independence work for sets of functions with any number of  members?

You betcha!

▪ Here's how you use it  on the sample case
            { (Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t]} ={Sin[t], t, (t^3),(t^5)} on [a,b] = [0, 2 π]:

Make the test matrix:

Clear[s, f, Subscript, k, t];
{(Subscript[f, 1])[t_], (Subscript[f, 2])[t_], (Subscript[f, 3])[t_], (Subscript[f, 4])[t_]}={Sin[t],t,(t^3),(t^5)};
testmatrix=Table[(Subscript[f, j])[(Subscript[t, i])],{i,1,4},{j,1,4}];
MatrixForm[testmatrix]

Evaluate the determinant of the test matrix at some random selections of (Subscript[t, 1]),(Subscript[t, 2]) (Subscript[t, 3])and (Subscript[t, 4]) in  [0, 2 π]:

{a, b}  =  {0, 2 π};
Det[testmatrix]/.{(Subscript[t, 1])->Random[Real, {a, b}],(Subscript[t, 2])->Random[Real, {a, b}],(Subscript[t, 3])->Random[Real, {a, b}],(Subscript[t, 4])->Random[Real, {a, b}]}

Not zero. 
The call:     
          {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t]}={Sin[t],t,(t^3),(t^5)}: is linearly independent on any interval [a,b] containing  [0, 2 π].
          .

▪ Here's how you use it  on the sample case
            { (Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t], (Subscript[f, 6])[t]} ={1,Cos[t],Cos[2 t],Cos[3 t],Cos[4 t], Cos[t]^4} on [a,b] = [0, 2 π]:

Make the test matrix:

Clear[s, f, Subscript, k, t];
{(Subscript[f, 1])[t_],(Subscript[f, 2])[t_],(Subscript[f, 3])[t_],(Subscript[f, 4])[t_],(Subscript[f, 5])[t_],(Subscript[f, 6])[t_]}={1,Cos[t],Cos[2 t],Cos[3 t],Cos[4 t], Cos[t]^4};
testmatrix=Table[(Subscript[f, j])[(Subscript[t, i])],{i,1,6},{j,1,6}];
MatrixForm[testmatrix]

Evaluate the determinant of the test matrix at some random selections of (Subscript[t, 1]),(Subscript[t, 2]) (Subscript[t, 3]),(Subscript[t, 4]),(Subscript[t, 5]) and (Subscript[t, 6]) in  [0, 2 π]:

{a, b}  =  {0, 2 π};
Det[testmatrix]/.{(Subscript[t, 1])->Random[Real, {a, b}],(Subscript[t, 2])->Random[Real, {a, b}],(Subscript[t, 3])->Random[Real, {a, b}],(Subscript[t, 4])->Random[Real, {a, b}],(Subscript[t, 5])->Random[Real, {a, b}],(Subscript[t, 6])->Random[Real, {a, b}]}

Zero every time.
All indications are that { (Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t], (Subscript[f, 6])[t]} is a linearly dependent set.

Give it the acid test by calculating Det[testmatrix] and letting Mathematica try to simplify:

Simplify[Det[testmatrix]]

Zero.
The call:

{ (Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t], (Subscript[f, 6])[t]} ={1,Cos[t],Cos[2 t],Cos[3 t],Cos[4 t], Cos[t]^4}

is linearly dependent on any interval [a,b].

B.5.b.iii) Finding the explicit dependence

Go with  {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t], (Subscript[f, 6])[t]}={Sin[t],Sin[2 t],Sin[3 t],Sin[4 t],Sin[5 t],((Sin[t])^5)} and make the test matrix:

Clear[s, f, Subscript, k, t];
{(Subscript[f, 1])[t_],(Subscript[f, 2])[t_],(Subscript[f, 3])[t_],(Subscript[f, 4])[t_],(Subscript[f, 5])[t_],(Subscript[f, 6])[t_]}={Sin[t],Sin[2 t],Sin[3 t],Sin[4 t],Sin[5 t],((Sin[t])^5)};
testmatrix=Table[(Subscript[f, j])[(Subscript[t, i])],{i,1,6},{j,1,6}];
MatrixForm[testmatrix]

The determinant of the test matrix is

Simplify[Det[testmatrix]]

Zero.
This tells you that

{(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t], (Subscript[f, 6])[t]}={Sin[t],Sin[2 t],Sin[3 t],Sin[4 t],Sin[5 t],((Sin[t])^5)}

is linearly dependent on any interval [a,b].

How do you determine the functions in {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t], (Subscript[f, 6])[t]} that are in the function spaces determined by the others?

Fairly easily. 
At this stage you know that the determinant of the test matrix is 0 for any and all choices of (Subscript[t, 1]),(Subscript[t, 2]),(Subscript[t, 3]),(Subscript[t, 4]),(Subscript[t, 5]) and (Subscript[t, 6]).
When you replace  (Subscript[t, 1]),(Subscript[t, 2]),(Subscript[t, 3]),(Subscript[t, 4]),(Subscript[t, 5]) with random numbers and replace  (Subscript[t, 6]) with t, you are guaranteed the resulting determinant is 0 for all t.

{a, b}  =  {0, 2 π};
Clear[
      t]
result =(Det[testmatrix]/.{(Subscript[t, 1])->Random[Real, {a, b}],(Subscript[t, 2])->Random[Real, {a, b}],(Subscript[t, 3])->Random[Real, {a, b}],(Subscript[t, 4])->Random[Real, {a, b}],(Subscript[t, 5])->Random[Real, {a, b}],(Subscript[t, 6])->t})

Knowing that this is 0 for all t, you can see at a glance that
▪  Sin[t]^5 is in the function space determined by the others.
▪  Sin[t] is in the function space determined by the others.
▪  Sin[3  t] is in the function space determined by the others.
▪  Sin[5  t] is in the function space determined by the others.

If this makes no sense to you, click on the right.

To see why Sin[t]^5 is in the function space determined by the others,take the coefficient of Sin[t]^5:

Coefficient[result, Sin[t]^5]

Divide everything by this coefficient:

Expand[(1/Coefficient)[result, Sin[t]^5] result]

Knowing that this is 0 for all t, you see that
                  Sin[t]^5 = 0.6250000000000048` Sin[t] - 0.3124999999999997` Sin[3 t] + 
        0.06250000000000053` Sin[5 t]
for all t., confirming that Sin[t]^5 is in the function space spanned by the others.

B.5.b.iv) Why the determinant test works

Two functions:

Here's why it works for two functions{f[t],g[t]} on an interval [a,b]:

If  Det[(({{f[x], g[x]}, {f[y], g[y]}}))] ≠ 0 for some x and y in [a,b], then (({{f[x], g[x]}, {f[y], g[y]}})) is of full rank; so neither function is a multiple of the other. This is enough to proclaim that {f[t],g[t]} is linearly independent on any interval including [a,b].

On the other hand, if  Det[(({{f[x], g[x]}, {f[y], g[y]}}))] = 0 for some x and y in [a,b], then you can solve:

Clear[f, g, x, y];
Solve[Det[(({{f[x], g[x]}, {f[y], g[y]}}))]==0,f[y]]

The upshot :
If there is an x with g[x]≠ 0,  plug in this x to see

f[y] = ((f[x] )/g)[x]g[y]

as a definite multiple (((f[x] )/g)[x]) of g[y] for all y's in [a,b]. This tells you that the set consisting of these two functions is a linearly independent set. 
This tells you that   for all y's in [a,b] with the result that {f[t],g[t]} is linearly dependent.

On the other hand, if g[x] = 0 for all x's in [a,b], then {f[t],g[t]} is automatically linearly dependent..

Three functions:

Here's why it works for three functions{f[t],g[t],h[t]} on an interval [a,b]:

If  Det[(({{f[x], g[x], h[x]}, {f[y], g[y], h[y]}, {f[z], g[z], h[z]}}))] ≠ 0 for some x, y and z in [a,b], then (({{f[x], g[x], h[x]}, {f[y], g[y], h[y]}, {f[z], g[z], h[z]}})) is of full rank; so neither This rules out the possibilities that one of the functions is in the function space spanned by the others. This signals that {f[t],g[t],h[t]} is linearly independent on [a.b] (and on any interval containing [a,b]).

On the other hand, if  Det[(({{f[x], g[x], h[x]}, {f[y], g[y], h[y]}, {f[z], g[z], h[z]}}))] = 0 for all x, y  and z in [a,b], then you can solve:

Clear[f, g, h, x, y, z]
Simplify[Solve[Det[(({{f[x], g[x], h[x]}, {f[y], g[y], h[y]}, {f[z], g[z], h[z]}}))]==0,f[z]]]

This says

f[z]=((f[y]  g[z]  h[x] - f[x]  g[z]  h[y] - f[y]  g[x]  h[z] + f[x]  g[y]  h[z] )/(g[y] h[x] - 
              g[x] h[y]))
for all x,y and z in [a,b].

This is the same as

f[z] = ( ((f[y]   h[x]   -   f[x]    h[
                  y] )/(g[y] h[x]  -  g[x] h[y]))) g[z]  + (((- f[y]  g[x]   +   f[x]  g[y])/(g[y] h[
                  x]  -  g[x] h[y])) ) h[z].
for all x,y and z in [a,b].

The upshot :
If there are x and y with 
               g[y] h[x] - g[x] h[y] ≠  0, 
you can plug in this choice of x and y to write f[z] s an explicit linear combination of g[z] and h[z] with the result that  f[t] is in the function space spanned by g[t] and h[t]. This signals that {f[t],g[t],h[t]}  is linearly dependent on [a,b]

On the other hand if

g[y] h[x] - g[x] h[y] = Det[(({{g[y], h[y]}, {g[x], h[x]}}))]  =  0

for all y and z in [a,b] then the two function case tells you {g[t],h[t]} is linearly dependent on [a,b] and so {f[t],g[t],h[t]} is linearly dependent as well.

More than three functions

It is possible to extend the explanation given above to more than 3 functions via Mathematical Induction.
Math mavens should think about this.

B.6) The Gram-Schmidt Process: Just the ticket for dealing with function spaces spanned by non-orthogonal sets of functions

B.6.a.i) Function spaces spanned ny non-orthogonal families

Given a set of functions 
	           {(Subscript[f, 1])[t], (Subscript[f, 2])[t], 
          (Subscript[f, 3])[t], ....(Subscript[f, k])[t]} 
on an interval [a, b],  
      you make the function space S[a, b] spanned by
              \({f\_1[t], f\_2[t], 
                f\_3[t], \(\(...\)\(.\)\(f\_k[t]\)\)} . 

              This\ function\ space\ S[a, b]\ consists\ of\ all\ functions\ s[
              t]\ of\ the\ form . 
\ \ \ \ \ \ \ \ \ \ \ s[t]\)=(∑_(j = 1)^k) (Subscript[c, j]) (Subscript[f, j])[t]  with  a≤t≤b.
One good example is the function space S[-1, 1] of all fourth degree polynomials \(on\ [\(-1\), 1] . \ 
You\) get this by going with
        {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], 
                        (Subscript[f, 5])[t]}  =  {1, t, (t^2), (t^3), (t^4)}.
See a random member of this function space:

Clear[f, Subscript, k, t];
(Subscript[f, 1])[t_] = 1;
(Subscript[f, 2])[t_] = t;
(Subscript[f, 3])[t_] = (t^2);
(Subscript[f, 4])[t_] = (t^3);
(Subscript[f, 5])[t_] = (t^4);
a = -1;
b = 1;
(Subscript[c, k])_ := Random[Real, {-2, 2}]
s[t_] = (∑_(k = 1)^5) (Subscript[c, k]) (Subscript[f, k])[t]

And its plot:

Plot[s[t], {t, a, b}, PlotStyle -> {{Thickness[0.01], NavyBlue}}, 
        AxesLabel -> {"t", "f[t]"}, 
        AspectRatio -> 1/GoldenRatio];

Now look at this:

(∫_a^b) (Subscript[f, 2])[t] (Subscript[f, 4])[t] \[DifferentialD]t

Interpret the result.

Look again:

(∫_a^b) (Subscript[f, 2])[t] (Subscript[f, 4])[t] \[DifferentialD]t

This tells you that 
             \(\(f\_2\) •\ f\_4\ \  = \ ∫\_a\%b f\_2[t]\ f\_4[t] dt\ \  ≠ \ 0. \)
The interpretation :  The given family
          {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], 
            (Subscript[f, 5])[t]}  =  {1, t, (t^2), (t^3), (t^4)} 
is not orthogonal on [a, b] = [-1, 1]

B.6.a.ii) Using Gram-Schmidt to get an orthogonal spanning set

Come up with an orthogonal family
            {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], 
        (Subscript[s, 5])[t]} on [a,b] 
 so that function space spanned by
            {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], 
        (Subscript[s, 5])[t]}   
 is the same as the function space spanned by
            {(Subscript[f, 1])[t], (Subscript[f, 2])[t],  (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}  =  {1, 
          t, (t^2), (t^3), (t^4)}

\(TextForm\`Apply\ something\ called\ the\ Gram - \(\(Schmidt\)\(\ \)\(process\)\(\ \)\(to\)\(\ \)\(\({f\_1[t], f\_2[t], \ f\_3[t], f\_4[t], 
            f\_5[t]}\)\(\ \)\(:\)\)\(
\)\(		\)\)\)

orthospanners = 
      GramSchmidt[{(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}, 
        InnerProduct -> ((∫_a^b) #1 #2 \[DifferentialD]t &)]

Put:

(Subscript[s, j])_[t_]  :=  orthospanners[[j]];
ColumnForm[Table[(Subscript[s, j])[t], {j, 1, Length[orthospanners]}]]

See this orthogonal family:

Plot[{(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t]}, {t, a, b}, 
        PlotStyle -> {{Thickness[0.02], 
              RGBColor[0.8, 0, 0]}, {Thickness[0.02], 
              RGBColor[0.7, 0.5, 0]}, {Thickness[0.02], 
              RGBColor[0.5, 1, 0]}, {Thickness[0.02], 
              RGBColor[0.2, 0.5, 0.5]}, {Thickness[0.02], 
              RGBColor[0, 1, 0.5]}}, 
        AxesLabel -> {"t", ""}];

The function space spanned by
            {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], (Subscript[s, 5])[t]}   
 \(is\ guaranteed\ to\ be\ the\ same\ as\ the\ function\ space\ spanned\ by\)
            {(Subscript[f, 1])[t], (Subscript[f, 2])[t],  (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}  =  {1, 
              t, (t^2), (t^3), (t^4)}

Gram-Schmidt Step 1:

Put (Subscript[g, 1])[t] = (Subscript[f, 1])[t]. 
:

Clear[g, s, t];
(Subscript[g, 1])[t_]  =  (Subscript[f, 1])[t]

Gram-Schmidt  Step 2:

Put 
      (Subscript[g, 2])[t] = 
        (Subscript[f, 2])[t] - (component of (Subscript[f, 2])[t] in the direction of (Subscript[g, 1])[
                t]).

(Subscript[g, 2])[t_]  =  
      (Subscript[f, 2])[t]  -  (((∫_a^b) (Subscript[f, 2])[t] (Subscript[g, 1])[t] \[DifferentialD]t)/((∫_a^b) (Subscript[g, 1])[t] (Subscript[g, 1])[t] \[DifferentialD]t))  (Subscript[g, 1])[t]

Gram-Schmidt Step 3:

Put 
      (Subscript[g, 3])[
          t] = (Subscript[f, 3])[
            t]- component of (Subscript[f, 3])[
              t] in the direction of (Subscript[g, 1])[t]-  .
                               - component of (Subscript[f, 3])[t] in the direction of (Subscript[g, 2])[
          t]

(Subscript[g, 3])[t_]  =  
      (Subscript[f, 3])[t]  -  (((∫_a^b) (Subscript[f, 3])[t] (Subscript[g, 1])[t] \[DifferentialD]t)/((∫_a^b) (Subscript[g, 1])[t] (Subscript[g, 1])[t] \[DifferentialD]t))  (Subscript[g, 1])[
            t]   -  (((∫_a^b) (Subscript[f, 3])[t] (Subscript[g, 2])[t] \[DifferentialD]t)/((∫_a^b) (Subscript[g, 2])[t] (Subscript[g, 2])[t] \[DifferentialD]t))  (Subscript[g, 2])[
            t]

Gram-Schmidt Step 4:

Put 
      (Subscript[g, 4])[t] = 
        (Subscript[f, 4])[t] -  (∑_(j = 1)^3) 
              component of (Subscript[f, 4])[t] in the direction of (Subscript[g, j])[t].

(Subscript[g, 4])[t_] = 
      (Subscript[f, 4])[t] - (∑_(j = 1)^3)((((∫_a^b) (Subscript[f, 4])[t] (Subscript[g, j])[t] \[DifferentialD]t)/((∫_a^b) (Subscript[g, j])[t] (Subscript[g, j])[t] \[DifferentialD]t)) (Subscript[g, j])[t])

Gram-Schmidt Step 5:

Put 
      (Subscript[g, 5])[t] = 
        (Subscript[f, 5])[t] -  (∑_(j = 1)^4) 
              component of (Subscript[f, 5])[t] in the direction of (Subscript[g, j])[t].

(Subscript[g, 5])[t_] = 
      (Subscript[f, 5])[t] - (∑_(j = 1)^4)((((∫_a^b) (Subscript[f, 5])[t] (Subscript[g, j])[t] \[DifferentialD]t)/((∫_a^b) (Subscript[g, j])[t] (Subscript[g, j])[t] \[DifferentialD]t)) (Subscript[g, j])[t])

Now you stop because you have used the whole family {(Subscript[f, 1])[t], (Subscript[f, 2])[t],  (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}  =  {1, 
          t, (t^2), (t^3), (t^4)}.
By its construction: 
-> The new family {(Subscript[g, 1])[t], (Subscript[g, 2])[t], (Subscript[g, 3])[t], (Subscript[g, 4])[t], 
        (Subscript[g, 5])[t]}   determines the same function space S[a,b] as the original family {(Subscript[f, 1])[t], (Subscript[f, 2])[t],  (Subscript[f, 3])[t], (Subscript[f, 4])[t], 
        (Subscript[f, 5])[t]} .
-> The new family {(Subscript[g, 1])[t], (Subscript[g, 2])[t], (Subscript[g, 3])[t], (Subscript[g, 4])[t], 
        (Subscript[g, 5])[t]}   is orthogonal on [a,b]. 
Spot check:

q  =  Random[Integer, {1, 3}];
p  = Random[Integer, {q  +  1, 5}];
 Integrate[(Subscript[g, q])[t] (Subscript[g, p])[t], {t, a, b}]

Now finish it off by setting
            (Subscript[s, j])[t] =(Subscript[g, j])[t]/(Sqrt[(Subscript[g, j]) •(Subscript[g, j])]):

(Subscript[s, j])_[
        t_]  :=   (Subscript[g, j])[t]/(Sqrt[(∫_a^b) (Subscript[g, j])[t] (Subscript[g, j])[t] \[DifferentialD]t])

Table[(Subscript[s, j])[t], {j, 1, 5}]

Compare:

\(GramSchmidt[{f\_1[t], f\_2[t], \ f\_3[t], f\_4[t], f\_5[t]}, 
      InnerProduct\  -> 
\ \ \ \ \ \((Integrate[#1\ #2, {t, a, 
                b}] &)\)]\)

That's it.

B.6.a.iii) Using Gram-Schmidt to come up with root-mean-square approximations

Come up with the best root-mean-square approximation on [-1 ,1] of f[t] = (e^t) by a fourth degree polynomial.

This is the same as going with the function space S[-1,1] spanned by
           {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}  =  {1, t, 
          (t^2), (t^3), (t^4)}
 and asking for the function  
         Sclosest[t] = (∑_(k = 1)^5) (Subscript[c, k]) (Subscript[f, k])[t] 
that is closest to
         f[t] = (e^t) 
 with respect to root-mean-square distance on [-1,1].
 
Thanks to the work in the last part, you know that the family
          {(Subscript[s, 1])[t], (Subscript[s, 2])[t], (Subscript[s, 3])[t], (Subscript[s, 4])[t], 
        (Subscript[s, 5])[t]}   
 resulting from running Gram-Schmidt on
           {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}  
  is orthogonal on [-1,1] and spans the same function space as the original family 
         {(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}  =  {1, t, 
          (t^2), (t^3), (t^4)}.

khigh = 5;
Clear[s, f, Subscript, k, t];
(Subscript[f, k])_[t_] = (t^(k - 1));
a = -1;
b = 1;
orthospanners = 
        GramSchmidt[{(Subscript[f, 1])[t], (Subscript[f, 2])[t], (Subscript[f, 3])[t], (Subscript[f, 4])[t], (Subscript[f, 5])[t]}, 
          InnerProduct -> ((∫_a^b) #1 #2 \[DifferentialD]t &)];
(Subscript[s, j])_[t_] := 
        orthospanners[[j]];
Table[(Subscript[s, j])[t], {j, 1, Length[orthospanners]}]

So the question reduces to finding the function of the form
and asking for the function  
         Sclosest[t] = (∑_(k = 1)^5) (Subscript[c, k]) (Subscript[s, k])[t] 
that is closest to
         f[t] = (e^t) 
 with respect to root-mean-square distance on [-1,1].
 And this is easy. 
 The function you are after is:

khigh = 5;
Clear[f, t];
f[t_] = (E^t);
Clear[fouriercoeff, Sclosest];
fouriercoeff[k_] := fouriercoeff[k] = 
          NIntegrate[f[t] (Subscript[s, k])[t], {t, a, b}]/NIntegrate[(Subscript[s, k])[t] (Subscript[s, k])[t], {t, a, b}];
Sclosest[
        t_] = (∑_(k = 1)^khigh) fouriercoeff[k] (Subscript[s, k])[t]

Multiply it out:

Expand[Sclosest[t]]

See the quality of the approximation:

fitplot  =  
        Plot[{f[t], Sclosest[t]}, {t, a, b}, 
          PlotStyle -> {{Thickness[0.03], NavyBlue}, {Thickness[0.01], 
                Gold}}, AxesLabel -> {"t", ""}, 
          Epilog -> {{NavyBlue, 
                Text["f[t]", {a  +  0.5, f[a  +  0.5]}]}, {Gold, 
                Text["Sclosest[t]", {b  -  0.5, 
                    Sclosest[b - 0.5]}]}}];

Copacetic.