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.

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

Computing matrix powers in Sage is illustrated by the example below.

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]

Matrix addition and multiplication:

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]