LESSON 1: BASIC INSTRUCTIONS TO USE MAPLE FOR LINEAR ALGEBRA

K.P.SATAGOPAN

Every MAPLE command must be followed by a semicolon to see the output of the command. If you still want the command to be executed and do not want to see the output you can use a colon after the command.

For example,

> 2+3;

5

> 2+3:This did not show me the output 5.

1. To input matrices.

We first include the LinearAlgebra package in MAPLE to make calculations easier by typing

>

> with (LinearAlgebra);

>

[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, Column...

> with(linalg);

Warning, the previous binding of the name GramSchmidt has been removed and it now has an assigned value

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

[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...

A:=

This tells Maple that you are going to define a variable A.

Each row of a matrix is entered in square brackets with a comma separating each entry in the row. Each row entered in square brackets are separated by commas .   You also have to tell MAPLE that you are going to enter a matrix by typing "matrix" before you enter the rows.

Example:

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

A := matrix([[1, 2], [4, 3]])

> B:= matrix([[1,2],[0,1],[4,5]]);

B := matrix([[1, 2], [0, 1], [4, 5]])

In entering a matrix, if you do not say matrix in the command, but you have entered the rows, Maple will recognize that as a variable A. But if you want to see A as a matrix then you have to say matrix(A) in the command line. The matrix A will be exibited as a matrix.

You can recall any specific entry in a matrix that you have defined:

We have defined matrix B above. Suppose I want to see what the (2,2) entry in that matrix is then I type

> B[2,2];

1

Note that you type the location 2,2 in square brackets.

You can also generate matrices by defining the (i,j) entry in a matrix.

Example:

First we define the function that will generate the (i,j) entry.

> f:=(i,j)->3*i-2*j;

f := proc (i, j) options operator, arrow; 3*i-2*j end proc

>

I want to generate a 3X4 matrix whose (i,j) entry is 3i-2j.

> C:=matrix(3,4,f);

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

>

>

Note that the syntax for the above command is as follows:

The first argument  is # of rows. ( This should always be a positive integer)

The second argument is the # of columns.( This should always be a positive integer)

The third is the function that describes the (i,j) element.

Augmenting matrices together;

Suppose I want to augment two matrices of the same order (dimension) say A which is already defined and E,

where

> E:=matrix([[1,4],[0,5]]);

E := matrix([[1, 4], [0, 5]])

I want to augment matrix A with matrix E. Of course A and E should have the same number of rows.

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

A := matrix([[1, 2], [4, 3]])

> augment(A,E);

matrix([[1, 2, 1, 4], [4, 3, 0, 5]])

To add matrices:

> evalm(A+E);

matrix([[2, 6], [4, 8]])

To find the product AB of two matrices:

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

A := matrix([[1, 2, 3], [0, 9, 4]])

To see the matrix A you need to type

> evalm(A);

matrix([[1, 2, 3], [0, 9, 4]])

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

B := matrix([[1, 2], [2, 5], [1, 1]])

To find the product you use &* as the operator and also "evalm" to say its matrix product.

> evalm(A&*B);

matrix([[8, 15], [22, 49]])

To find the Transpose:

> transpose(A);

matrix([[1, 0], [2, 9], [3, 4]])

To find the inverse of A:

> B:=matrix([[1,2],[3,4]]);

B := matrix([[1, 2], [3, 4]])

> evalm(1/B);

matrix([[-2, 1], [3/2, (-1)/2]])

> evalm(1/A);

Error, (in ) singular matrix

The error is because non-square matrices do not have inverses.

To solve a system of equations directly , without matrices:

> solve({x+2*y=2,3*x-3*y=3},{x,y});

{y = 1/3, x = 4/3}

The above system had a unique solution.

If a system has infinite number of solutions and you want to prescribe the free variable, you can do that as follows:

> solve({x+y+2*z-5*w=3,2*x+5*y-z-9*w=-3,2*x+y-z+3*w=-11,x-3*y+2*z+7*w=-5},{x,y,z,w});

{z = 3+2*w, y = 2+3*w, x = -5-2*w, w = w}

You notice that the solution is in terms of 'w'. If we want the solution in terms of 'x' we can say the following:

> solve({x+y+2*z-5*w=3,2*x+5*y-z-9*w=-3,2*x+y-z+3*w=-11,x-3*y+2*z+7*w=-5},{y,z,w});

{w = -1/2*x-5/2, z = -x-2, y = -3/2*x-11/2}

You see the solution is in terms of 'x'.