This page contains several redefinitions of a Python function inprod. You will get incorrect results or errors if you Evaluate a Sage cell defining that function in one subsection below, and then Evaluate Sage cells that use a function by that same name in a different subsection below without evaluating the appropriate Sage cell near the beginning of that different subsection that redefines that inprod function to the appropriate formula used in the example in that particular subsection.
Let’s begin simply with the standard inner product on \(\R^4\text{.}\) Suppose we want to produce an orthogonal basis for the “hyperplane” in \(\R^4\) defined by the equation
\begin{equation*}
w + 2 x + 3 y - 4 z = 0 \text{.}
\end{equation*}
First, we can obtain a basis for this space by treating this single equation as a homogeneous linear system. In other words, we want a basis for the null space of the matrix
Is this an orthogonal basis? We can realize the dot product just by multiplying vectors — Sage will interpret the first vector as a row vector and the second as a column matrix.
If we want an orthonormal basis, we can go one step further and normalize each of these vectors. This will re-introduce some fractions, but that can’t be helped.
We know that these vectors are independent because they’re orthogonal, and there are three of them, so as long as they all lie in our \(3\)-dimensional hyperplane, they will for a basis for it. We can test that by making sure they satisfy the hyperplane equation,
\begin{equation*}
w + 2 x + 3 y - 4 z = 0 \text{.}
\end{equation*}
Here we will carry out the Gram-Schmidt portion of Example 37.4.7. It will get annoying typing conjugate for every complex dot product calculation, so let’s start by creating a Python function to return inner product values. Remember that the order of multiplication matters for the complex dot product.
To get an orthogonal basis, it’s time to Gram-Schmidt. The last input line gets a bit long, so we have used the Python line-continuation character \ to break it up over multiple input lines.
Each block of four results contains three zeros and one nonzero value. The three zeros represents the orthogonality of that particular vector with the other three vectors in the basis, while the nonzero value is the result of the inner product of that vector paired with itself.
Once again we create a Python function to return inner product values, but this time we’ll use slightly more sophisticated Python/Sage programming techniques.
Even though we are using the same initial basis as in Subsection B.6.3, the Gram-Schmidt process has produced a different result because we are using a different inner product.
If you’ve taken a Python programming class, see if you can write a procedure (using def) that takes a list B and a function inprod as parameters, and returns a list containing the results of performing the Gram-Schmidt process on the objects in B using the input parameter function inprod as the inner product function. Fun!