Vector space functions for STACK
STACK has a contributed library for vector space functions. To use this library you must load it into the question variables.
- To use the latest code from GitHub:
stack_include_contrib("vectorspaces.mac");
This page contains reference documentation on functions in this library.
Student vector input
Students can enter column or row vectors using vector notation.
Unit vectors and scalar products
vectorspaces.mac provides a few functions to manipulate vectors.
unit_vecp(ex)is a predicate function that tests whether a given input is a unit vector.exmust be a matrix (usevec_convertfor vector notation) with exactly one row or one column.
The following functions have the optional argument sp. If this argument is omitted then the standard inner product is used: the dot product for real vectors, and x . conjugate(y) for complex vectors, linear in the first slot (entries are conjugated only when a vector contains %i, so symbolic entries are treated as real). Otherwise, sp must be the name of a function that performs a scalar product of two vectors; i.e. it takes two vector inputs and outputs a scalar. If given, this scalar product function will be used in place of the standard inner product.
proj(u, v, [sp])will compute the projection ofvontouusing scalar productsp(the standard inner product if omitted).orthogonalize(L, [sp])will orthogonalise a list of vectorsLwith respect to scalar productsp(the standard inner product if omitted)normalize(L, [sp])will normalise a list of vectorsLwith respect to scalar productsp(the standard inner product if omitted)
For complex vectors, a supplied sp should be linear in its first argument and conjugate-linear in its second, as in most linear algebra texts.
Equivalence functions
lin_indp(ex)is a predicate function that tests whether a set of vectors is linearly independent. It can take many forms of input (seecols_to_matrixin the core linear algebra documentation). If given a matrix, it tests whether it has full column rank. The empty set ([],{},ntuple()orspan()) is linearly independent, since it is a basis of .row_equivp(ex,ta)checks whether matrixexis row equivalent to matrixta. Literally, this checks whether the row-reduced echelon forms of the matrices are exactly equal.col_equivp(ex,ta)does the same for column equivalence.subspace_equivp(ex,ta)checks whether two collections of column vectors span the same subspace. i.e. Is each element ofexlinearly dependent ontaand vice versa? Likelin_indp(ex), this function accepts many forms of input. It does not check whether each set of vectors is linearly independent. To check whether two bases are equivalent, use this function in conjunction withlin_indp. The empty set spans , so it is equivalent to another empty set or to any collection of zero vectors.
Manipulating subspaces
Maxima provides columnspace and nullspace functions natively. This will return a span object, where span is an inert function. vectorspaces.mac also provides rowspace and nullTspace functions to extract the row space and cokernel (left null space or null space of the transpose). Literally, these functions just call columnspace and nullspace on the transpose matrix.
columnspace(matrix([1,2,3],[4,5,6],[7,8,9]))givesspan(matrix([1],[4],[7]),matrix([2],[5],[8]))rowspace(matrix([1,2,3],[4,5,6],[7,8,9]))givesspan(matrix([1],[2],[3]),matrix([4],[5],[6]))nullspace(matrix([1,2,3],[4,5,6],[7,8,9]))givesspan(matrix([-3],[6],[-3]))nullTspace(matrix([1,2,3],[4,5,6],[7,8,9]))givesspan(matrix([-3],[6],[-3]))
vectorspaces.mac also provides functions to "trim out" linearly dependent vectors from a set and to extend a basis to .
remove_dep(ex)takes exactly a list of lists or a matrix (it is not flexible likelin_indp) and removes any linearly dependent vectors (or columns if given a matrix). It works from left to right but keeps the left-most vector when comparing vectors.- For example,
remove_dep(matrix([1,2,3],[1,2,4],[1,2,5]))givesmatrix([1,3],[1,4],[1,5]) basisify(ex)will generate a basis for where each vector inexhas elements. This will first remove any dependent vectors usingremove_depand then attempt to extend the basis by adding for from to one at a time.- It will take an optional argument that, when true, orthonormalises the basis, i.e.
basisify(ex, true). This is only really useful whenexis already orthonormal (or at least orthogonal), because if not Gram-Schmidt orthogonalisation will remove most of the original vectors anyway. -
For example,
basisify(matrix([1,1],[1,-1],[0,1]))will givebut
basisify(matrix([1,1],[1,-1],[0,1]),true)will give -
The intended use of this function is for making the in factorisations orthogonal or for computing a full SVD
Projection matrices
projection_matrix(A)will produce the symmetric, idempotent matrix that orthogonally projects vectors in onto the column space of matrixA. For a complex matrixAit produces the Hermitian, idempotent matrix that projects vectors in , using the conjugate transpose.