Maple Tutorial for Linear Algebra

Introduction

On most platforms, Maple V is started by double-clicking on the Maple icon. However, in our Computer Lab in HH-3030/3056 you can simply type xmaple or xmaple & to start a Maple session. If you are familiar with the Unix environment you can create a Maple subdirectory and start Maple from within that subdirectory.

At the top of the window is the menu bar containing such menus as File and Edit . Immediately below the menu bar is the tool bar , which contains button-based shortcuts to common operations such as opening, saving, and printing. Immediately below the tool bar is the context bar which contains controls specific to the task you are currently performing. The next area is large and displays your worksheet, the region in which you work. At the bottom of the window is the status bar, which displays system information. The worksheet should have opened with the prompt (>) in the upper left corner. This worksheet can be viewed and downloaded from my home page. The URL is http://www.math.mun.ca/~drideout . If you download the worksheet, you should execute each of the commands, after the prompt (>), either one at a time or go to the menu bar, and then edit, and then execute the whole worksheet.

We will introduce Maple commands which will be useful in Mathematics 2050 or 2051. Maple V provides a wide range of special packages specially designed for students. For example, there are packages for calculus, statistics, number theory, group theory, and graph theory. One of the most frequently used packages is the linear algebra package, linalg . This package provides a complete set of commands for working with vectors and matrices.

First load the linear algebra package using the with command. If you do not wish to load the entire package, you can load selected routines from the package using the syntax

with(packagename, routine1, ..., routineN);

You can also use the long form of the routine name

packagename[routinename](...);

> with(linalg);

Warning, new definition for norm

Warning, new definition for trace

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

Note the many functions that are listed above. To find more information on any topic you can look at the help pages by typing ?topic . For example, ?addrow will show you clearly, with examples, how to use this function. Experiment, by executing the command ?addrow on a command line.

Solving Systems of Equations

An array is a generalization of the matrix data structure. The conversion between arrays and matrices is automatic, so following the creation of an array it can be used as a matrix.

Consider the 4x6 numeric matrix created using the array command.

> A:=array([[1,3,-2,0,2,0],[2,6,-5,-2,4,-3],[0,0,5,10,0,15],[2,6,0,8,0,18]]);

[Maple Math]

The above label A always refers to the above matrix unless we unassign the symbol A. Note the use of the semicolin (;). The semicolin is always needed in order to see the output. If you do not want to see the output, end the command with the colin (:) instead.

> A;

[Maple Math]

The matrix is not displayed. It is displayed using the evalm command.

> evalm(A);

[Maple Math]

The command print(A) will also work. The following command unassigns the symbol A.

> A:='A';

[Maple Math]

> evalm(A);

[Maple Math]

The above matrix can also be defined with the matrix command.

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

[Maple Math]

> B:=vector([0,-1,5,6]);

[Maple Math]

If A is the coefficient matrix and B the constant matrix of a system of 4 equations in 6 unknowns, then one way to solve the system is to form the augmented matrix.

> A_B:=augment(A,B);

[Maple Math]

Next we can row-reduce the matrix by using the commands addrow, mulrow, and swaprow , as many times as is necessary. The symbol (%) always refers to the latest output.

> addrow(%,1,2,-2);

[Maple Math]

> addrow(%,1,4,-2);

[Maple Math]

> mulrow(%,2,-1);

[Maple Math]

> addrow(%,2,3,-5);

[Maple Math]

> addrow(%,2,4,-4);

[Maple Math]

> swaprow(%,3,4);

[Maple Math]

> row_esc_form:=mulrow(%,3,-1/4);

[Maple Math]

We could have gotten to the same place in the computation by using the gausselim command, except that the leading numbers are not necessarily 1's.

> gausselim(A_B);

[Maple Math]

To put the matrix row_esc_form in reduced row eschelon form, we continue with the following computations.

> addrow(row_esc_form,2,1,2);

[Maple Math]

> addrow(%,3,1,-2);

[Maple Math]

As above, we can use one command in Maple to do the same thing. Either use the command rref or the following.

> gaussjord(A_B);

[Maple Math]

As you may have already guessed, Maple has one command to do all of the above at once.

> linsolve(A,B);

[Maple Math]

Note the three free variables, [Maple Math] . Another way to solve the system is to write the equations out, and use the solve command.

> eq1:=x1+3*x2-2*x3+2*x5=0;

[Maple Math]

> eq2:=2*x1+6*x2-5*x3-2*x4+4*x5-3*x6=-1;

[Maple Math]

> eq3:=5*x3+10*x4+15*x6=5;

[Maple Math]

> eq4:=2*x1+6*x2+8*x4+18*x6=6;

[Maple Math]

> solve({eq1,eq2,eq3,eq4},{x1,x2,x3,x4,x5,x6});

[Maple Math]

The free variables here are x2, x4, and x6. Show that the two solutions are equivalent. Another facility built into linalg can extract the coefficient matrix and the constant matrix from a system of linear equations.

> A:=genmatrix([eq1,eq2,eq3,eq4],[x1,x2,x3,x4,x5,x6],'B');

[Maple Math]

> evalm(B);

[Maple Math]

Matrix Algebra

> A:=matrix(3,3,a);

[Maple Math]

> B:=matrix(3,3,b);

[Maple Math]

> A+B;

[Maple Math]

> evalm(A+B);

[Maple Math]

> evalm(k*A);

[Maple Math]

> evalm(-A);

[Maple Math]

> transpose(A);

[Maple Math]

> A&*B;

[Maple Math]

> evalm(%);

[Maple Math]

How can we denote the identity matrix? We cannot use the symbol I , since it is reserved for [Maple Math] . Check the help page on the word alias .

> alias(Id=&*());

[Maple Math]

> zero:=matrix(3,3,0);

[Maple Math]

> evalm(zero+Id);

[Maple Math]

> evalm(A^2);

[Maple Math]

> A:=matrix(2,2,[a,b,c,d]);

[Maple Math]

> inverse(A);

[Maple Math]

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

[Maple Math]

> evalm(A^(-1));

[Maple Math]

> evalm(%%&*%); # Note (%%) refers to second last output. The stuff after the symbol # is a comment and is not executed on the command line.

[Maple Math]