For vector spaces of column vectors, Sage can quickly determine the coordinates of a vector relative to a basis, as guaranteed by Theorem VRRB. We illustrate some new Sage commands with a simple example and then apply them to orthonormal bases. The vectors v1 and v2 are linearly independent and thus span a subspace with a basis of size 2. We first create this subspace and let Sage determine the basis, then we illustrate a new vector space method, .subspace_with_basis(), that allows us to specify the basis. (This method is very similar to .span_of_basis(), except it preserves a subspace relationship with the original vector space.) Notice how the description of the vector space makes it clear that W has a user-specified basis. Notice too that the actual subspace created is the same in both cases.
Now we manufacture a third vector in the subspace, and request a coordinatization in each vector space, which has the effect of using a different basis in each case. The vector space method .coordinate_vector(v) computes a vector whose entries express v as a linear combination of basis vectors. Verify for yourself in each case below that the components of the vector returned really give a linear combination of the basis vectors that equals v3.
Now we can construct a more complicated example using an orthonormal basis, specifically the one from Example CROB4, but we will compute over QQbar, the field of algebraic numbers. We form the four vectors of the orthonormal basis, install them as the basis of a vector space and then ask for the coordinates. Sage treats the square roots in the scalars as “symbolic” expressions, so we need to explicitly coerce them into QQbar before computing the scalar multiples.
Is this right? Our exact coordinates in the text are printed differently, but we can check that they are the same numbers:
With an orthonormal basis, we can illustrate Theorem CUMOS by making the four vectors the columns of $4\times 4$ matrix and verifying the result is a unitary matrix.
We will see coordinate vectors again, in a more formal setting, in Sage VR.