LAexamples.mw

 

Using Maple to learn Linear Algebra 

Maple has a number of facilities that can help you get proficient in linear algebra. There are special Student versions of some of the packages, and there are some Tutors. 

 

First we load the Linear Algebra part of the Student package. As usual, the first statement i a restart statement. 

> restart;
 

> with(Student[LinearAlgebra]);
 

[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
[`&x`, `.`, AddRow, AddRows, Adjoint, ApplyLinearTransformPlot, BackwardSubstitute, BandMatrix, Basis, BilinearForm, CharacteristicMatrix, CharacteristicPolynomial, ColumnDimension, ColumnSpace, Compa...
 

 

As you can see, there are many commands. In contrast to the full LinearAlgebra package this package has a restricted number of options to each command, meaning that they are easier to use. Some of the general commands from the Linear Algebra package have been given new names, which explain what they do. 

Here are some examples. 

 

Row operations 

Row operations can be carried out step by step using the commands from Students[LinearAlgebra]. the following examples should be self-explanatory. 

 

 

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

Matrix(%id = 135828376)
 

> SwapRow(A,1,3);
 

Matrix(%id = 135967576)
 

> MultiplyRow(A,3,1/3);
 

Matrix(%id = 135990460)
 

> AddRow(A,3,1,-3);
 

Matrix(%id = 136011728)
 

 

These three commands, which implement the three basic row operations, are in the LinearAlgebra package covered by one command, RowOperations, with many more options. 

 

There is a command called Pivot, which implements pivoting around an entry, meaning that by using row operations the entries both below and above the pivot position are changed to zeroes. Here is an example using the matrix above, and the entry in the second row and third column as pivot. Note that the entry is not scaled to be 1. 

 

 

> Pivot(A,2,3);
 

Matrix(%id = 136045708)
 

 

Echelon form and reduced echelon form 

 

What we call finding the echelon form of a matrix is in Maple called Gaussian elimination. Here it is applied to the matrix A above. 

 

 

> GaussianElimination(A);
 

Matrix(%id = 136250388)
 

The reduced row echelon form is obtained as follows: 

 

 

> ReducedRowEchelonForm(A);
 

Matrix(%id = 136325808)
 

 

There are two interactive tutors that you can use either to perform the reductions on your own, or what Maple do it for you. They are usefull for practice. Once you give the command, a new window opens, and it is in this window that the interaction takes place. The two commands are 

 

 

> GaussianEliminationTutor();
 

> GaussJordanEliminationTutor();
 

 

Solving systems of linear equations 

 

Suppose we regard the above matrix A as the augmented matrix for a linear system of three equations in three unknown. Then we can solve this system by the command 

 

> LinearSolve(A);
 

Vector[column](%id = 136453640)
 

If we want to specify the coefficient matrix and the right hand side, then it can be done as follows. 

 

> B:=Matrix([[1,2,2],[2,0,5],[4,3,2]]); b:=Vector([1,2,3]);
 

Matrix(%id = 140726700) 

Vector[column](%id = 135391108)
 

> LinearSolve(B,b);
 

Vector[column](%id = 136758584)
 

 

If there are free variables, then you can specify them. Here is an example with a homogeneous equation. 

 

> C:=Matrix([[2,3,5,6],[-2,3,3,3]]);nul:=Vector([0,0]);
 

Matrix(%id = 140805020) 

Vector[column](%id = 138557856)
 

> LinearSolve(C,nul,free=x);
 

Vector[column](%id = 140833072)
 

 

Warning: The algorithms used by Maple may not always choose the free variable that you expect.  Here is an example: 

 

 

> X:=Matrix([[90,88,41,70],[80,-82,91,-32],[19,-70,29,-1]]); z:=ZeroVector(3);
 

Matrix(%id = 139682212) 

Vector[column](%id = 136806960)
 

> ReducedRowEchelonForm(Matrix([X,z]));
 

Matrix(%id = 140992540)
 

> LinearSolve(X,z,free=x);
 

Vector[column](%id = 138267748)
 

 

There is also a tutor available for practicing solving linear equations. The command is 

 

 

> LinearSolveTutor();
 

>
 

 

First you have to decide, by choosing an option in a window, whether to base the solution on the echelon form or the reduced echelon form. I recommend the latter, thus choose Gauss Jordan Elimination. This tutor is probably not at useful as the ones practicing finding the (reduced) echelon form.  

 

It is possible to visualize small linear systems as systems of (non)-intersecting lines and planes. The tutor illustrating this is called by the command 

 

 

> LinearSystemPlotTutor();
 

Plot
 

>