Five “random” vectors, each with 4 entries.
{{{ v1 = vector(QQ, [-4, -2, 3, -11]) v2 = vector(QQ, [-2, 7, 3, 9]) v3 = vector(QQ, [6, -4, -7, 5]) v4 = vector(QQ, [-1, 0, 3, -4]) v5 = vector(QQ, [-4, 5, -5, 11]) S = [v1, v2, v3, v4, v5] }}}Consider the subspace spanned by these five vectors. We will make these vectors the rows of a amtrix and row-reduce to see a basis for the space (subspace, or row space, take your pick).
{{{ A = matrix(S) A }}} {{{ A.rref() }}}Sage does this semi-automatically.
{{{ W = span(S) B = W.basis() B }}}Construct a “random” in this subspace.
{{{ w = 5*v1 - 6*v2 + 3*v3 -4*v4 + v5 w }}}Quick check?
{{{ w in W }}}This vector (or any other linear combination of the five vectors) should be a (unique) linear combination of the three basis vectors.
{{{ *B[0] + *B[1] + *B[2] }}}
A totally random vector with 10 entries.
{{{ v = random_vector(ZZ, 10, x=-9, y=9) v }}}The columns of the matrix are a basis of ${ℂ}^{10}$. So the vector v should be a linear combination of the columns of the matrix.
First, the old-fashioned way, exposing Theorem NMUS.
{{{ aug = M.augment(v) aug.rref() }}}Second, with an inverse, since a nonsingular matrix is invertible, exposing Theorem SNCM.
{{{ M.inverse()*v }}}The Sage way. Create a space with a “user basis” and ask for a coordinatization, exposing Theorem VRRB.
{{{ X = (QQ^10).subspace_with_basis(M.columns()) X.coordinates(v) }}}
A particularly simple orthonormal basis of ${ℂ}^{3}$.
{{{ v1 = vector(QQ, [1/3, 2/3, 2/3]) v2 = vector(QQ, [2/3, -2/3, 1/3]) v3 = vector(QQ, [2/3, 1/3, -2/3]) S = [v1, v2, v3] }}}If these vectors are an orthonormal basis, then as the columns of a matrix they should create an orthonormal basis.
{{{ Q = column_matrix(S) Q }}} {{{ Q.conjugate_transpose()*Q }}} {{{ Q.is_unitary() }}}A totally random vector with 3 entries.
{{{ v = random_vector(ZZ, 3, x=-9, y=9) v }}}Four ways to express v as a (unique) linear combination of the basis vectors. Which is most efficient?
First, the old-fashioned way, exposing Theorem NMUS.
{{{ aug = Q.augment(v) aug.rref() }}}Second, with an inverse, since a nonsingular matrix is invertible, exposing Theorem SNCM.
{{{ Q.inverse()*v }}}The Sage way. Create a space with a “user basis” and ask for a coordinatization, exposing Theorem VRRB.
{{{ X = (QQ^3).subspace_with_basis(Q.columns()) X.coordinates(v) }}}Finally, exploiting the orthonormal basis. (Spring 2012: FCLA inner product is reversed from Sage.)
{{{ a1 = v1.hermitian_inner_product(v) a2 = v2.hermitian_inner_product(v) a3 = v3.hermitian_inner_product(v) a1, a2, a3 }}}