⇤ ← Revision 1 as of 2008-02-23 16:04:47
1111
Comment:
|
3963
|
Deletions are marked like this. | Additions are marked like this. |
Line 63: | Line 63: |
== Kernels == The kernel is computed by applying the kernel method to the matrix object. The following examples illustrate the syntax. {{{ sage: M = MatrixSpace(IntegerRing(),4,2)(range(8)) sage: M.kernel() Free module of degree 4 and rank 2 over Integer Ring Echelon basis matrix: [ 1 0 -3 2] [ 0 1 -2 1] }}} A kernel of dimension one over $ \mathbb{Q}$ : {{{ sage: A = MatrixSpace(RationalField(),3)(range(9)) sage: A.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 -2 1] }}} A trivial kernel: {{{ sage: A = MatrixSpace(RationalField(),2)([1,2,3,4]) sage: A.kernel() Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: [] sage: M = MatrixSpace(RationalField(),0,2)(0) sage: M [] sage: M.kernel() Vector space of degree 0 and dimension 0 over Rational Field Basis matrix: [] sage: M = MatrixSpace(RationalField(),2,0)(0) sage: M.kernel() Vector space of dimension 2 over Rational Field }}} Kernel of a zero matrix: {{{ sage: A = MatrixSpace(RationalField(),2)(0) sage: A.kernel() Vector space of degree 2 and dimension 2 over Rational Field Basis matrix: [1 0] [0 1] }}} Kernel of a non-square matrix: {{{ sage: A = MatrixSpace(RationalField(),3,2)(range(6)) sage: A.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 -2 1] }}} The 2-dimensional kernel of a matrix over a cyclotomic field: {{{ sage: K = CyclotomicField(12); a = K.gen() sage: M = MatrixSpace(K,4,2)([1,-1, 0,-2, 0,-a^2-1, 0,a^2-1]) sage: M [ 1 -1] [ 0 -2] [ 0 -zeta12^2 - 1] [ 0 zeta12^2 - 1] sage: M.kernel() Vector space of degree 4 and dimension 2 over Cyclotomic Field of order 12 and degree 4 Basis matrix: [ 0 1 0 -2*zeta12^2] [ 0 0 1 -2*zeta12^2 + 1] }}} A nontrivial kernel over a complicated base field. {{{ sage: K = FractionField(MPolynomialRing(RationalField(),2,'x')) sage: M = MatrixSpace(K, 2)([[K.gen(1),K.gen(0)], [K.gen(1), K.gen(0)]]) sage: M [x1 x0] [x1 x0] sage: M.kernel() Vector space of degree 2 and dimension 1 over Fraction Field of Multivariate Polynomial Ring in x0, x1 over Rational Field Basis matrix: [ 1 -1] }}} Other methods for integer matrices include: `elementary_divisors`, `smith_form` (for the Smith normal form), `echelon` (a method for integer matrices) for the Hermite normal form, `frobenius` for the Frobenius normal form (rational canonical form). There a many methods for matrices over a field such as $ \mathbb{Q}$ or a finite field: `row_span`, `nullity`, `transpose`, `swap_rows`, `matrix_from_columns`, `matrix_from_rows`, among many others. |
Linear Algebra
SAGE has extensive linear algebra capabilities.
Vector Spaces
The VectorSpace command creates a vector space class, from which one can create a subspace. Note the basis computed by Sage is row reduced.
Computing matrix powers in Sage is illustrated by the example below. Matrix addition and multiplication:
The kernel is computed by applying the kernel method to the matrix object. The following examples illustrate the syntax. A kernel of dimension one over \mathbb{Q} : A trivial kernel: Kernel of a zero matrix: Kernel of a non-square matrix: The 2-dimensional kernel of a matrix over a cyclotomic field: A nontrivial kernel over a complicated base field. Other methods for integer matrices include: elementary_divisors, smith_form (for the Smith normal form), echelon (a method for integer matrices) for the Hermite normal form, frobenius for the Frobenius normal form (rational canonical form). There a many methods for matrices over a field such as \mathbb{Q} or a finite field: row_span, nullity, transpose, swap_rows, matrix_from_columns, matrix_from_rows, among many others. sage: V = VectorSpace(GF(2),8)
sage: S = V.subspace([V([1,1,0,0,0,0,0,0]),V([1,0,0,0,0,1,1,0])])
sage: S.basis()
[
(1, 0, 0, 0, 0, 1, 1, 0),
(0, 1, 0, 0, 0, 1, 1, 0)
]
sage: S.dimension()
2
Matrix arithmetic
sage: R = IntegerModRing(51)
sage: M = MatrixSpace(R,3,3)
sage: A = M([1,2,3, 4,5,6, 7,8,9])
sage: A^1000*A^1007
[ 3 3 3]
[18 0 33]
[33 48 12]
sage: A^2007
[ 3 3 3]
[18 0 33]
[33 48 12]
sage: R = IntegerModRing(51)
sage: M = MatrixSpace(R,3,3)
sage: A = M([1,2,3, 4,5,6, 7,8,9])
sage: B = M([1,0,1, 0,1,0, 1,1,1])
sage: A+B
[ 2 2 4]
[ 4 6 6]
[ 8 9 10]
sage: A*B
[ 4 5 4]
[10 11 10]
[16 17 16]
sage: -7*B
[44 0 44]
[ 0 44 0]
[44 44 44]
Kernels
sage: M = MatrixSpace(IntegerRing(),4,2)(range(8))
sage: M.kernel()
Free module of degree 4 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1 0 -3 2]
[ 0 1 -2 1]
sage: A = MatrixSpace(RationalField(),3)(range(9))
sage: A.kernel()
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[ 1 -2 1]
sage: A = MatrixSpace(RationalField(),2)([1,2,3,4])
sage: A.kernel()
Vector space of degree 2 and dimension 0 over Rational Field
Basis matrix:
[]
sage: M = MatrixSpace(RationalField(),0,2)(0)
sage: M
[]
sage: M.kernel()
Vector space of degree 0 and dimension 0 over Rational Field
Basis matrix:
[]
sage: M = MatrixSpace(RationalField(),2,0)(0)
sage: M.kernel()
Vector space of dimension 2 over Rational Field
sage: A = MatrixSpace(RationalField(),2)(0)
sage: A.kernel()
Vector space of degree 2 and dimension 2 over Rational Field
Basis matrix:
[1 0]
[0 1]
sage: A = MatrixSpace(RationalField(),3,2)(range(6))
sage: A.kernel()
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[ 1 -2 1]
sage: K = CyclotomicField(12); a = K.gen()
sage: M = MatrixSpace(K,4,2)([1,-1, 0,-2, 0,-a^2-1, 0,a^2-1])
sage: M
[ 1 -1]
[ 0 -2]
[ 0 -zeta12^2 - 1]
[ 0 zeta12^2 - 1]
sage: M.kernel()
Vector space of degree 4 and dimension 2 over Cyclotomic Field of order 12
and degree 4
Basis matrix:
[ 0 1 0 -2*zeta12^2]
[ 0 0 1 -2*zeta12^2 + 1]
sage: K = FractionField(MPolynomialRing(RationalField(),2,'x'))
sage: M = MatrixSpace(K, 2)([[K.gen(1),K.gen(0)], [K.gen(1), K.gen(0)]])
sage: M
[x1 x0]
[x1 x0]
sage: M.kernel()
Vector space of degree 2 and dimension 1 over Fraction Field of Multivariate Polynomial Ring in x0, x1 over Rational Field
Basis matrix:
[ 1 -1]