Implementing the Gram-Schmidt Algorithm
Let's implement the notions of orthogonality and the Gram-Schmidt algorithm.
This is a very nice example of the beauty and power of functional programming.
Orthogonality
Let's implement the notion of an orthogonal list of vectors.
In[1]:=
(* Inductive definition:
A list containing one vector is orthogonal.
A list containing more than one vector is orthogonal if
the first vector in the list is orthogonal to the remaining vectors, and
removing the first vector from the list results in a (shorter) list of vectors which are mutually orthogonal.
*)
In[2]:=
Testing.
In[5]:=
Out[9]=
Out[10]=
In[11]:=
Out[11]=
Out[12]=
Projection of a vector onto a subspace spanned by an orthogonal basis
Let's implement the notion of the projection of a vector onto a subspace which is spanned by an orthogonal basis.
In[13]:=
In[14]:=
Testing.
In[15]:=
Out[15]=
Out[16]=
Out[17]=
In[18]:=
Out[18]=
Out[19]=
Out[20]=
In[21]:=
Out[21]=
Gram-Schmidt
Let's implement the Gram-Schmidt algorithm.
In[22]:=
In[23]:=
Testing.
In[24]:=
Display the results
The Arrow3D package can be downloaded from Wolfram Research.
showColorful3DVectors is based on a similar procedure written by Selwyn Hollis.
In[29]:=
In[30]:=
In[31]:=
In[34]:=
Where is the third blue vector?
Created by Mathematica (April 8, 2005) | ![]() |