LinearAlgebra Computation
The computation component of the Student[LinearAlgebra] subpackage contains commands that can be used to study the various matrix and vector computations presented in an introductory linear algebra course. There are many commands, and this worksheet demonstrates the basics of a selection of them.
Most of the computation commands in this package are front-ends to more powerful (and often more complicated) commands in the top-level LinearAlgebra package. In all such cases, the help page for the command in the Student[LinearAlgebra] subpackage documents only those features which are considered relevant in a linear algebra course context. Each page includes a link to the help page for the main LinearAlgebra command, should you need more details.
For further information about the commands in the Student[LinearAlgebra] package, see the help page for that command. For a general overview, see Student[LinearAlgebra].
Getting Started
Commands in the package can be referred to using the long form, that is, Student[LinearAlgebra][Eigenvalues].
It is recommended to load the package first and then use the shorter command names.
restart
with⁡StudentLinearAlgebra:
The following examples show how the various routines work.
Note: If you set infolevel[Student] := 1 or infolevel[Student[LinearAlgebra]] := 1, many of the routines in this package provide additional information about the objects they are passed in the form of userinfo messages. This setting is recommended.
infolevelStudentLinearAlgebra≔1:
Basic Matrices and Vectors
Syntax
Most matrices and vectors can be constructed using the angle bracket (< >) syntax. To build a column vector, for example, use this form:
v:=3,2,1
v:=321
A row vector is similarly constructed using vertical bars instead of commas as the separators.
w:=a|b|c
w:=abc
A matrix is constructed out of vectors, either as rows (separated by commas) or as columns (separated by vertical bars).
A≔1,2,3|4,5,6
A:=142536
B:=a|b|c,d|e|f
B:=abcdef
The rows or columns of a matrix can be pre-existing vectors or matrices, so long as the dimensions are compatible.
C:=v|4,5,6
C:=342516
B:=w,w
B:=abcabc
A|x,y,z
14x25y36z
These syntactic constructions result in calls to the Maple commands Vector and Matrix. These are very powerful constructor commands, taking a wide variety of options, which control the precise form and properties of the result. The constructed objects are of type Vector and Matrix.
type⁡v,Vector
true
type⁡A,Matrix
This distinguishes these objects from the older vector and matrix objects, which were used in earlier versions of Maple to represent vectors and matrices. Because these older objects continue to exist in Maple, in the remainder of this worksheet the capitalized names, Vector and Matrix, are used whenever discussing the corresponding Maple object, as distinct from the represented mathematical object.
type⁡v,vector
false
type⁡B,matrix
Standard Operations
Arithmetic with Matrices and Vectors can be carried out using the standard + operator for addition and the . (dot) operator for non-commutative multiplication.
B.A
a+2⁢b+3⁢c4⁢a+5⁢b+6⁢ca+2⁢b+3⁢c4⁢a+5⁢b+6⁢c
w.A
a+2⁢b+3⁢c4⁢a+5⁢b+6⁢c
A+a,b,c|d,e,f
1+a4+d2+b5+e3+c6+f
The dot product of two Vectors is also computed using the . operator.
w.w
a2+b2+c2
The transpose of a Matrix or Vector is computed using the ^ (exponentiation) operator with the special exponent value %T.
B%T
aabbcc
A%T.v
1028
To consider Matrices and Vectors with complex-valued components, the Hermitian transpose of a Matrix or Vector is similarly represented using the ^ operator with exponent %H.
1+I,2⁢I%H
1−I−2⁢I
The cross product of two 3-D Vectors is computed using the &x operator.
1,2,3 &x a,b,c
2⁢c−3⁢b3⁢a−cb−2⁢a
Notes:
Most commands in the Student[LinearAlgebra] subpackage consider symbolic quantities to represent real variables. For example, a dot product of Vectors whose entries are symbolic expressions does not use complex conjugates when computing the result. This assumption is specific to the Student[LinearAlgebra] subpackage and does not hold in the main LinearAlgebra package. To allow variables to represent complex-valued quantities, use the package command, SetDefault( conjugate = true ).
All syntaxes, except for the cross product (&x), are available throughout Maple, whether or not the Student[LinearAlgebra] subpackage has been loaded. The definition of the . (dot) operator is, however, different if the Student[LinearAlgebra] subpackage has been loaded, in that it then treats symbolic quantities as being real-valued by default, as discussed earlier.
Other Useful Matrices and Vectors
The basic syntax described in the preceding sections suffices to construct most of the Matrices and Vectors you need. However, there are some commands in the package that build more specialized Matrices and Vectors.
The n x n identity Matrix is represented as Id(n). Note that n must be a non-negative integer, not a symbol.
Id⁡2
1001
Other useful Matrices and Vectors include:
RandomMatrix⁡4
−93−32844−76−746992−72−499−31−2272967
DiagonalMatrix⁡v
300020001
JordanBlockMatrix⁡λ1,3,λ2,2
λ110000λ110000λ100000λ210000λ2
UnitVectorrow2,5
01000
CharacteristicMatrix⁡1,2,3|4,5,6|7,8,9,t
t−1−4−7−2t−5−8−3−6t−9
RotationMatrix⁡π6
12⁢3−121212⁢3
Queries
There are several commands to handle basic queries about Matrices and Vectors, such as dimensionality, rank, and other properties.
B:=1,2,3|4,5,6|7,8,9
B:=147258369
ColumnDimension⁡B,RowDimension⁡B,Rank⁡B
3,3,2
Both dimensions of a Matrix can be obtained at once, using the same command as is used for the dimension of a Vector.
Dimension⁡B;Dimension⁡v
3,3
3
IsDefinite⁡3,1,1|2,4,2|1,2,5
IsOrthogonal⁡3,1,1|2,4,2|1,2,5
Linear Systems
The simplest way to solve a linear system of equations is to represent the problem as a (Matrix, Vector) pair and call LinearSolve.
A,v,LinearSolve⁡A,v
142536,321,−7343
Alternatively, LinearSolve accepts a Matrix, which it interprets as an augmented matrix with the last column representing the right-hand side of the system.
LinearSolve⁡1,2|3,4|−1,2
5−2
The GenerateMatrix command can be used to transform a set of linear equations into an augmented Matrix suitable for use in LinearSolve.
eqns:=x+2⁢y−3⁢z=5,y+4⁢z=2,2⁢x−y+z=1
eqns:=y+4⁢z=2,x+2⁢y−3⁢z=5,2⁢x−y+z=1
GenerateMatrix⁡eqns,x,y,z
014212−352−111
LinearSolve⁡
38275027127
LinearSolve also handles underdetermined systems.
LinearSolve⁡1,2|3,4|5,6,−1,1,free=t
72+t3−32−2⁢t3t3
There are many commands available to study the process of solving a linear system in more detail. There are factorization commands that are equivalent to the elementary row operations needed to reduce a system to a triangular or diagonal one, which can then be easily solved. For example:
GaussianElimination⁡A|v
1430−3−4000
To obtain the components of this reduction, use:
P,L,U:=LUDecomposition⁡A
P,L,U:=100010001,100210321,140−300
To obtain a triangular system, multiply the inverses of P and L.
u:=P.L−1.v
u:=3−40
The system can then be solved using BackwardSubstitute.
BackwardSubstitute⁡U,u
−7343
The reduced row echelon form of a Matrix is also easily obtained.
ReducedRowEchelonForm⁡1,2,3|4,5,6|7,8,9|10,11,12
10−1−201230000
At an even more detailed level, commands for the elementary row operations are available.
A,SwapRows⁡A,2,3
142536,143625
MultiplyRow⁡A,2,12
1415236
AddRow⁡A,2,1,−2
140−336
Vector Spaces
The technology of solving linear systems can be used to obtain bases for various vector spaces. For example, the null space, row space, and column space of a Matrix can all be computed.
A1:=A%T
A1:=123456
NullSpace⁡A1,RowSpace⁡A1,ColumnSpace⁡A1
1−21,10−1,012,10,01
You can also determine a basis for the span of a set of Vectors, for the sum of two subspaces, or for the intersection of two subspaces.
Basis⁡1,4,7,3,−3,2,4,−2,4,2,5,3,0,1,−3,7,3,1,1,0,−2,−3,−1,4
−324−2,−2−3−14,01−37,1473
IntersectionBasis⁡1,2,3,−1,0,1,4,2,5,2,0,−1
−6210
SumBasis⁡1,2,0,−3,−1,0,−1,0,2,0,1,1,1,1,0,−1
−10−10,120−3,110−1
Eigenvalues and Eigenvectors
You can compute eigenvalues and eigenvectors with a single command, Eigenvectors.
B:=−1,2,3|0,1,3|−1,1,1
B:=−10−1211331
e,E:=Eigenvectors⁡B
e,E:=11−1,−120−11201100
If only the eigenvalues are of interest, you can use the Eigenvalues command.
Eigenvalues⁡B
−111
You can also study the basic computation of eigenvalues and eigenvectors.
p:=CharacteristicPolynomial⁡B,t
p:=t3−t2−t+1
This polynomial is the determinant of the characteristic matrix of B.
p=Determinant⁡B−t⁢Id⁡3
t3−t2−t+1=−1+t+t2−t3
e:=solve⁡p
e:=−1,1,1
NullSpace⁡B−e1⁢Id⁡3
−110
You can also obtain the eigenvalues from the Jordan canonical form.
JordanForm⁡B
−100011001
Return to Index of Example Worksheets
Download Help Document