Linear Algebra Reference Sheet

ADVERTISEMENT

Sage Quick Reference: Linear Algebra
indices of columns spanning column space
A.pivots()
Robert A. Beezer
indices of rows spanning row space
A.pivot_rows()
Matrix Multiplication
Sage Version 4.8
u = vector(QQ,
[1,2,3]),
v = vector(QQ, [1,2])
Pieces of Matrices
A = matrix(QQ, [[1,2,3],[4,5,6]])
GNU Free Document License, extend for your own use
Caution: row, column numbering begins at 0
B = matrix(QQ, [[1,2],[3,4]])
Based on work by Peter Jipsen, William Stein
all possible
u*A, A*v, B*A, B^6,
B^(-3)
A.nrows(),
A.ncols()
0
1
5
produces
entry in row i and column j
B.iterates(v, 6)
A[i,j]
rows = False moves v to the right of matrix powers
row i as immutable Python tuple. Thus,
A[i]
Vector Constructions
then
is possible
Caution: OK: A[2,3] = 8, Error: A[2][3] = 8
f(x)=x^2+5*x+3
f(B)
Caution: First entry of a vector is numbered 0
1
matrix exponential, i.e.
returns row i as Sage vector
B.exp()
A.row(i)
=0
!
length 3 over rationals
u = vector(QQ, [1, 3/2, -1])
returns column j as Sage vector
A.column(j)
v = vector(QQ, {2:4, 95:4, 210:0})
returns single Python list, row-major order
A.list()
Matrix Spaces
211 entries, nonzero in entry 4 and entry 95, sparse
A.matrix_from_columns([8,2,8])
is space of 3
4 matrices
M = MatrixSpace(QQ, 3, 4)
new matrix from columns in list, repeats OK
A = M([1,2,3,4,5,6,7,8,9,10,11,12])
Vector Operations
A.matrix_from_rows([2,5,1])
coerce list to element of M, a 3
4 matrix over QQ
new matrix from rows in list, out-of-order OK
u = vector(QQ, [1, 3/2, -1])
M.basis()
A.matrix_from_rows_and_columns([2,4,2],[3,1])
v = vector(ZZ, [1, 8, -2])
M.dimension()
common to the rows and the columns
linear combination
2*u - 3*v
M.zero_matrix()
all rows as a list of tuples
u.dot_product(v)
A.rows()
all columns as a list of tuples
order: u v
A.columns()
u.cross_product(v)
Matrix Operations
inner product matrix from parent
A.submatrix(i,j,nr,nc)
u.inner_product(v)
vector as a result
linear combination
start at entry (i,j), use nr rows, nc cols
u.pairwise_product(v)
5*A+2*B
A.inverse(), A^(-1), ~A, singular is ZeroDivisionError
Python-style list slicing
Euclidean norm
A[2:4,1:7],
A[0:8:2,3::-1]
u.norm() == u.norm(2)
sum of entries
u.norm(1)
A.transpose()
entry-by-entry complex conjugates
u.norm(Infinity)
maximum entry
A.conjugate()
Combining Matrices
converts the rows of matrix A
A.conjugate_transpose()
A.gram_schmidt()
A in first columns, matrix B to the right
A.augment(B)
transpose + reverse orderings
A.antitranspose()
A in top rows, B below; B can be a vector
A.stack(B)
matrix of cofactors
A.adjoint()
Matrix Constructions
Diagonal, A upper left, B lower right
A.block_sum(B)
restriction to invariant subspace V
A.restrict(V)
Multiples of B, arranged as in A
Caution: Row, column numbering begins at 0
A.tensor_product(B)
A = matrix(ZZ, [[1,2],[3,4],[5,6]])
Row Operations
3
2 over the integers
Scalar Functions on Matrices
Row Operations: (change matrix in place)
B = matrix(QQ, 2, [1,2,3,4,5,6])
A.rank(),
A.right_nullity()
2 rows from a list, so 2
3 over rationals
Caution: first row is numbered 0
A.left_nullity() == A.nullity()
A.rescale_row(i,a)
a*(row i)
C = matrix(CDF, 2, 2, [[5*I, 4*I], [I, 6]])
A.determinant() == A.det()
a*(row j) + row i
complex entries, 53-bit precision
A.add_multiple_of_row(i,j,a)
A.permanent(),
A.trace()
zero matrix
Z = matrix(QQ, 2, 2, 0)
A.swap_rows(i,j)
Euclidean norm
A.norm() == A.norm(2)
Each has a column variant, row col
D = matrix(QQ, 2, 2, 8)
largest column sum
A.norm(1)
For a new matrix, use e.g.
diagonal entries all 8, other entries zero
B = A.with_rescaled_row(i,a)
largest row sum
A.norm(Infinity)
block_matrix([[P,0],[1,R]]), very flexible input
E =
Frobenius norm
A.norm(’frob’)
5
5 identity matrix
II = identity_matrix(5)
Echelon Form
I =
1, do not overwrite with matrix name
A.rref(), A.echelon_form(),
A.echelonize()
Matrix Properties
J = jordan_block(-2,3)
Note: rref() promotes matrix to fraction field
3
3 matrix,
2 on diagonal, 1’s on super-diagonal
.is_zero(); .is_symmetric(); .is_hermitian();
A = matrix(ZZ,[[4,2,1],[6,3,2]])
.is_square(); .is_orthogonal(); .is_unitary();
var(’x y z’); K = matrix(SR, [[x,y+z],[0,x^2*z]])
A.rref()
A.echelon_form()
symbolic expressions live in the ring SR
.is_scalar(); .is_singular(); .is_invertible();
1
2 1 0
1
0
2
.is_one(); .is_nilpotent();
.is_diagonalizable()
L = matrix(ZZ, 20, 80, {(5,9):30, (15,77):-6})
0 0 1
0
0 1
20
80, two non-zero entries, sparse representation

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2