EnteringMatrices.mws

Creating Matrices and Vectors in Maple

Version .8 for Maple V R7.

Load pointers to functions in the linear algebra package.

> with(linalg):

Warning, the protected names norm and trace have been redefined and unprotected

Entering a matrix as a list of lists.

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

A1 := matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

Enter a vector - will be viewed as a column vector.

> v1 := vector([1, 2, 3]);

v1 := vector([1, 2, 3])

We could now multiply A1 times v1 by evalm(A1 &* v1);
Another form of the vector call is vector(3,1) producing a column vector of dim 3 with
initial entries 1.

> v2 := vector(3,1);

v2 := vector([1, 1, 1])

Enter a 2 by 3 matrix with entries taken in row major order from the list.

> A2 := matrix(2,3,[x,y,z,w,u,v]);

A2 := matrix([[x, y, z], [w, u, v]])

Enter a 2 by 2 matrix with all entries initialized to 0.

> A3 := matrix(2,2,0);

A3 := matrix([[0, 0], [0, 0]])

One can also define a function of row and column indices to initialize a matrix.

> f := (i,j) -> j * x^(i + j);

f := proc (i, j) options operator, arrow; j*x^(i+j)...

> A4 := matrix(2,2,f);

A4 := matrix([[x^2, 2*x^3], [x^3, 2*x^4]])

A 1 by 3 matrix; i.e. a row vector.

> v3 := matrix(1,3,4);

v3 := matrix([[4, 4, 4]])

Another form of a column vector.

> v4 := matrix(2,1,[ 5, 6]);

v4 := matrix([[5], [6]])

Matrices can be partially specified:

> A4 := matrix(2,3,[[x,y,z]]);

A4 := matrix([[x, y, z], [A4[2,1], A4[2,2], A4[2,3]...

And then updated with a for loop.

> for j from 1 to 3 do
A4[2,j] := x * y^j:
od:

> print(A4);

Nested loops are also possible to update all entries of a matrix.

matrix([[x, y, z], [x*y, x*y^2, x*y^3]])

Matrices can be stacked horizontally.

> A5 := augment(A2,A4);

A5 := matrix([[x, y, z, x, y, z], [w, u, v, x*y, x*...

Or vertically:

> A6 := stackmatrix(A2,v3);

A6 := matrix([[x, y, z], [w, u, v], [4, 4, 4]])

One can delete a range of rows from a matrix.

> delrows(A1,1..2);

(Use delcols for columns.)

matrix([[7, 8, 9]])

Block diagonal or diagonal matrices can also be easily generated.

> A6 := diag(lambda_1, lambda_2);

(These commands can be used with more than two arguments.)

A6 := matrix([[lambda_1, 0], [0, lambda_2]])

> A7 := diag(A6,A6):

One can create a 5 x 5 banded matrix by:

> band([a,b,c],5);

matrix([[b, c, 0, 0, 0], [a, b, c, 0, 0], [0, a, b,...

A 3 by 3 Jordan block with diagonal entry 5 can be generated by:

> JordanBlock(5,3);

matrix([[5, 1, 0], [0, 5, 1], [0, 0, 5]])

Extract a submatrix using rows 1..3 of A1 and columns 2..3.

> A8 := submatrix(A1,1..3,2..3);

A8 := matrix([[2, 3], [5, 6], [8, 9]])

Extract rows and columns as vectors.

> row(A8,2); col(A8,1);

vector([5, 6])

vector([2, 5, 8])

>

>