Application: a simple cipher using matricesMatrices with MapleIntroduction to the linear algebra package

Introduction to the linear algebra package

Ever since high school, you have known and loved systems of simultaneous linear equations. One way to solve linear systems is to use Maple's solve command. For example, if you set

     eqns := {u+v+w=1, 3*u+v=3, u-2*v-w=0}; 

then you can solve(eqns); to get numerical values for the variables u, v, and w. Try this by copying the example into your Maple session with the mouse.

Matrices are often an efficient way to handle linear systems. Maple views a matrix as a list of lists. For example, you can define a matrix with the name A via

     A:=matrix([[9,13,17],[14,18,22]]);

Alternatively, you can specify the number of rows and the number of columns and give a single list (which Maple will then break up into the appropriate rows). Thus, another way to specify the above matrix is

     A:=matrix(2,3,[9,13,17,14,18,22]);

Still another way to define a matrix is to specify a formula for the entries in terms of the row and column indices. For instance, the above matrix can be generated via

     A:=matrix(2,3,(i,j)->5*i+4*j);

After you have defined the above matrix A, try the command A; to see how Maple responds. Because Maple arrays obey the special procedure of last name evaluation, you probably have to ask Maple for either eval(A); or evalm(A); to get the response you expected.

Maple knows the standard matrix operations of addition, subtraction, multiplication, scalar multiplication, forming inverses, and exponentiation. For the 2×3 matrix A that you defined above, try evalm(A+A); and evalm(4*A); for example.

Maple uses the asterisk * for scalar multiplication and the symbol &* for matrix multiplication. Since A is a 2×3 matrix, it is not possible to multiply A by itself. If you ask Maple for A^2; does it complain? Now try evalm(A^2); for comparison.

The above matrix A is a 2×3 matrix, so its transpose is a 3×2 matrix. Therefore you can multiply A by its transpose (in either order). Try evalm(A&*transpose(A)); to evaluate the product. An alternate syntax that computes the same result is multiply(A, transpose(A));. (If this command does not work, then you probably forgot to load the linear algebra package via with(linalg):.) If you form the product in the other order via multiply(transpose(A), A);, do you get the same answer?

Define B:=evalm(A&*transpose(A));. What does Maple do if you ask for 1/B;? How about B^(-1);? What about evalm(1/B);?

You can also use inverse(B); to display the inverse of a matrix. What happens if you ask for inverse(transpose(A)&*A);? Can you now predict what det(transpose(A)&*A); will return?

Maple can perform operations on the individual entries of a matrix. Try map(sin,A); map(evalf,%); for example. You can also refer to individual entries of a matrix. For example, A[2,3]; picks out the entry of A that is in the second row and the third column.

Exercise

Try the following Maple commands.

     Digits:=3; 
     C:=hilbert(4): 
     inverse(map(evalf,C)); 
     inverse(C); 

These commands compute (a) the inverse of a three-digit numerical approximation to the 4×4 Hilbert matrix and (b) the exact inverse of the 4×4 Hilbert matrix. Do you see any resemblance between the two inverses? Does this explain the terminology "ill-conditioned"? 


logo The Math 696 course pages were last modified April 5, 2005.
These pages are copyright © 1995-2005 by Harold P. Boas. All rights reserved.
 
Application: a simple cipher using matricesMatrices with MapleIntroduction to the linear algebra package