# Section 5.4 $\quad$ Gram-Schmidt Process

In this section, we introduce a method to obtain an orthonormal basis for a finite dimensional inner product space, which is called **Gram-Schmidt Process**.

**Question:** Why do we want an orthonormal basis?

### Example 1

Let $S = \{\mathbf{u}_1,\mathbf{u}_2, \mathbf{u}_3\}$ be a basis for $\mathbb{R}^3$, where
\begin{equation*}
  \mathbf{u_1} = \left[\begin{array}{c}2/3\\ 2/3\\ 1/3\\\end{array}\right],
\mathbf{u_2} = \left[\begin{array}{c}-2/3\\1/3\\ 2/3\\\end{array}\right],
\mathbf{u_3} = \left[\begin{array}{c}1/3\\-2/3\\ 2/3\\\end{array}\right].
\end{equation*}
Note that $S$ is orthonormal. Write the vector $\mathbf{v} = \left[\begin{array}{c}3\\ 4\\ 5\\\end{array}\right]$
as a linear combination of vectors in $S$.


```python
from numpy import *
linalg.solve(array([[2/3, -2/3, 1/3], [2/3, 1/3, -2/3], [1/3, 2/3, 2/3]]), array([3, 4, 5]))
```




    array([ 6.33333333,  2.66666667,  1.66666667])



## Gram-Schmidt Process

Let $V$ be an inner product space, and $W\neq\{\mathbf{0}\}$ an $m$-dimensional subspace of $V$. We can construct an orthonomal basis $T = \{\mathbf{w}_1,\mathbf{w}_2, \cdots,\mathbf{w}_m\}$ for $W$.

**Note:** We first find an orthogonal basis $T^* = \{\mathbf{v}_1,\mathbf{v}_2, \cdots,\mathbf{v}_m\}$ for $W$.<br /><br /><br /><br /><br /><br /><br />

### Example 2

Let $W$ be the subspace of $\mathbb{R}^4$ with basis $S = \{\mathbf{u}_1,\mathbf{u}_2, \mathbf{u}_3\}$ where
\begin{equation*}
  \mathbf{u_1} = \left[\begin{array}{c}1\\ 1\\ 1\\ 0 \\\end{array}\right],
\mathbf{u_2} = \left[\begin{array}{c}-1\\0\\ -1\\ 1 \\\end{array}\right],
\mathbf{u_3} = \left[\begin{array}{c}-1\\0\\ 0\\ -1 \\\end{array}\right].
\end{equation*}
Transform $S$ to an orthonormal basis $T = \{\mathbf{w}_1,\mathbf{w}_2, \mathbf{w}_3\}$


```python
from sympy import *

A = Matrix([[1, -1, -1], [1, 0, 0], [1, -1, 0], [0, 1, -1]]);

A.QRdecomposition()[0]
```




    Matrix([
    [sqrt(3)/3,  -sqrt(15)/15, -4*sqrt(35)/35],
    [sqrt(3)/3, 2*sqrt(15)/15,  3*sqrt(35)/35],
    [sqrt(3)/3,  -sqrt(15)/15,    sqrt(35)/35],
    [        0,    sqrt(15)/5, -3*sqrt(35)/35]])



### Example 3

Find an orthonormal basis for the subspace of $R_4$ consisting of all vectors $[a~~b~~c~~d]$ such that
\begin{equation*}
  a-b-2c+d=0
\end{equation*}


```python
from sympy import *

A = Matrix([[1, -1, -2, 1], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]).T;
B = A.QRdecomposition()[0];
B.col_del(0);

B
```




    Matrix([
    [  sqrt(42)/7,            0,           0],
    [ sqrt(42)/42,   sqrt(30)/6,           0],
    [ sqrt(42)/21, -sqrt(30)/15,   sqrt(5)/5],
    [-sqrt(42)/42,  sqrt(30)/30, 2*sqrt(5)/5]])



a99061298b1e82821261fd39baad527757350d6a
ipynb
Jupyter Notebook
Jupyter_Notes/Lecture27_Sec5-4_GramSchmidtProcess.ipynb
xiuquan0418/MAT341
2fb7ec4e5f0771f10719cb5e4a00a7ab07c49b59
MIT
Jupyter_Notes/Lecture27_Sec5-4_GramSchmidtProcess.ipynb
xiuquan0418/MAT341
2fb7ec4e5f0771f10719cb5e4a00a7ab07c49b59
MIT
Jupyter_Notes/Lecture27_Sec5-4_GramSchmidtProcess.ipynb
xiuquan0418/MAT341
2fb7ec4e5f0771f10719cb5e4a00a7ab07c49b59
MIT
Qwen/Qwen-72B
1. YES
2. YES