MGM.08 Subspaces, Spans , Dimension, Linear Independence, Basis, Orthonormal Bases
 BASICS

Needs["LinearAlgebra`MatrixManipulation`"];
Needs["LinearAlgebra`Orthogonalization`"];
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) Subspaces,  spanning sets.
The SpannerMatrix for a given spanning set {spanner[1], spanner[2], . . . , spanner[n]} is                       
SpannerMatrix =   (({{spanner[1], spanner[2], ..., spanner[n]}, {↓, ↓, ..., ↓}})).

The subspace spanned by a given spanning set consists exactly of the vectors that are hits with the SpannerMatrix.
The dimension of a subspace spanned by a given spanning set is the rank of the  SpannerMatrix.

B.1.a.i) Subspaces defined by spanning sets

To get a line through {0, 0, 0} in 3D, you  go with one direction vector such as:

Clear[s, spanner];
spanner[1] = {1.43, -0.5, 1.2}

And then you make the line by taking all multiples of this vector.
Here's a piece of it:

Clear[s, 
        spanner];
spanner[1] = {1.43, -0.5, 1.2};
h = 3;

Clear[s];
lineplot=ParametricPlot3D[s spanner[1],{s, -h, h},PlotPoints -> 2,DisplayFunction -> Identity];

linepiece = 
        Show[lineplot, ThreeAxes[2], ViewPoint -> CMView, 
          PlotRange -> All, Axes -> True, 
          AxesLabel -> {"x", "y", "z"}, Boxed -> False, 
          PlotLabel -> "Piece of line", 
          DisplayFunction -> $DisplayFunction];

Folks say that the specified vector spans the line because you can get to any point on the line by advancing on a multiple of the given vector:

s = Random[Real, {-h, h}];
\(\(linepoint = s\ spanner[1];\)
\)
\(\(pointplot = 
        Graphics3D[{Blue, PointSize[0.025], Point[linepoint]}];\)
\)
\(\(pointspannerplot = 
        Arrow[s\ spanner[1], Tail -> {0, 0, 0}, 
          VectorColor -> CadmiumOrange];\)
\)
Show[linepiece, pointplot, pointspannerplot, 
        ViewPoint -> CMView, PlotRange -> All, Axes -> True, 
        AxesLabel -> {"x", "y", "z"}, Boxed -> False, 
        PlotLabel -> "Piece of line", 
        DisplayFunction -> $DisplayFunction];

To get a plane through {0,0,0} in 3D, you just go with two vectors such as:

Clear[s, spanner, i];
spanner[1] = {1.43, -0.5, 1.2};
spanner[2] = {-0.9, 0.0, 1.5};
\(\(spanners = Table[spanner[i], {i, 1, 2}];\)
\)
ColumnForm[spanners]

And then you make the plane by taking all combinations  
       s spanner[1] + t spanner[2] 
of multiples of these two vectors:

h = 5;
k = 4;
Clear[s, t];
planeplot=ParametricPlot3D[s spanner[1]+t spanner[2],{s, -h, h},{t, -k, k},PlotPoints -> {2, 2},DisplayFunction -> Identity];

spannerplot = {Arrow[1.3 h spanner[1], 
              Tail -> {0, 0, 0}, VectorColor -> Red], 
            Arrow[1.3 k spanner[2], Tail -> {0, 0, 0}, 
              VectorColor -> Red]};

spannerlabels = {Graphics3D[
              Text["spanner[1]", 0.9 h spanner[1]]], 
            Graphics3D[Text["spanner[2]", 0.9 k spanner[2]]]};

planepiece = 
        Show[planeplot, spannerplot, spannerlabels, ThreeAxes[10], 
          ViewPoint -> CMView, PlotRange -> All, Axes -> True, 
          AxesLabel -> {"x", "y", "z"}, Boxed -> False, 
          PlotLabel -> "Piece of plane", 
          DisplayFunction -> $DisplayFunction];

Folks say that the two specified vectors span the plane because you can get to any point on the plane by advancing on a multiple of spanner[1] and then advancing on a multiple of spanner[2].
See it happen for some random points on this plane:

s = Random[Real, {-h, h}];
t = Random[Real, {-k, k}];
\(\(planepoint = s\ spanner[1] + t\ spanner[2];\)
\)
\(\(pointplot = 
        Graphics3D[{Blue, PointSize[0.035], 
            Point[planepoint]}];\)
\)
\(\(pointspannerplot = {Arrow[s\ spanner[1], Tail -> {0, 0, 0}, 
            VectorColor -> Red], 
          Arrow[t\ spanner[2], Tail -> s\ spanner[1], 
            VectorColor -> Red]};\)
\)
Show[planepiece, pointplot, pointspannerplot, 
        ViewPoint -> CMView, PlotRange -> All, Axes -> True, 
        AxesLabel -> {"x", "y", "z"}, Boxed -> False, 
        PlotLabel -> "Piece of plane", 
        DisplayFunction -> $DisplayFunction];

Once you see how to make lines and planes with spanning vectors in 3D, you can make the jump to working with the analogs of planes and lines in higher dimensions. Most folks call these higher dimensional analogs by the name "subspaces."

Here are three vectors in 4D:

Clear[s, i, spanner];
spanner[1] = {3.43, -0.57, 8.19, -0.94};
spanner[2] = {0.97, 1.29, 0.83, 5.23};
spanner[3] = {-6.14, 3.08, -5.00, -1.97};
spanners = Table[spanner[i], {i, 1, 3}]

When folks talk about the subspace of 4D spanned by these three vectors, they are talking about the whole collection of all vectors expressible as a combination
         x[1] spanner[1]+x[2] spanner[2]+x[3] spanner[3]
where {x[1], x[2], x[3]} range over all real numbers:

Clear[x, k];
(∑_(k = 1)^(Length[spanners]))x[k] spanner[k]

Here are some random members of this subspace:

a = 8;
Clear[x];
x[i_] := 
        Random[Real, {-a, a}];
(∑_(k = 1)^(Length[spanners]))x[k] spanner[k]

What's a good way of describing the vectors in this subspace?

The vectors in this subspace of 4D look like this
       x[1] spanner[1] + x[2] spanner[2] + x[3] spanner[3].
These can be described as the 4D destinations of all three-stage trips made by
1) going at first on a straight line segment from {0, 0, 0, 0} in the direction of spanner[1], 
2) then stopping and switching directions by going on a straight line segment in the direction of spanner[2],
3) then stopping and switching directions by going on a straight line segment in the direction of spanner[3].
The size of the coefficients x[i] indicate the length of the trip at the ith stage.

B.1.a.ii) The spanner matrix for a given spanning set {spanner[1],spanner[2], , , ,spanner[n]}
is    (({{spanner[1], spanner[2], ..., spanner[n]}, {↓, ↓, ..., ↓}})).
The subspace spanned by {spanner[1],spanner[2], , , ,spanner[n]} consists exactly of the vectors that are hits with this matrix

Stay with the same subspace as in part i) immediately above spanned by the vectors:

spanners  =  {spanner[1], spanner[2], spanner[3]}

and look at this associated spanner matrix
             SpannerMatrix  = (({{spanner[1], spanner[2], spanner[3]}, {↓, ↓, ↓}})):

SpannerMatrix=Transpose[spanners];
MatrixForm[
      SpannerMatrix]

How are the vectors in the subspace S of 4D spanned by
      spanner[1], spanner[2] and spanner[3] 
related to hits with the  associated spanner matrix?

The subspace S of 4D spanned by
      spanner[1], spanner[2] and spanner[3] 
consists exactly of the vectors that are hits with the SpannerMatrix.

Reason:
Hits with SpannerMatrix look like this:
                  SpannerMatrix.{x[1],x[2],x[3]}

=   (({{spanner[1], spanner[2], spanner[3]}, {↓, ↓, ↓}})).{x[1],x[2],x[3]}

=  x[1] spanner[1] + x[2] spanner[2] + x[3] spanner[3] 
                   
where x[1], x[2] and x[3] are real numbers.

The vectors in the subspace of 4D spanned by spanner[1], spanner[2] and spanner[3] look like this:  
                          x[1] spanner[1] + x[2] spanner[2] + x[3] spanner[3] 
                   
where x[1], x[2] and x[3] are real numbers.

This is a big break in your favor because the spanner matrix is the key to working with subspaces.

B.1.b.i) The rank of the spanner matrix is the dimension of the corresponding subspace

Here are five vectors in 5D:

Clear[i, spanner];
spanner[1] = {3.43, -0.57, 2.19, -0.94, 1.28};
spanner[2] = {0.97, 1.29, 0.83, 5.23, 1.26};
spanner[3] = {-6.14, 
          3.08, -5.00, -1.97, -0.96};
spanner[4] = {-3.68, 
          1.22, -3.64, -8.14, -0.94};
spanner[5] = {2.71, -2.51, 2.81, 2.91, -0.32};
spanners = Table[spanner[i], {i, 1, 5}]

These vectors span a subspace S of 5D. 
Make the associated spanner matrix for this subspace S:

SpannerMatrix = Transpose[spanners];
MatrixForm[SpannerMatrix]

The subspace S is the same as all possible hits with this spanner matrix.
Check the rank of this spanner matrix:

rank=Length[SingularValues[SpannerMatrix][[2]]]

Why do folks say that because the rank of the SpannerMatrix is 3, the dimension of the subspace S is 3?

The rank of the spanner matrix is 3. 
This means the Spanner Matrix needs a perpendicular frame
consisting of three 5D mutually perpendicular unit vectors to hang its hits.
Here is one such perpendicular frame:

Clear[k, hangerframe];
\(\(hangerframe[
          k_]\  := \ \(SingularValues[SpannerMatrix]\)[\([1, 
            k]\)];\)\ 
\)
Table[hangerframe[k], {k, 1, rank}]

And because the subspace S is the same as the collection of all possible hits with SpannerMatrix, this tells you that everything in S is framed up with the same three 5D mutually perpendicular unit vectors. 
That's why folks say that the dimension of S is 3.

B.1.c.i) Calculating the dimension of a subspace of 6D

A subspace S of 6D is defined by the following given spanning set:

Clear[s, i, spanner];
spanner[1] = {0.829, 1.202, 0.539, -0.925, 
          1.289, -0.397};
spanner[2] = {0.073, 1.463, 0.312, 1.622, 1.841, 2.916};
spanner[3] = {0.902, 2.665, 0.851, 0.697, 3.130, 2.519};
spanner[4] = {2.335, -1.908, 
          0.925, -1.391, -1.820, -0.154};
spanner[5] = {0.390, -4.513, 0.0, 
          1.316, -1.968, -0.037};
spanners = Table[spanner[i], {i, 1, 5}]

Calculate the dimension of S.

The spanner matrix is:

SpannerMatrix = Transpose[spanners];
MatrixForm[SpannerMatrix]

The dimension of S is the same as the rank of the spanner matrix:

rank=Length[SingularValues[SpannerMatrix][[2]]]

The dimension of S is 4.

B.1.c.ii) A perpendicular frame spanning S

Stay with the same four dimensional subspace  S of 6D as in part. i) immediately above. 
Exhibit a spanning set for S that consists of 4 mutually perpendicular 6D unit vectors.

Just go with the SVD hangerframe for the spanner matrix.

hangerframe = SingularValues[SpannerMatrix][[1]]

Done.

B.2) Using the Ytest idea to determine whether a given vector is in a given subspace.
Using the Sprojection matrix to find the vector in a subspace that is closest to a given vector.
Using the fact that Sprojection.Y = Ytest to build Sprojection as the sum of rank one matrices or through SVD of the SpannerMatrix.
Using the Sprojection matrix to determine whether a given vector is in a subspace.
Using the Sprojection matrix to determine whether two given subspaces are the same or different

B.2.a.i) Using Ytest to determine whether a given vector is in a given subspace

Here is a spanning set for a subspace S of 4D;

Clear[k, spanner];
spanner[1]  =  {1.0, 0, 2.6, -4.1};
spanner[2]  =  {0.3, 1.2, 0.5, 1.3}; 
\(\(spanner[3]\  = \ \ {\(-0.6\), 1.8, \(-1.2\), 0.2};\)
\)
spanners  =  Table[spanner[k], {k, 1, 3}]

Here are three 4D vectors:

Y1 = {0.76,-0.96,2.2,-5.14}
            Y2 = {0.48,-2.13,0.66,1.66}
            Y3 = {-0.62,1.38,-0.92,-2.42}

Which of these vectors are in S?

Make the spanner matrix
             SpannerMatrix  = (({{spanner[1], spanner[2], spanner[3]}, {↓, ↓, ↓}})):

SpannerMatrix=Transpose[spanners];
MatrixForm[
      SpannerMatrix]

Calculate the dimension of S:

dim=Length[SingularValues[SpannerMatrix][[2]]]

Calculate a hangerframe for SpannerMatrix:

Clear[hangerframe];
hangerframe[k_] := SingularValues[SpannerMatrix][[1,k]] ;
Table[
      hangerframe[k], {k, 1, dim}]

Because S consists exactly of all hits with the SpannerMatrix, saying that a 4D vector Y is in S is the same as saying that the linear system
              SpannerMatrix.X = Y 
has a solution for X.
Consequently, saying that Y is in S is the same as saying that Y is the same as

Ytest=(∑_(k = 1)^rank)(Y.hangerframe[k]) hangerframe[k] = (∑_(k = 1)^dim)(Y.hangerframe[k]) hangerframe[k]

Try it out for Y1:

Y1 = {0.76, -0.96, 2.2, -5.14}

Y1test = (∑_(k = 1)^dim)(Y1.hangerframe[k]) hangerframe[k]

The call:
        Y1 is in S because Y1test = Y1.

Try it out for Y2:

Y2 = {0.48, -2.13, 0.66, 1.66}

Y2test = (∑_(k = 1)^dim)(Y2.hangerframe[k]) hangerframe[k]

The call:
        Y2 is not in S because Y2test ≠ Y2.

Try it out for Y3:

Y3 = {-0.62, 1.38, -0.92, -2.42}

Y3test = (∑_(k = 1)^dim)(Y3.hangerframe[k]) hangerframe[k]

The call:
        Y3 is in S because Y3test = Y3.

B.2.a.ii) Using a hit with Sprojection = SpannerMatrix . PseudoInverse[SpannerMatrix] to get as close as you can get

Here's a spanning set for a random subspace S of 5D:

\(
\(Clear[k, spanner];\)\)
spanner[1]  =  
        Table[Random[Real, {-2, 2}], {k, 1, 5}];
spanner[2]  =   Table[
          Random[Real, {-2, 2}], {k, 1, 5}];
spanner[3]  =   Table[
          Random[Real, {-2, 2}], {k, 1, 5}];
\(\(spanner[4]\  = \ \ Table[
          Random[Real, {\(-2\), 2}], {k, 1, 
            5}];\)
\)
spanners  =  Table[spanner[k], {k, 1, 4}]

Here is a random 5D vector:

Y  =  Table[Random[Real, {-7, 7}], {k, 1, 5}]

Come up with a matrix Sprojection so that 
        Sprojection.Y is the member of S that is closest to Y.

Just do this:

Make the spanner matrix
             SpannerMatrix  = (({{spanner[1], spanner[2], spanner[3]}, {↓, ↓, ↓}})    ({{spanner[4]}, {↓}})):

SpannerMatrix=Transpose[spanners];
MatrixForm[
      SpannerMatrix]

Define the Sprojection matrix:

Sprojection =SpannerMatrix.PseudoInverse[SpannerMatrix];
MatrixForm[Sprojection]

The member of S closest to Y is:

Sprojection . Y

Reason: 
When you go with any matrix A, then
         A.(PseudoInverse[A].Y)
is as close as you can get to Y with a hit with A.
So when you have a spanning set for a subspace S of kD and make the corresponding SpannerMatrix, you know that for any Y in kD
         SpannerMatrix.(PseudoInverse[SpannerMatrix].Y)
is as close as you can get to Y with a hit with SpannerMatrix. 
And because S consists precisely of all possible hits with SpannerMatrix, it is guaranteed that for any kD Y, 
       Sprojection.Y =  SpannerMatrix.PseudoInverse[SpannerMatrix].Y
is the member of S closest to Y.

B.2.a.iii)   Sprojection.Y = Ytest,  so Ytest is as close as you can get to Y.

Here's a spanning set for a random subspace S of 6D:

\(
\(Clear[k, spanner];\)\)
spanner[1]  =  
        Table[Random[Real, {-2, 2}], {k, 1, 6}];
spanner[2]  =   Table[
          Random[Real, {-2, 2}], {k, 1, 6}];
spanner[3]  =   Table[
          Random[Real, {-2, 2}], {k, 1, 6}];
\(\(spanner[4]\  = \ \ Table[
          Random[Real, {\(-2\), 2}], {k, 1, 
            6}];\)
\)
spanners  =  Table[spanner[k], {k, 1, 4}]

Here is a random 6D vector:

Clear[y];
Y  =  Table[Random[Real, {-8, 8}], {k, 1, 6}]

The vector in S closest to Y is:

SpannerMatrix=Transpose[spanners];
Sprojection =SpannerMatrix.PseudoInverse[SpannerMatrix];
closest  =  Sprojection . Y

Now look at this:

dim=Length[SingularValues[SpannerMatrix][[2]]];
Clear[
        hangerframe];
hangerframe[k_] := SingularValues[SpannerMatrix][[1,k]] ;
Ytest = (∑_(k = 1)^dim)(Y.hangerframe[k]) hangerframe[k]

Ytest  came out to be equal to the vector in S closest to Y.
Is this some sort of accident? 
If not explain why it is not an accident.

Criminee.

In mathematics, there are no accidents.

To explain why it is not an accident and will happen every time, remember

PseudoInverse[SpannerMatrix].Y=(∑_(k = 1)^dim)(((Y.hangerframe[k])/(stretch[k]))) alignerframe[k]

where stretch[k], hangerframe[k] and alignerframe[k] come from SVD analysis of SpannerMatrix so that
                 SpannerMatrix.alignerframe[k] = stretch[k] hangerframe[k].
Now rock on:
              Sprojection.Y 
                       = SpannerMatrix.PseudoInverse[SpannerMatrix].Y

=   SpannerMatrix. (∑_(k = 1)^dim)(((Y . hangerframe[k])/(stretch[k]))) alignerframe[k]

=  . (∑_(k = 1)^dim)(((Y . hangerframe[k])/(stretch[k]))) SpannerMatrix.alignerframe[k]

=  . (∑_(k = 1)^dim)(((Y . hangerframe[k])/(stretch[k]))) stretch[k] hangerframe[k]

=  . (∑_(k = 1)^dim)(Y . hangerframe[k]) hangerframe[k]

=  . Ytest.
That's it.

B.2.a.iv) Using the fact that Sprojection.Y = Ytest to build Sprojection as the sum of rank one matrices

Here's a spanning set for a a subspace  S of 6D:

\(
\(Clear[k, spanner];\)\)
spanner[1]  =  {-0.36, -1.77, -1.55, 1.24, 
          0.26, -0.57};
spanner[2]  =   {-1.76, -1.34, 1.39, 0.73, 1.85, 
          0.87};
spanner[3]  =   {1.41, 0.40, 1.94, -1.48, 1.52`, 
          1.57};
spanner[4]  =  {3.16, 
          0.91, -4.33, -0.22, -3.44, -2.31};
spanner[5]  =  {0.21, -1.32, -1.77, -1.39, 
          0.67, -0.29};
spanner[6]  = {-3.73, -1.36, 4.55, 2.85, 3.03, 
          2.03};
spanners  =  Table[spanner[k], {k, 1, 6}]

The Sprojection matrix for this subspace is:

SpannerMatrix  =  Transpose[spanners]; 
Sprojection = SpannerMatrix.PseudoInverse[SpannerMatrix];
MatrixForm[
      Sprojection]

Build this matrix as the sum of well-chosen rank one matrices.

In part iii) immediately above, you saw that

Sprojection.Y    =  . (∑_(k = 1)^dim)(Y . hangerframe[k]) hangerframe[k].

This tells you how to make rank one matrices whose sum is Sprojection.
Just do this:

dim = Length[SingularValues[SpannerMatrix][[2]]];
Clear[hangerframe, rankOne];
hangerframe[k_] := SingularValues[SpannerMatrix][[1,k]];
rankOne[k_] := Transpose[{hangerframe[k]}].{hangerframe[k]};
sum=(∑_(k = 1)^dim)rankOne[k];
MatrixForm[
      sum]

Compare:

MatrixForm[Sprojection]

Nailed it clean.
This will work every time because

Sprojection.Y    =  . (∑_(k = 1)^dim)(Y . hangerframe[k]) hangerframe[k].

B.2.a.v) Building Sprojection directly from the SVD hanger frames of the SpannerMatrix

Here's a spanning set for a a subspace  S of 6D:

\(
\(Clear[k, spanner];\)\)
spanner[1]  =  {-0.36, -1.77, -1.55, 1.24, 
          0.26, -0.57};
spanner[2]  =   {-1.76, -1.34, 1.39, 0.73, 1.85, 
          0.87};
spanner[3]  =   {1.41, 0.40, 1.94, -1.48, 1.52, 
          1.57};
spanner[4]  =  {3.16, 
          0.91, -4.33, -0.22, -3.44, -2.31};
spanner[5]  =  {0.21, -1.32, -1.77, -1.39, 
          0.67, -0.29};
spanner[6]  = {-3.73, -1.36, 4.55, 2.85, 3.03, 
          2.03};
spanners  =  Table[spanner[k], {k, 1, 6}]

The Sprojection matrix for this subspace is:

SpannerMatrix  =  Transpose[spanners]; 
Sprojection = SpannerMatrix.PseudoInverse[SpannerMatrix];
MatrixForm[
      Sprojection]

Build this matrix directly from the SVD of the SpannerMatrix.

In part iii) immediately above, you saw that

Sprojection.Y    =  . (∑_(k = 1)^dim)(Y . hangerframe[k]) hangerframe[k].

This tells you how to make Sprojection directly from the SVD hangerframe of the Spanner Matrix
You go with the SVD hangerframe for both the alignerframe and the hangerframe of Sprojection with all stretch factors equal to 1.

dim = Length[SingularValues[SpannerMatrix][[2]]];
Clear[hangerframe, rankOne];
aligner = SingularValues[SpannerMatrix][[1]];
stretcher  =  IdentityMatrix[dim];
hanger = Transpose[SingularValues[SpannerMatrix][[1]]];

Sprojection = hanger.stretcher.aligner;
MatrixForm[
      Sprojection]

Compare:

MatrixForm[SpannerMatrix.PseudoInverse[SpannerMatrix]]

Nailed it clean.
This will work every time because

Sprojection.Y    =  . (∑_(k = 1)^dim)(Y . hangerframe[k]) hangerframe[k].

B.2.b)  Using the Sprojection matrix to determine whether a given vector is in a given subspace

Here is a spanning set for a subspace S of 5D:

Clear[k, spanner];
spanner[1]  =  {-1.4, 1.5, 2.9, 0.6, -2.4};
spanner[2]  =   {-1.7, 0.0, 2.9, 0.0, -3.6};
spanner[3]  =  {0.2, 1.0, 0.0, 0.4, 0.8};
\(\(spanner[4]\  = \ {\(-0.3\), 1.7, \(-2.1\), \(-0.7\), 
          0.1};\)
\)
spanners  =  Table[spanner[k], {k, 1, 4}];

Here are two 5D vectors:

X =  {-5.08,  4.15, 6.89, 0.28, -9.1}

Y = {-5.57,  4.15, 6.89, 
        0.28, -9.1}

One of these vectors is in S. 
The other is not. 
Your job is to determine which one is in S and which one is not.

Go directly to the spanner matrix for S:

SpannerMatrix = Transpose[spanners];
MatrixForm[SpannerMatrix]

Calculate Sprojection matrix

Sprojection = 
        SpannerMatrix . PseudoInverse[SpannerMatrix];
MatrixForm[Sprojection]

The  first given vector is:

X

The vector in S that is closest to X is:

Sprojection . X

The result:
           Sprojection . X = X
The vector in S that is closest to X is X itself.
This tells you that X is in S.

The  second given vector is:

Y

The vector in S that is closest to Y is:

Sprojection . Y

Close, but no cigar.
           Sprojection . Y    ≠   Y
The vector in S that is closest to Y is not the same as Y.
This tells you that Y is NOT in S.

B.2.c.i)  Different spanning sets for the same subspace

Here's a set of spanning vectors which define a subspace S1 of 5D:

Clear[s, i, spanner1];
spanner1[1] = {3.43, -0.57, 8.19, -0.94, 0.48};
spanner1[2] = {0.97, 1.29, 0.83, 5.23, -2.31};
spanner1[3] = {-6.14, 3.08, -5.00, -1.97, 
          0.78};
spanners1 = Table[spanner1[i], {i, 1, 3}]

Here's a another set of spanning vectors which define a subspace S2 of 5D:

Clear[s, i, spanner2];
spanner2[1] = {4.40, 0.72, 9.02, 4.29, -1.83};
spanner2[2] = {-5.17, 4.37, -4.17, 
          3.26, -1.53};
spanner2[3] = {-5.17, 4.37, -4.17, 
          3.26, -1.53};
spanner2[4]  =  {1.94, 2.58, 1.66, 10.46, -4.62};
\(\(\(spanners2\)\(=\)\(Table[
        spanner2[i], {i, 1, 4}]\)\(
\)\)\)

At first glance, it would appear that S1 and S2 are in fact different subspaces of 5D.
Is this true?

Answer:

Go directly to the spanner matrices for each subspace.

SpannerMatrix1 = Transpose[spanners1];
\(MatrixForm[SpannerMatrix1]
\)
SpannerMatrix2 = Transpose[spanners2];
MatrixForm[SpannerMatrix2]

Calculate the  S1projection matrix and the S2projection matrix and look at them:

S1projection = 
        SpannerMatrix1 . PseudoInverse[SpannerMatrix1];
MatrixForm[S1projection]
S2projection = 
        SpannerMatrix2 . PseudoInverse[SpannerMatrix2];
MatrixForm[S2projection]

The result:
             S1projection = S2projection
The call::
The two subspaces are the same.
Reason: 
        Saying a vector Y is in S1 is the same as saying S1projection.Y = Y.
        Saying a vector Y is in S2 is the same as saying S2projection.Y = Y.
        And because 
                    S1projection = S2projection,
       saying that a vector Y is in S1 is the same as saying Y is in S2.

B.2.c.ii)  Different spanning sets for different subspaces

Here's a set of spanning vectors which define a subspace S1 of 6D:

Clear[s, i, spanner1];
spanner1[1] = {3.43, -0.57, 8.19, -0.94, 0.48, 
          0.78};
spanner1[2] = {0.97, 1.29, 0.83, 5.23, -2.31, 7.80};
spanner1[3] = {-6.14, 3.08, -5.00, -1.97, 0.78, 
          0.85};
spanner1[4] = {0.0, -1.00, 0.0, -2.97, 0.69, 
          1.75};
spanners1 = Table[spanner1[i], {i, 1, 4}]

Here's a another set of spanning vectors which define a subspace S2 of 6D:

Clear[s, i, spanner2];
spanner2[1] = {1.39, -0.49, -2.96, -4.13, 0.74, 
          4.19};
spanner2[2] = {-0.68, 1.23, 0.62, 5.09, 
          2.06, -2.37};
spanner2[3] = {1.16, 1.18, 1.20, -1.30, 2.42, 2.85};
spanner2[4] = {0.48, 2.41, 1.82, 3.79, 4.48, 0.48};
spanners2 = Table[spanner2[i], {i, 1, 4}]

Are these two subspaces the same?

Answer:

Go directly to the spanner matrices for each subspace.

SpannerMatrix1 = Transpose[spanners1];
\(MatrixForm[SpannerMatrix1]
\)
SpannerMatrix2 = Transpose[spanners2];
MatrixForm[SpannerMatrix2]

Calculate the  S1projection matrix and the S2projection matrix and look at them:

S1projection = 
        SpannerMatrix1 . PseudoInverse[SpannerMatrix1];
MatrixForm[S1projection]
S2projection = 
        SpannerMatrix2 . PseudoInverse[SpannerMatrix2];
MatrixForm[S2projection]

The result:
             S1projection  ≠  S2projection
The call:
The two subspaces are the not same.
Reason: 
        Saying a vector Y is in S1 is the same as saying S1projection.Y = Y.
        Saying a vector Y is in S2 is the same as saying S2projection.Y = Y.
        And because 
                    S1projection ≠ S2projection,
       saying that a vector Y is in S1 is not the same as saying Y is in S2.

B.3)  Linear independence and dimension:
Saying that a  spanning set {spanner[1], spanner[2],  . . . , spanner[k]} for a subspace S of nD is linearly independent is the same as saying the dimension of S is k.
Redundant spanning sets and linear dependence

Most folks like to say:
A given spanning set for a subspace S is linearly independent if the dimension of S is the same as the number of vectors in the given spanning set.

A given spanning set for a subspace S is linearly dependent if the dimension of S is less than the number of vectors in the given spanning set.

B.3.a.i) A linearly independent set in 6D

Here is a spanning set for a subspace S of 6D:

Clear[spanner, i];
spanner[1] = {1.0, -2.3, 5.0, 
          6.7, -4.9, -2.0};
spanner[2] = {0.3, 2.3, -4.6, -1.7, 5.8, 0.0};
spanner[3] = {1.0, 7.1, 5.0, 3.7, 0.9, -2.0};
spanners = Table[spanner[i], {i, 1, 3}]

Determine whether this spanning set is linearly independent or linearly dependent.

The spanner matrix for the subspace spanned by the given spanning set is:

SpannerMatrix = Transpose[spanners];
MatrixForm[SpannerMatrix]

The dimension of the subspace spanned by these vectors is the rank of SpannerMatrix:

rank=Length[SingularValues[SpannerMatrix][[2]]]

The number of vectors in this given spanning set is:

Length[spanners]

The result: The dimension of the subspace spanned by this spanning set is the same as the number of vectors in the given spanning set. 
The call:
This spanning set is LINEARLY INDEPENDENT.

B.3.a.ii) A linearly dependent set in 7D

Here is a spanning set of made with four vectors in 7D:

Clear[spanner, i];
spanner[1] = {1.0, -2.3, 5.0, 
          6.7, -4.9, -2.0, -2.3};
spanner[2] = {0.3, 2.3, -4.6, -1.7, 5.8, 0.0, 
          3.5};
spanner[3] = {1.0, 7.1, 5.0, 3.7, 0.9, -2.0, 4.9};
spanner[4] = {1.6, 11.7, -4.2, 0.3, 12.5, -2.0, 
          11.9};
spanners = Table[spanner[i], {i, 1, 4}]

Determine whether this spanning set is linearly independent or linearly dependent.

The spanner matrix for the subspace spanned by the given spanning set is:

SpannerMatrix = Transpose[spanners];
MatrixForm[SpannerMatrix]

The dimension of the subspace spanned by these vectors is the rank of SpannerMatrix:

rank=Length[SingularValues[SpannerMatrix][[2]]]

The number of vectors in this given spanning set is:

Length[spanners]

The result: The dimension of the subspace spanned by this spanning set is less than the number of vectors in the given spanning set. 
The call:
This spanning set is LINEARLY DEPENDENT.

B.3.a.iii) A set of four 3D vectors cannot be linearly independent

You are given a set of four vectors in 3D. 
How do you know in advance that the given set of four given vectors is linearly dependent?

If the four vectors are linearly independent, then they span an four dimensional subspace of 3D.
But 3D can accommodate at most 3 dimensions and this rules out the possibility of any four dimensional subspace of 3D.

B.3.a.iv)  A set of twelve 8D vectors cannot be linearly independent

You are given a set of 12 vectors in 8D. 
How do you know in advance that the given set of 12 given vectors is linearly dependent?

If the 12 vectors are linearly independent, then they span an 12  dimensional subspace of 8D.
But 8D can accommodate at most 8 dimensions and this rules out the possibility of any 12 dimensional subspace of 8D.

B.3.b.i) Finding redundant vectors  in linearly dependent sets

Here's a spanning set for a subspace S of 5D:

Clear[s, i, spanner];
spanner[1] = {1.43, 2.57, 6.19, -3.94, 0.0};
spanner[2] = {0.95, 1.50, 1.85, 1.20, 0.50};
spanner[3] = {0.67, 1.37, 4.71, -4.9, -0.4};
spanner[4] = {2.1, 3.94, 10.9, -8.84, -0.4};
spanner[5] = {1.10, 2.00, -2.1, -1.90, 0.46};
spanners = Table[spanner[i], {i, 1, 5}]

When you look at:

SpannerMatrix = Transpose[spanners];
MatrixForm[
        SpannerMatrix];
Sdim=Length[SingularValues[SpannerMatrix][[2]]]

And:

Length[spanners]

You see:
The original spanning set is linearly dependent.

And after a little more thought, you realize the 5 - 3 = 2 of the given spanners are redundant in the sense when you throw them out of the spanning set, the resulting spanning set still spans the same subspace S.
Find the redundant vectors in the given spanning set.

To identify the redundant spanners, look at

spanners12  =  {spanner[1], spanner[2]};
SpannerMatrix12  =  
        Transpose[spanners12];
rank  =  
        Length[SingularValues[
              SpannerMatrix12][[2]]];
S12dim  =  
      rank

This tells you that {spanner[1], spanner[2]} span a two dimensional subspace S12 of 5D.
The call:  Neither spanner[1] nor spanner[2] are redundant.
Now look at:

spanners123  =  {spanner[1], spanner[2], spanner[3]};
SpannerMatrix123  =  
        Transpose[spanners123];
rank  =  
        Length[SingularValues[
              SpannerMatrix123][[2]]];
S123dim  =  
      rank

The upshot: Including spanner[3] does not raise the dimension.

So spanner[3] belongs to the subspace S12 spanned by  {spanner[1], spanner[2]}. 
The call:  spanner[3] is redundant.

Now look at:

spanners1234  =  {spanner[1], spanner[2], spanner[3], 
            spanner[4]};
SpannerMatrix1234  =  
        Transpose[spanners1234];
rank  =  
        Length[SingularValues[
              SpannerMatrix1234][[2]]];
S1234dim  =  
      rank

The upshot: Including spanner[4] does not raise the dimension.
So spanner[3] belongs to the subspace S12 spanned by  {spanner[1], spanner[2]}. 
The call:  spanner[4] is redundant.
Now look at:

spanners12345  =  {spanner[1], spanner[2], spanner[3], spanner[4], 
          spanner[5]};
SpannerMatrix12345  =  Transpose[spanners12345];
rank  =  
        Length[SingularValues[SpannerMatrix12345][[2]]];
S12345dim  =  rank

The upshot: Including spanner[5] does raise the dimension.
 The call:  spanner[5] is  not redundant.
 
The original (linearly dependent) spanning set for S is:

originalspanners  = {spanner[1], spanner[2], spanner[3], spanner[4], 
        spanner[5]}

The redundant vectors are spanner[3] and spanner[4]. Throwing them out gives a linearly independent spanning set for S ( with no redundant vectors):

reducedspanners  =  {spanner[1], spanner[2], spanner[5]}

Confirm by looking at the Sprojection matrices coming from the original spanning set and the reduced spanning set:

SpannerMatrix1 = Transpose[originalspanners];
\(\(SpannerMatrix2 = Transpose[reducedspanners];\)
\)
S1projection = 
        SpannerMatrix1 . PseudoInverse[SpannerMatrix1];
\(MatrixForm[S1projection]
\)
S2projection = 
        SpannerMatrix2 . PseudoInverse[SpannerMatrix2];
MatrixForm[S2projection]

Right on target.

B.3.b.ii) Linearly independent sets have no redundant members

Given a spanning set, agree that one of the spanners is redundant if you remove it from the spanning set and the remaining spanners span the same subspace as the original spanning set. 
Explain why it is IMPOSSIBLE for a linearly independent spanning set to contain a redundant vector.

If a given spanning set 
          {spanner[1], spanner[2],  .   .   . , spanner[k]}
is linearly independent, then the dimension of the subspace S spanned by this set is k.

If you remove any one of the spanners from this set, then you are left with (k-1) vectors. These (k - 1) vectors can span at most a (k-1) dimensional subspace. This (k-1) dimensional subspace cannot be all of S (because S is k-dimensional).

B.4) A basis for S is any linearly independent spanning set for S.
Using calculations of dimension to help to pare a linearly dependent spanning set down to a basis

Most folks say that a basis for a subspace S is any linearly independent spanning set for S.

B.4.a.i)  A basis for a subspace S is any spanning set for S not containing a redundant vector

Is it true that  a basis for a subspace S is any spanning set for S not containing a redundant vector?

In one word:

B.4.a.ii) Saying that a spanning set is a basis is the same as saying that the associated spanner matrix is of full rank

Is it true that saying that a spanning set is a basis is the same as saying that the associated spanner matrix is of full rank?

In one word:

B.4.b) Basis expansion

Given a basis {spanner[1], spanner[2],  .   .   . , spanner[k]} of a subspace S, 
explain why X in S determines unique coefficients x[1], x[2],  .   .   . , x[k] so that
             X = (∑_(i = 1)^k) x[i] spanner[i]

You are given that
          {spanner[1], spanner[2],  .   .. , spanner[k]} 
 is linearly independent.
This tells you that the associated spanner matrix is of full rank.
Now saying
        X = (∑_(i = 1)^k) x[i] spanner[i] 
is the same as saying
         X =  SpannerMatrix . {x[1], x[2],  .   .   . , x[k]}
This is the same as saying
         XX  = {x[1], x[2],  ... , x[k]} 
is a solution of
        SpannerMatrix . XX = X.
And because SpannerMatrix is of full rank,
the solution
         XX  = {x[1], x[2],  ... , x[k]}
is the only solution. 
So the coefficients {x[1], x[2],  .   .  , x[k]} 
that make
           X = (∑_(i = 1)^k) x[i] spanner[i]
are uniquely determined.

B.4.c.i) Is it a basis?

Here's a spanning set for a subspace S of 4D:

Clear[s, i, spanner];
spanner[1] = {3.43, -0.57, 8.19, -0.94};
spanner[2] = {0.97, 1.29, 0.83, 5.23};
spanner[3] = {-6.14, 3.08, -5.00, -1.97};
\(\(spanners = Table[spanner[i], {i, 1, 3}];\)
\)
ColumnForm[spanners]

Determine whether this spanning set is a basis for S.

This is the same as checking whether this spanning set is linearly independent.
To do this, check the rank of the associated spanner matrix:

SpannerMatrix = Transpose[spanners];
rank = 
        Length[SingularValues[
              SpannerMatrix][[2]]];
Sdim = rank

This tells you that these 3 spanning vectors span a 3-dimensional subspace of S of 4D, so
the given spanner set is linearly independent.  
This confirms that the given spanning set is a basis of S.

B.4.c.ii) Calculating a basis expansion

Stay with the same spanning set and subspace S as in part i) and look at
the projection of a random 4D vector onto S:

\(
\(random4D\  = \ {Random[Real, {\(-4\), 4}], 
          Random[Real, {\(-4\), 4}], Random[Real, {\(-4\), 4}], 
          Random[Real, {\(-4\), 4}]};\)
\)
\(\(Sprojection = 
        SpannerMatrix . PseudoInverse[SpannerMatrix];\)
\)
Svector  =  Sprojection . random4D

This vector is guaranteed to be in S. 
Your job is to come up the basis expansion of Svector by coming up with the unique numbers
           x[1], x[2] and x[3]
that make
        Svector=(∑_(i = 1)^3)x[i]  spanner[i].

The unique  x[1], x[2] and x[3] that make
         Svector=(∑_(i = 1)^3)x[i] spanner[i]
 solve the linear system
        SpannerMatrix.{x[1], x[2], x[3]}= Svector.
The solution is:

{x[1], x[2], x[3]}  =  PseudoInverse[SpannerMatrix] . 
        Svector

Check:

(∑_(i = 1)^3)x[i] spanner[i]
Svector

Nailed it.

B.4.d.i) Is it a basis?

Here's a spanning set for a subspace S of 5D:

Clear[s, i, spanner];
spanner[1] = {1.43, 2.57, 6.19, -3.94, 0.0};
spanner[2] = {0.95, 1.50, 1.85, 1.20, 0.50};
spanner[3] = {0.67, 1.37, 4.71, -4.9, -0.4};
spanner[4] = {2.1, 3.94, 10.9, -8.84, -0.4};
spanner[5] = {1.10, 2.00, -2.1, -1.90, 0.46};
\(\(spanners = Table[spanner[i], {i, 1, 5}];\)
\)
ColumnForm[spanners]

Determine whether this spanning set is a basis for S.

This is the same as checking whether this spanning set is linearly independent.
To do this, check the rank of the associated spanner matrix:

SpannerMatrix = Transpose[spanners];
rank = 
        Length[SingularValues[
              SpannerMatrix][[2]]];
Sdim = rank

This tells you that these 5 spanning vectors span a 3-dimensional subspace of S of 5D, so
the given spanner set is linearly dependent.  
This confirms that the given spanning set is NOT a basis of S.

B.4.d.ii) Paring a linearly dependent spanning set down to a basis

Stay with the same spanning set for a subspace S of 5D as in part i).

Clear[s, i, spanner];
spanner[1] = {1.43, 2.57, 6.19, -3.94, 0.0};
spanner[2] = {0.95, 1.50, 1.85, 1.20, 0.50};
spanner[3] = {0.67, 1.37, 4.71, -4.9, -0.4};
spanner[4] = {2.1, 3.94, 10.9, -8.84, -0.4};
spanner[5] = {1.10, 2.00, -2.1, -1.90, 0.46};
\(\(spanners = Table[spanner[i], {i, 1, 5}];\)
\)
ColumnForm[spanners]

Sitting in this spanning set is a basis for S. 
Come up with this basis for S by identifying and throwing out the redundant spanning vectors.

In part i), You saw that the dimension of subspace S spanned by the original spanning set is 3. Because there are 5 vectors in the spanning set you are sure that the original spanning set has two redundant vectors.
To identify them, look at

spanners12  =  {spanner[1], spanner[2]};
SpannerMatrix12  =  Transpose[spanners12];
rank  =  
        Length[SingularValues[SpannerMatrix12][[2]]];
S12dim  =  rank

This tells you that {spanner[1], spanner[2]} span a two dimensional subspace S12 of 5D.
The call:  Neither spanner[1] nor spanner[2] are redundant.
Now look at:

spanners123  =  {spanner[1], spanner[2], spanner[3]};
SpannerMatrix123  =  Transpose[spanners123];
rank  =  
        Length[SingularValues[SpannerMatrix123][[2]]];
S123dim  =  rank

The upshot: Including spanner[3] does not raise the dimension.
So spanner[3] belongs to the subspace S12 spanned by  {spanner[1], spanner[2]}. 
The call:  spanner[3] is redundant.
Now look at:

spanners1234  =  {spanner[1], spanner[2], spanner[3], 
          spanner[4]};
SpannerMatrix1234  =  Transpose[spanners1234];
rank  =  
        Length[SingularValues[SpannerMatrix1234][[2]]];
S1234dim  =  rank

The upshot: Including spanner[4] does not raise the dimension.
So spanner[3] belongs to the subspace S12 spanned by  {spanner[1], spanner[2]}. 
The call:  spanner[4] is redundant.
Now look at:

spanners12345  =  {spanner[1], spanner[2], spanner[3], spanner[4], 
          spanner[5]};
SpannerMatrix12345  =  Transpose[spanners12345];
rank  =  
        Length[SingularValues[SpannerMatrix12345][[2]]];
S12345dim  =  rank

The upshot: Including spanner[5] does raise the dimension.
 The call:  spanner[5] is  not redundant.
 
The original (linearly dependent) spanning set for S is:

{spanner[1], spanner[2], spanner[3], spanner[4], spanner[5]}

The redundant vectors are spanner[3] and spanner[4]. Throwing them out gives a (linearly independent) basis for S:

{spanner[1], spanner[2], spanner[5]}

B.5) Traditional book definitions of linear independence and linear dependence

B.5.a.i) Saying a spanning set is linearly independent is the same as saying the SpannerMatrix is of full rank

Explain this:
Saying that a given spanning set
         {spanner[1], spanner[2], . . ., 
        spanner[k]}
 is linearly independent is the same as saying that the associated spanner matrix is of full rank.

Call S the subspace of nD spanned by the given spanning set
      {spanner[1], spanner[2], . . ., 
        spanner[k]}.
The associated spanner matrix (whose ith column is spanner[i]) hits on kD.

Saying that the spanner matrix is of full rank is the same as saying that the rank of the spanner matrix is k.

Saying that {spanner[1], spanner[2], . . ., 
        spanner[k]}is linearly independent is the same as saying that the rank of the spanner matrix is k.

So saying that a given spanning set
         {spanner[1], spanner[2], . . ., 
        spanner[k]}
 is linearly independent is the same as saying that the associated spanner matrix is of full rank.

B.5.a.ii) Traditional book definition of linear independence

Explain this arcane statement:
 Saying that a given spanning set
          {spanner[1], spanner[2], . . ., 
        spanner[k]} 
 is linearly independent the same as saying that it is IMPOSSIBLE to come up with numbers 
           {x[1], x[2], . . ., x[k]}
not all of which are zero, so that
           (∑_(i = 1)^k) x[i] spanner[i] = {0, 0, . . ., 0}.

Saying that a given spanning set
         {spanner[1], spanner[2], . . ., 
        spanner[k]}
 is linearly independent is the same as saying that the associated spanner matrix is of full rank.
 
 This is the same as saying that all the SVD stretch factors for the spanner matrix are positive.
 
 This is the same as saying that the only solution of
         SpannerMatrix . {x[1], x[2], . . , x[k]} = {0, 
          0, . . ., 0} 
  is
         {x[1], x[2], . . , 
          x[k]} = {0, 0, . . ., 
            0}.
         
 Because
  SpannerMatrix . {x[1], x[2], . . , 
            x[k]} = (∑_(i = 1)^k) x[i] spanner[i],
 this is the same as saying that the only solution of
                (∑_(i = 1)^k) x[i] spanner[i] = {0, 0, . . ., 0}
is 
         {x[1], x[2], . . , 
          x[k]} = {0, 0, . . ., 
            0}.
         
And this is the same as saying it is impossible to come up with numbers 
           {x[1], x[2], . . ., x[k]}
not all of which are zero, so that
           (∑_(i = 1)^k) x[i] spanner[i] = {0, 0, . . ., 0}.

B.5.b.i) Saying a spanning set is linearly dependent is the same as saying the SpannerMatrix is not of full rank

Explain this:
Saying that a given spanning set
         {spanner[1], spanner[2], . . ., 
        spanner[k]}
is linearly dependent is the same as saying that the associated spanner matrix is not of full rank.

Call S the subspace spanned by the given spanning set
      {spanner[1], spanner[2], . . ., 
        spanner[k]}.
The associated spanner matrix (whose ith column is spanner[i]) hits on kD.

Saying that the spanner matrix is of not of full rank is the same as saying that the rank of the spanner matrix is less than k.

Saying that {spanner[1], spanner[2], . . ., 
        spanner[k]}is linearly dependent is the also same as saying that the rank of the spanner matrix is less than k.

So saying that a given spanning set
         {spanner[1], spanner[2], . . ., 
        spanner[k]}
 is linearly dependent is the same as saying that the associated spanner matrix is of not of full rank.

B.5.b.ii) Traditional book definition of linear dependence

Explain this arcane statement:
 Saying that a given spanning set
          {spanner[1], spanner[2], . . ., 
        spanner[k]} 
is linearly dependent the same as saying that it is POSSIBLE to come up with numbers 
           {x[1], x[2], . . ., x[k]}
not all of which are zero, so that
           (∑_(i = 1)^k) x[i] spanner[i] = {0, 0, . . ., 0}.

Saying that a given spanning set
         {spanner[1], spanner[2], . . ., 
        spanner[k]}
 is linearly dependent is the same as saying that the associated spanner matrix is of not of full rank.
 
 This is the same as saying that at least one SVD stretch factors for the spanner matrix is 0.
 
 This is the same as saying there is at least one vector
        {x[1], x[2], . . , x[k]} ≠ {0, 
          0, . . ., 0} 
 so that
        SpannerMatrix . {x[1], x[2], . . , x[k]} = {0, 
          0, . . ., 0} . 
         
 Because
        SpannerMatrix . {x[1], x[2], . . , 
            x[k]} = (∑_(i = 1)^k) x[i] spanner[i],
this is the same as saying there is at least one vector
        {x[1], x[2], . . , x[k]} ≠ {0, 
          0, . . ., 0} 
 so that
        (∑_(i = 1)^k) x[i] spanner[i] = {0, 
          0, . . ., 0}.

And this is the same as saying it is possible to come up with numbers 
           {x[1], x[2], . . ., x[k]}
not all of which are zero, so that
           (∑_(i = 1)^k) x[i] spanner[i] = {0, 0, . . ., 0}.

B.6) All bases for a given subspace of nD have the same number of vectors

Implicit in the definition of dimension as the rank of the Spanner Matrix is the fact that if a subspace S of nD is spanned by a perpendicular frame   {(Subscript[B, 1]),(Subscript[B, 2]),. . ., (Subscript[B, k])}, then any basis of S also consists of exactly k vectors.
The purpose of this problem is to explain this in detail.
Mathematics majors should fully engage. Others might want to as well. 
If so, then continue on for a dose of some advanced mathematical reasoning.

B.6.a.i)  If a subspace S of nD is spanned by perpendicular frame (orthonormal basis) consisting of exactly k vectors, then all other bases of S also consist of exactly k vectors

Explain this statement:
If a subspace S of nD is spanned by perpendicular frame (orthonormal basis)

{(Subscript[B, 1]),(Subscript[B, 2]),. . ., (Subscript[B, k])}

then all other bases (linearly independent spanning sets)  of S consist of exactly k vectors.

The statement is true for k =1.
To prove this by induction, you take a positive integer k. 
You get to assume that  for any positive integer m < k that
if a subspace S of nD is spanned by perpendicular frame (orthonormal basis)

{(Subscript[B, 1]),(Subscript[B, 2]),. . ., (Subscript[B, m])}

then all other bases  of S consist of exactly m vectors.

The goal is to use this assumption to argue why the statement is true when you replace m with k.

To this end, go with a subspace S of nD spanned by a perpendicular frame

{(Subscript[B, 1]),(Subscript[B, 2]),. . ., (Subscript[B, k])}

Put
      SS = the subspace spanned by

{(Subscript[B, 1]),(Subscript[B, 2]),. . ., (Subscript[B, k - 1])}

Legal Assumption:
Because k - 1 < k, you get to assume that every basis for SS consists of exactly k-1 vectors.

Notice that SS = everything is S that is perpendicular to (Subscript[B, k]).

Now take another basis

{(Subscript[A, 1]),(Subscript[A, 2]),. . ., (Subscript[A, r])}

of S.  
The goal is to explain why r = k.
First note that it must be true that (Subscript[B, k])•(Subscript[A, j]) ≠ 0 for some j. 
If r > j, swap the labels so that the old (Subscript[A, j]) becomes the new (Subscript[A, r]).

This guarantees that (Subscript[B, k]) •(Subscript[A, r]) ≠ 0.
Now look at the vectors

(Subscript[C, i]) = (Subscript[A, i]) -  ((((Subscript[B, k]) •(Subscript[A, i]))/((Subscript[B, k]) •(Subscript[A, r])))) 
        (Subscript[A, r])    for i =1,2,. . ., r - 1.

Fact 1: The set {(Subscript[C, 1]),(Subscript[C, 2]),. . ., (Subscript[C, r - 1])} is linearly independent.

Reason: Because

{(Subscript[A, 1]),(Subscript[A, 2]),. . ., (Subscript[A, r])}

is linearly independent,

and

(Subscript[C, i]) = (Subscript[A, i]) -  ((((Subscript[B, k]) •(Subscript[A, i]))/((Subscript[B, k]) •(Subscript[A, r])))) 
        (Subscript[A, r])    for i =1,2,. . ., r-1.

you know that

(∑_(i = 1)^(r - 1)) (Subscript[λ, i]) (Subscript[C, i]) = (∑_(i = 1)^(r - 1)) (Subscript[λ, i]) (Subscript[A, i]) + (messy constant) (Subscript[A, r])

cannot be {0,0,. . .,0}  unless  (Subscript[λ, 1])=  (Subscript[λ, 2]) = .... =  (Subscript[λ, r  -  1]) = 0.

This explains (via the traditional definition of linear independence) why the set {(Subscript[C, 1]),(Subscript[C, 2]),. . ., (Subscript[C, r - 1])} is linearly independent.

Fact 2: The set {(Subscript[C, 1]),(Subscript[C, 2]),. . ., (Subscript[C, r - 1])}  spans SS and is therefore a basis of SS.

Because S consists of all sums

(∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])

and because SS is everything in S perpendicular  to (Subscript[B, k]), you know that SS is all sums

A =  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])   with  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])▪(Subscript[B, k]) = 0.

Remember that

(Subscript[C, i]) = (Subscript[A, i]) -  ((((Subscript[B, k]) •(Subscript[A, i]))/((Subscript[B, k]) •(Subscript[A, r])))) 
        (Subscript[A, r])    for i =1,2,...,r-1.

So SS is all sums   
              A =  \(∑\+\(i = 1\)\%\(r - 1\)\ \(λ\_i\) \((C\_\(\(i\)\(\ \)\) + \((\(\(B\_k\) •A\_i\)\/\(\(B\_k\) •A\_r\))\) A\_r)\)\) + (Subscript[λ, r ]) (Subscript[A, r ])  with  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])▪(Subscript[B, k]) = 0

= (∑_(i = 1)^(r - 1)) (Subscript[λ, i ]) 
          (Subscript[C, i ]) + \(∑\+\(i = 1\)\%\(r - 1\)\ \(λ\_\(\(i\)\(\ \)\)\) \((\(\(B\_k\) •A\_i\)\/\(\(B\_k\) •A\_r\))\) A\_r\) + (Subscript[λ, r ]) (Subscript[A, r ]) with  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])▪(Subscript[B, k]) = 0.

= (∑_(i = 1)^(r - 1)) (Subscript[λ, i ]) 
          (Subscript[C, i ]) + \(∑\+\(i = 1\)\%\(r - 1\)\ \(λ\_\(\(i\)\(\ \)\)\) \((\(\(B\_k\) •A\_i\)\/\(\(B\_k\) •A\_r\))\) A\_r\) + \(\(λ\_\(\(r\)\(\ \)\)\) \((\(\(B\_k\) •A\_r\)\/\(\(B\_k\) •A\_r\))\) A\_\(\(r\)\(\ \)\)\) with  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])▪(Subscript[B, k]) = 0.

= (∑_(i = 1)^(r - 1)) (Subscript[λ, i ]) 
          (Subscript[C, i ]) + \(∑\+\(i = 1\)\%r\ \(λ\_\(\(i\)\(\ \)\)\) \((\(\(B\_k\) •A\_i\)\/\(\(B\_k\) •A\_r\))\) A\_r\)  with  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])▪(Subscript[B, k]) = 0.

= (∑_(i = 1)^(r - 1)) (Subscript[λ, i ]) 
          (Subscript[C, i ]) +(1/((Subscript[B, k]) •(Subscript[A, r])))(Subscript[A, r]) \(∑\+\(i = 1\)\%r\ \(λ\_\(\(i\)\(\ \)\)\) \((\(B\_k\) •A\_i)\)\)  with  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])▪(Subscript[B, k]) = 0.

= (∑_(i = 1)^(r - 1)) (Subscript[λ, i ]) 
          (Subscript[C, i ]) + 0  with  (∑_(i = 1)^r) (Subscript[λ, i]) (Subscript[A, i])▪(Subscript[B, k]) = 0.

= (∑_(i = 1)^(r - 1)) (Subscript[λ, i ]) 
          (Subscript[C, i ])

This shows that the set {(Subscript[C, 1]),(Subscript[C, 2]),. . ., (Subscript[C, r - 1])}  spans SS. 
And because the set {(Subscript[C, 1]),(Subscript[C, 2]),. . ., (Subscript[C, r - 1])} is also linearly independent, the set {(Subscript[C, 1]),(Subscript[C, 2]),. . ., (Subscript[C, r - 1])} is a basis of SS.

Fact 3:  r  =  k.

{(Subscript[C, 1]),(Subscript[C, 2]),. . ., (Subscript[C, r - 1])} is a basis of SS.
The legal assumption is that  every basis for SS consists of exactly k-1 vectors.
So r - 1 = k - 1. This yields the equality r = k.

Summary:
You started with a subspace S of nD spanned by a perpendicular frame

{(Subscript[B, 1]),(Subscript[B, 2]),. . ., (Subscript[B, k])}

And then you took any old basis

{(Subscript[A, 1]),(Subscript[A, 2]),. . ., (Subscript[A, r])}

of S and argued why r = k. 
This shows that all other bases (linearly independent spanning sets)  of S consist of exactly k vectors.

B.6.a.ii) If a subspace S of nD is spanned by basis (linearly independent spanning set) consisting of exactly k vectors, then all other bases of S also consist of exactly k vectors

Explain this statement:
If a subspace S of nD is spanned by a basis (linearly independent spanning set but not necessarily orthonormal)

{(Subscript[X, 1]),(Subscript[X, 2]),. . ., (Subscript[X, k])}

then all other bases (linearly independent spanning sets)  of S consist of exactly k vectors.

Apply the Gram-Schmidt (See Tutorials) process to

{(Subscript[X, 1]),(Subscript[X, 2]),. . ., (Subscript[X, k])}
 to get an orthonormal basis

{(Subscript[G, 1]),(Subscript[G, 2]),. . ., (Subscript[G, k])}

of S. According to the problem immediately above, all other bases of S consist of exactly k vectors.