t> LINEAR ALGEBRA EXAMPLES
b>
t> This section gives a brief overview of Maple's linear algebra
t> facilities.  We start off with a lesson on the Maple data types used in
t> linear algebra, and then take a quick overview of functions available
t> in the linalg package.
b>
c1>
t> Arrays
b>
t> Before we learn about what sort of functionality is available in linear
t> algebra, we need to understand about Maple arrays. An array is a
t> high-level Maple structure (of one or more dimensions) containing a
t> collection of individual elements. Each dimension of an array has
t> ranges predefined by the user. A simple way to think of arrays is: in
t> one dimension as lists, and in two dimensions as lists of lists. Also,
t> a vector is equivalent to a one-dimensional array with a range starting
t> at 1, and a matrix is equivalent to a two-dimensional array with both
t> ranges starting at 1.
b>
t> Arrays can be created with the array command. The individual elements
t> of an array are either be specified beforehand or left as unknowns. The
t> following is an example of a 3 x 3 array that contains predefined
t> elements.
b>
c1>
x> array(1..3, 1..3, [[a,b,c],[d,e,f],[g,h,i]]);
t> As you can see, Maple prints out the array in two-dimensional form. In
t> the linalg package there are commands that allow you to create a matrix
t> or a vector, but since they are just special cases of the array
t> command, we will not go into them at this time.
b>
c1>
t> Special Types of Arrays
b>
t> There are a few special types of arrays (or matrices) that can be
t> automatically generated in Maple. Symmetric, antisymmetric, sparse,
t> diagonal, and identity matrices are all supported. To create such
t> matrices, define the necessary elements and add the matrix type as an
t> additional option to the array command.
b>
c1>
x> array(1..2, 1..2, identity);
x> array(1..2, 1..6, [(1,3)=p,(2,4)=r], sparse);
c1>
t> Manipulating Elements of Arrays
b>
t> In earlier chapters we learned a little bit about how Maple evaluates
t> different types of objects. There is one major difference in the
t> evaluation rules for arrays. If you assign an array to a
t> variable name, and then you type in that variable, the result is not
t> the array itself, but the variable name to which it is assigned. This
t> is called "last name evaluation". Two commands that can be used to
t> force evaluation to the array are op and evalm (for evaluate a
t> matrix).
b>
c1>
x> M := array(1..2, 1..2, [[3,4],[6,5]]);
c1>
x> op(M);
x> evalm(M);
h> M := 'M';
t> Last name evaluation also holds for Maple tables and procedures. The
t> advantages and disadvantages of last name evaluation are not discussed
t> here.
b>
c1> 
t> Individual elements of arrays are referenced by specifying at which
t> row and which column the desired element is. Note though, that when you
t> reference an element of an array, you do not need to worry about last
t> name evaluation. As well, elements of an array can be redefined after
t> the array is created by assigning new values to their referenced
t> names.
b>
t> The following example demonstrates referencing of array elements.
b>
c1>
x> M := array(1..2, 1..3, [[2,8,32],[45,-1,0]]);
x> M[1,3];
x> M[2,3] := x-3;
x> op(M);
h> M := 'M';
c1>
t> Useful Commands
b>
t> As mentioned earlier, the linalg package is full of useful commands. To
t> begin let's load in pointers to all those functions with the "with"
t> command.
b>
c1>
x> with(linalg);
c1>
b>
t> Now all of the above functions are available for immediate use.
b>
c1>
t> First, let's define three matrices upon which to work.
b>
x> A := array(1..3, 1..3, [[1,x,-x],[-x,0,x],[0,1,x]]);
c1>
x> B := array(1..3, 1..3, [[y,y,-1],[-y,y,0],[y,0,0]]);
c1>
x> C := array(1..2, 1..2, [[x,y],[y,x]]);
c1>
t> Basic matrix arithmetic is available. Matrices can be added.
b>
x> add(A, B);
c1>
t> And they can be multiplied.
b>
x> multiply(A, B);
c1>
t> As well, standard matrix operations are available.
b>
t> Transposition:
b>
x> op(A);
x> transpose(A);
c1>
t> Inversion:
b>
x> inverse(A);
c1>
t> And determinant:
b>
x> det(A);
c1>
t> Eigenvectors and eigenvalues can be determined.
b>
x> op(C);
x> eigenvals(C);
c1>
t> Other commands in the linalg package include those for manipulating
t> rows, columns, and submatrices. The following are examples of just a
t> few of these commands.
b>
t> Taking a submatrix.
b>
x> op(A);
x> Asub := submatrix(A, 1..2, 2..3);
c1>
t> Appending one matrix to the left of another:
b>
x> augment(A, B);
c1>
t> Stacking two matrices, one on top of the other:
b>
x> stack(A, B);
c1>
t> And pivoting a matrix about a non-zero element:
b>
x> op(A);
x> pivot(A, 2, 3);
c1>
t> There are many, many more commands available for arrays, vectors,
t> and matrices. Please consult the on-line documentation or your Maple
t> manuals for more details.
b>
t> Questions
b>
c2>
q> With one command, define a 2 by 2 matrix with the elements (reading left to
q> right, top to bottom) a, b, c, and d, and find its determinant.
a> det(array(1..2, 1..2, [[a,b],[c,d]]));
c2>
q> Using the 3 by 3 matrix A (defined earlier) and the commands, inverse, 
q> multiply, and array, show that a matrix multiplied by its inverse
q> equals the identity matrix of the appropriate dimensions.
a> multiply(A, inverse(A)) = array(1..3, 1..3, identity);
eoq>
h> A := 'A';
h> B := 'B';
h> C := 'C';
h> Asub := 'Asub';
eof>
