Matrices

Matrices - Matrices, including basic operations, solving linear systems, and eigenvalues and eigenvectors.

This session introduces matrices and some basic operations in linear algebra. A hyperlink allows you to download the Maple worksheet.

Linear Algebra

The text has an excellent section introducing linear algebra. This can be found in Chapters 6 and 7, which provides the basic commands for linear algebra. You begin any session where you are going to ask Maple to perform operations in linear algebra by entering the Maple linear algebra package. (By using a ; instead of a :, you see the functions that this particular package has and it is an extensive package. Some of these topics will be familiar, but many may not be. Once again, the Maple help can be used to learn more about a particular topic of interest and how to use the Maple package.)

> with(linalg);

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

Basic Matrix Operations

There are several ways that you can enter a matrix.

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

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

If your matrix has a certain structure that can be easily programmed in, then the array command with a simple Maple program is an easier way to produce your matrix. The array command creates the dimensions of the matrix, then you can write a program to fill in the entries. Maple has for and do loops as shown below. A do loop is ended with the command od:

> C := array(1..2,1..3):

> for i to 2 do

> for j to 3 do

> C[i,j] := x^i + j - i

> od: od:

> print(C);

> evalm(2*A + B + C);

Note that Maple does have several special matrix forms that can be entered more easily with other commands, such as a diagonal matrix.

> Q := diag(4, -5, 3);

Matrix multiplication requires &*. Clearly, the matrices above cannot be multiplied together, but we can multiply the transpose of one with another.

> F := evalm(A&*transpose(B)); G := evalm(transpose(A)&*C);

Other matrix operations are very easy with many of the commands fairly obvious.

> inverse(F);

> det(F); det(G); Note that G is singular.

> trace(F);

Solving Linear Systems

Maple has a couple ways to solve linear systems of equations. Suppose we want to solve the linear system Ax = b, where

> A := matrix(3,3,[1, 0, 2, 3, 4, -2, 2, -1, 0]); b := [2, 6, -3];

> x := linsolve(A, b);

An alternate method using Gaussian elimination can be done as follows:

> A1 := augment(A, b);

> B := gausselim(A1);

> x := backsub(B);

Maple readily handles the infinite or no solution cases for linear systems also.

> A2 := matrix(3,3,[2, -1, 4, 3, 0, 1, 1, 1, -3]);

> b1 := [2, 4, 2]; b2 := [1, 3, -1];

> x1 := linsolve(A2,b1);

> x2 := linsolve(A2, b2);

> rank(A2);

Eigenvalues and Eigenvectors

Very useful information about matrices concerns their eigenvalues and eigenvectors.

> eig := eigenvectors(A);

The response gives the value of each eigenvalue, its multiplicity, and its corresponding eigenvector. We can readily acquire any of these components as follows:

> eig[2];

> eig[3][3];

The characteristic matrix and characteristic polynomial are found with the following commands.

> charmat(A, lambda); Characteristic matrix in the form lI - A

> charpoly(A, lambda); Characteristic polynomial det(lI - A)

> roots(%, lambda); Eigenvalues and multiplicities