Maple examples for linear algebra ================================= # signs introduce comments (you don't need to type these) M := Matrix([[1, 2, 3], [4, 5, 6]]); # by rows A := <<0, -2, -2, -2> | <-3, 1, 1, -3> | <1, -1, -1, 1> | <2, 2, 2, 4>>; # by columns M := Matrix(3, 3, [[4, 7, 3], [3, 0, 6], [2, 2, 4]]); M.M; # matrix multiplication N := Matrix(3, 5, [[4, 7, 3, 3, -22], [3, 0, 6, 7, 8], [2, 2, 4, 11, 6]]); ReducedRowEchelonForm(N); HermiteForm(N); HermiteForm(N, output=['H', 'U']) # get transformation matrix as well (H = U.N) N2 := Matrix([N, IdentityMatrix(3)]); # pad N on the right E2 := ReducedRowEchelonForm(E2); E := SubMatrix(E2, 1 .. 3, 1 .. 5); U := SubMatrix(E2, 1 .. 3, 6 .. 8); # the transformation matrix Equal(U . N, E); # should return "true" A := <<0, -2, -2, -2> | <-3, 1, 1, -3> | <1, -1, -1, 1> | <2, 2, 2, 4>>; JordanForm(A, output = ['J', 'Q']); J,Q = JordanForm(A, output = ['J', 'Q']); # store the answer Equal(A, Q.J.Q^(-1)); # should return "true" B := <<0, 32, -2, -2> | <-3, 1, 1, -3> | <1, -1, -1, 1> | <2, 2, 2, 4>> Sage examples for linear algebra ================================= # again, signs introduce comments (you don't need to type these) #Vectors and matrices A = Matrix(QQ, [[1,2,3],[3,2,1],[1,1,1]]) A[0,0] A.det() A.echelon_form() matrix.identity(3) B=A.augment(_). #Pad _ on the left C=B.rref() B[[0,1,2],[3,4,5]] #Extract the transformation matrix matrix(QQ,2,[1,2,3,4,5,6]); #Input matrix by only giving one vector A.left_kernel() A.right_kernel() w=vector(QQ, [1,2,4]) A*w w*A ##The matrix A was created as a matrix over the rationals. If no ring is specified, sage tries to choose an appropriate ring. For example v=vector([1,2,4]) # is created as a vector over the integers, and x=vector([1,2,1/4]) x.base_ring() # is created as a vector over the rationals. A*v x*A ### Now let us consider A over F_2 B=A.change_ring(GF(2)) A.base_extend(GF(2)) B.base_extend(GF(4)) B*x B*v ### Now let us consider A over Z C=A.change_ring(ZZ) C.smith_form() C.hermite_form() ###Jordan form A.jordan_form() ## But what if it does not exist over Q? You can go to Qbar A=Matrix([[0,-1],[1,0]] A.change_ring(QQbar) _.jordan_form() ###########Vectorspaces V = VectorSpace(QQ,4) S = V.subspace([V([1,1,0,0]),V([1,0,0,0]), V([0,1,0,0])]) T = V.subspace([V([1,2,3,4]),V([5,6,7,8]), V([9,1,0,1])]) T.intersection(S) T+S _==V W = span([[1,2,3], [4,5,6]], ZZ)