MAPLE HELPSHEETS: Matrix Algebra

MAPLE: Matrix Algebra


Click here if you are seeking to calculate Norms and Condition Numbers


  1. Whenever doing linear algebra on maple, first enter

    > with(linalg):

  2. For a list of commands available in the linalg package

    > ?linalg

  3. For help on any of the linalg commands, enter ?command, for example:

    > ?det

    > ?mulrow

    > ?addrow

    > ?matrix

    > ?vector

    > ?multiply

    > ?augment

  4. To define a matrix A, say 6 by 4 (6 rows and 4 columns) without specifying its entries:

    > A := matrix(6,4);

  5. Example: to create matrix A while specifying its entries:

    A = 6 3 -2 1
    8 0 7 2
    9 5 4 -3

    > A := matrix( [ [6,3,-2,1], [8,0,7,2], [9,5,4,-3] ] ) ;

    Spaces are allowed but not required. Also, the command may span several lines.

    > A[3,4]; shows that -3 is stored in row 3 column 4 of A

    > A[3,4] := 9 ; stores 9 in row 3 column 4 of A

  6. Some common linear algebra commands. Suppose we have matrices A, B, and C:

    A = 6 3 -2 1
    8 0 7 2
    9 5 4 -3
    B = 7 2 0
    -5 3 4
    2 1 9
    6 -7 2
    C = 7 2 0
    -5 3 4
    2 1 9

    > A := matrix( [ [6,3,-2,1], [8,0,7,2], [9,5,4,-3] ] ) ;

    > B := matrix( [ [7,2,0], [-5,3,4], [2,1,9], [6,-7,2] ] ) ;

    > C := matrix( [ [7,2,0], [-5,3,4], [2,1,9] ] ) ;

    > det(C); gives the determinant of square matrix C

    > inverse(A); gives the inverse of matrix A

    > rank(A); gives the rank of matrix A

    > gaussjord(A); gives the Gauss-Jordan canonical form of matrix A

    > augment(A,C); augments two matrices A and C

    > multiply(A,B); matrix product AB

    > multiply(B,A); matrix product BA

  7. To view an existing matrix:

    > evalm(A);

  8. To multiply row r of matrix A by k:

    > A := mulrow( A, r, k ) ;

  9. To multiply column c of matrix A by k:

    > A := mulcol( A, c, k ) ;

  10. To replace row r1 of matrix A by k × (row r1) + (row r2), where k is a constant:

    > A := addrow( A, r1, r2, k ) ;

  11. To obtain the characteristic polynomial of a square matrix C:

    > p := charpoly(C, x) ; calls the resulting polynomial p

  12. To obtain eigenvalues of a square matrix C:

    > eigenvals(C,'radical');

  13. To obtain eigenvectors and eigenvalues of a square matrix C:

    > eigenvects(C,'radical');

  14. TO SOLVE A LINEAR SYSTEM of n equations for its n variables, you may define an n x (n+1) augmented matrix and then use the command gaussjord. For example, suppose we wish to solve the following system of 3 linear equations for its 3 unknowns x, y, and z:

    6x + 3y - 2z = 1

    8x + 7z = 2

    9x + 5y + 4z = -3

    > M := matrix( [ [6,3,-2,1], [8,0,7,2], [9,5,4,-3] ] ) ; gives

    M = 6 3 -2 1
    8 0 7 2
    9 5 4 -3

    > gaussjord(M);

    1 0 0 142 / 197
    0 1 0 -289 / 197
    0 0 1 -106 / 197

    As long as the identity matrix appears in the coefficient matrix portion, then the rightmost column gives the solution x, y, z.

    If you use a decimal point anywhere, the solution will be given in decimal form.

    Alternatively, you can solve the linear system Ax = b where A is an n x n coefficient matrix and b is the n-term constant vector by:

    > A := matrix( [ [6,3,-2], [8,0,7], [9,5,4] ] ) ; defines coefficient matrix A

    A = 6 3 -2
    8 0 7
    9 5 4

    > b := vector( [1,2,-3] ) ; defines constant vector b

    > linsolve(A,b); gives the solution of system Ax = b in vector form

    > det(A); gives the determinant of coefficient matrix A

    > AI := inverse(A); gives the inverse A-1 of coefficient matrix A and calls it AI

    > multiply(AI,b); multiplies A-1b, which is the solution x of Ax = b

  15. The linalg package has many other commands. For a complete list, enter

    > ?linalg;


Go to the Maple Help Sheet Index

Written and Maintained by

Prof. Kevin G. TeBeest
Applied Mathematics
Kettering University

Last modified: 06/07/2012

Maple® is a registered trademark of Waterloo Maple Software.

Copyright © 1997–2023 Kevin G. TeBeest. All rights reserved.