Problem 11.3.2
This will be very short. We are asked for an orthogonal basis for
$$
\mathrm{span}
\left\{
\left[
\begin{array}{r}
0\\
1\\
1\\
0
\end{array}
\right],\
\left[
\begin{array}{r}
3\\
0\\
2\\
-1
\end{array}
\right]
\right\}
$$
This, you can simply ask SymPy for: search for GramSchmidt
on that page.
In [1]:
from sympy import *
init_printing(use_latex='mathjax')
In [2]:
GramSchmidt([Matrix([0,1,1,0]), Matrix([3,0,2,-1])])
Out[2]:
$\displaystyle \left[ \left[\begin{matrix}0\\1\\1\\0\end{matrix}\right], \ \left[\begin{matrix}3\\-1\\1\\-1\end{matrix}\right]\right]$
Those two vectors are supposed to be orthogonal. Why don't we check, just to make sure:
In [3]:
Matrix([0,1,1,0]).dot(Matrix([3,-1,1,-1]))
Out[3]:
$\displaystyle 0$
By the way, you'll notice the two orthogonal vectors by applying GramSchmidt
are not orthonormal: their lengths will not be 1, generally. You can fix that by also passing an extra second parameter True
to the GramSchmidt
function:
In [4]:
GramSchmidt([Matrix([0,1,1,0]), Matrix([3,0,2,-1])], True)
Out[4]:
$\displaystyle \left[ \left[\begin{matrix}0\\\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\\0\end{matrix}\right], \ \left[\begin{matrix}\frac{\sqrt{3}}{2}\\- \frac{\sqrt{3}}{6}\\\frac{\sqrt{3}}{6}\\- \frac{\sqrt{3}}{6}\end{matrix}\right]\right]$
This gives us the same vectors as before, but also scaled to length 1.