% FILE anton0.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\par\noindent
This July 1994 document is available in versions which accompany 
either the 6th or the 7th edition of the text \cite{AR}.
This is for the \ARedition edition.
\smallskip

%After revision in order to achieve approval from 
%Anton and his publishers - Wiley - for its more widespread distribution,
%this approval will be recorded in the document
% APPROVAL GIVEN on 16 JUNE 1994.
Approval has been given (on 16 June 94) by the section of Wiley in charge of
Anton's textbooks for the posting of this document to
the Maple Share Library.
Because the document deliberately works the same examples as the
text and often quotes theorems in the form given in the text,
authors will be making every effort to improve the document along
lines approved by Wiley.
The copyright of items quoted from the text is with Wiley.
\smallskip

\par\noindent
Associate authors who have been involved with discussion,
planning, or classroom testing of this document are listed
in the footnote.
\footnote{Associate Authors/Checkers:
Australia -
F. Benyah, Monash University Gippsland;
R. Booth, Flinders University;
New Zealand -
L. Johnston, Victoria University Wellington;
Norway - 
I. Somme, Tromso.}
A set of Maple Worksheets, each one accompanying an individual topic
from the final Applications Chapter of \cite{AR} is in preparation.
Neither the authors, nor their respective universities,
accept any legal liability for any use beyond their universities.


\subsection*{Copyright Notice.}

The copyright for this document belongs to its authors.
Subject to conditions given immediately below,
permission is granted to any lecturer with a class for which
\cite{AR} is the prescribed text
and whose university library owns a copy of \cite{BEJ}
(i) to copy this document and updates from the Maple Share Library,
(ii) to print, and then to copy, paper versions 
and to distribute these to the class.
\begin{enumerate}
\item This Notice shall be retained and the document shall not be 
  modified in any way without the written permission of the authors: 
  additions and modifications to any Worksheet supplement will be provided
  to the authors, with permission for them to be 
  redistributed, via the Maple Share Library,
  with the same conditions as in this copyright.
\item No charge shall be made for copies, except to cover the cost
  of the medium on which it is distributed.
  This document shall not be reproduced for commercial purposes.
\item Copies of the printed document may only be provided to persons
  owning a copy of a linear algebra text \cite{AR} as in references at end. 
%This text is henceforth abbreviated to [AR].
%  The programs supplement on disk is available without this restriction.
\item All copies of this document that are distributed in printed form
  shall be bound in such a way that the first page shall include
  the title of the document, the name and affiliation of the authors,
  and this Copyright Notice.
\item These conditions shall apply to all persons 
  or institutions receiving copies of this document.
\end{enumerate}

\goodbreak
%\bigskip



This document {\bf is not an introduction to Maple}.
In this connection, useful books include:
\begin{itemize}
\item {\it Maple: First Leaves : a tutorial introduction to Maple} 
  (Waterloo, 1990);
\end{itemize}
and the item %by A. Heck \cite{He} and 
by W. Ellis et al. %\cite{El89}, 
\cite{El92} in the reference list.
These are materials which come with the Maple software,
as sold by its different distributors.\\
This document {\bf does not provide a systematic account of Maple}.
In this connection see:
\begin{itemize}
\item {\it Maple V Language Reference Manual} (Springer, 1991), 
  (abbreviated to {\it MRM} below);
\item {\it Maple V Library Reference Manual};
\end{itemize}
Public domain notes from the Share Library going way beyond
immediate needs include:
\begin{itemize}
\item M. Monagan {\it Programmming in Maple: the basics} (Maple Share Library: 1993).
%\item D. Harper {\it An introduction to Maple} (QMW, London: 1992).
%(Liverpool, 1990).
\end{itemize}
Students should have an exposure to Maple from Calculus before
moving to its linalg package.
  Particularly for students who use
  H. Anton {\it Calculus with analytic geometry} (Wiley)
  for their calculus text, the coverage in \cite{H}
  K. Harris {\it Discovering calculus with Maple} (Wiley: 1992)
  (in which the material follows the order of the topics in
   Anton's calculus text) would provide the right knowledge.
Many Engineering Maths students will be using Maple in other parts of
their courses, and then introductions such as those in
the very early parts of
\cite{CH} or \cite{KN} will also provide adequate introductions.

\smallskip

\noindent {\bf These ``Maple linalg ..." notes presuppose}
\begin{enumerate}
\item  {\bf The reader has a knowledge of Maple} at the level
  of \cite{H}, 
  or of the early Chapters of \cite{CH} or \cite{KN} or \cite{El92},
  or of Chapter 0 of \cite{J}.
  (The {\it First Leaves} book, % or {\it MRM}, 
  or Monagan's 
  %or Harper's 
  document both go considerably further than is needed.)
\item {\bf The reader has been introduced to linear algebra} similar to 
  the early Chapters of \cite{AR}, excluding determinants,
  but has had no exposure to Maple's linalg package.
\end{enumerate}
The material on determinants (Chapter 2),
on inner-product spaces (Chapter \ChIPS),
on eigenvalues (Chapter \ChEV) and the later material can be taught 
with the Maple given at the same time.
\smallskip

\noindent  There are books which treat the use of Computer Algebra (CA)
packages in connection with linear algebra.
The typography and exposition in these are better than in
handout notes such as this one.
Even where these are not mandatory text book purchases for students,
it is strongly recommended that they should be studied in the
library.
It is a condition of the Copyright of this document that
\cite{BEJ} shall be available in your library.
The authors of the book \cite{BEJ} state that ``we
were guided by the contents, terminology and general flow of"
\cite{AR}.
(There is a similar book, \cite{EJ}, for DERIVE 
instead of Maple.
DERIVE, along with Maple is a CA package:
for the flavour of it, and some others, see \cite{HWH},
though remember that this book is out-of-date now.)
Another book related to Maple is \cite{J}.
These notes are complementary to the other books.
The differences between these notes and the books include:
\begin{enumerate}
\item These notes are shorter than the books.
\item  These notes are for classes where 
(i) Maple lab participation is not compulsory;
(ii) the level of uptake of Maple
is left to the decision of the student, and where, as a consequence
some students would prefer less expensive notes
ahead of buying another book.
\item These notes are for a second course in linear algebra,
such as might be taken by engineering maths students.
\end{enumerate}
\smallskip

The authors do not judge Computer Algebra to be worth introducing for a
single linear algebra course. 
It is when several courses are using CA
that the advantages of keeping the linear algebra course with
the same software can be realised.
If simple numerical illustration
of points in linear algebra is all that is required then
a good general-purpose, widely-used numeric package is Matlab.
(See, however, \cite{M93} for evidence against this opinion.)


%\bigskip
%The Maple example programs supplement associated with these notes, 
%available on disk in Maple-readable format, includes:
%\begin{enumerate}
%\item solutions of selected questions from the text;
%\item more major Maple programming examples 
%  associated with various applications, such as those of 
%  the final (applications) chapter 
%  of Anton and Rorres \cite{AR}.  
%\end{enumerate}

\medskip
%\goodbreak
%\vfill\eject

\subsubsection*{Goals of Maple in teaching and this document}

In any course using \cite{AR}  you are being asked to learn Maths,
here linear algebra, as the main priority.
The Maple is definitely not incompatible with this,
but it is the second priority.

A moderate amount of hand calculation is educationally useful
(e.g. in exemplifying the ideas for theorems),
provided that the calculation is correct.
Confusion can be created if your hand calculation is wrong.
One valid use of Maple is to CHECK your calculations:
if the answers from the two methods differ sort out why
immediately.
We urge that you work with other students,
and particularly when you are getting started with Maple.

We now define
two styles of Maple usage. Both are exemplified in these notes
(and there are continual graduations between them).
It is assumed that you are reasonably proficient at style 1:
later in the course
proficiency in style 2 will be desirable, but not essential.

\par\noindent
1. Maple can be used `as a calculator'. By this we mean that
for one or two lines of simple Maple code
(with no repetition or conditional programming constructs)
Maple can be asked to solve some maths task,
e.g. invert a matrix.
This style of use of Maple is often given in this document
in lines such as
\begin{verbatim}
> vvec:=array([v1,v2]);
\end{verbatim}
Here the {\tt >} is the computer's prompt - it is not something
you type. It may well happen that your computer uses a different
prompt: it is often $\bullet$.

\par\noindent
2. Maple can be used `as a specialised programming language
for manipulative maths applications'.
Knowledge for this style of use of Maple is something which you can
gradually acquire.
In this document there are blocks of Maple code
(which are also available in the disk supplement).
You might find these (and other items on the disk supplement)
useful if you like to `learn by example'.
However, to learn to `program in Maple' the other documents
referenced on the preceding page are essential,
as this document merely presents some linear-algebra-related
examples.

\section*{Introduction}

\subsection*{Exact and float computations}
Most scientific and engineering problems come from approximate modelling and
float-approximations to their answers, often with graphical representations of
them where appropriate.
Linear problems often occur, either in their own right
or as subproblems (arising, for example, in local linearisations
such as Newton iteration for nonlinear systems).
There are several styles of float-numeric computation.
User-written C or Fortran programs using standard libraries such as 
NAG (for general applications)
or LAPACK (for numerical linear algebra)
is one style, suitable for larger scale, or less-standardised problems.
Matlab is a good package for interactive numerical linear
algebra work. 

Numerical analysis, i.e. the serious study of float-computations, 
is a difficult area.
An introduction to numerical linear algebra is given in
the appropriate parts of 
\cite{AR} Chapter 9.  % BOTH ed.s
% (6th ed. Chapter 9, 7th ed. \S9.9).
A separate document treating it in greater depth,
and with some use of Maple, may be
available from your lecturer.
While float-numeric computation is scientifically much more important
than exact solution of linear systems, pedagogically
the exact solution of easier, small-scale problems remains extremely important.
At universities where Maple is available it is likely to be used in
Calculus teaching, and it makes sense to use 
some Maple in linear algebra teaching too.
These notes are intended to facilitate the latter.

Before leaving the discussion of styles of 
float-numeric computation compared with Computer Algebra (CA),
it is worth mentioning that recent developments aim to
obtain the best of both styles.
%Some of these recent developments are described below in the appendix.
Links between CA systems and NAG library are available.
There is also the MAGNum Toolbox for Matlab which makes the NAG library
easily callable from Matlab:
there is a Maple Toolbox for Matlab.
MathCAD is a product with Maple as its `algebra engine',
and some very good Fortran and/or C libraries
underlying its advanced numeric capabilities.

\medskip
%\goodbreak

\subsection*{Introduction to Maple's linalg}
\headq{Note.} These notes are for
Maple~V.

\smallskip
The Maple linear algebra package, {\tt linalg}, contains a number of functions
that are useful in the study of matrices and linear transformations,
in the solution of systems of linear equations, and in similar problems. 
See {\it First Leaves}, \S3.14.

\smallskip
\noindent Access to the {\tt linalg} package requires
\begin{verbatim}
> with(linalg):
Warning: new definition for   norm
Warning: new definition for   trace
\end{verbatim}
before accessing the function you want.

\smallskip
\headq{Note.} Although the above two lines always appear after the command\quad
{\tt with(linalg):}\quad they will be omitted in the rest of this document
(together with any timing messages by Maple).  If a {\tt ;} terminator is used,
the functions that are loaded into the Maple environment are displayed on the
screen. If you want only a few of these functions,
you need  only load those you need. This is illustrated in the next example
which makes use of the 
{\tt vector}\index{vector} 
function in the {\tt linalg} package.

\noindent A vector, being an array of numbers, may be entered using the
{\tt array} function.
\begin{maple}
> vec:= array( [x,y] );
                                vec := [ x, y ]
\end{maple} 

%\goodbreak
\noindent Alternatively, use can be made of the {\tt vector} function in the
{\tt linalg} package.
\begin{maple}
> with(linalg,vector):                                vector( [x,y] );
                                    [ x, y ]
\end{maple} 

\noindent Similarly, a matrix may be entered as an array of lists.
\begin{maple}
> A:= array( 1..2,1..2,[[a11,a12], [a21,a22] ]);
                                    [ a11  a12 ]
                               A := [          ]
                                    [ a21  a22 ]
\end{maple} 

\headq{Warning.} In Maple, a matrix is not an array of arrays. For example
(assuming {\tt vec} is as above)
\begin{verbatim}
> mat:=array([eval(vec),eval(vec)]):            # NOT a matrix
\end{verbatim}
creates a structure where one addresses individual entries through, 
for example, {\tt mat[1][2]}. 
With {\tt eval} replaced by {\tt convert/list} we would get a matrix
(see help on {\tt convert} for the syntax). 

\medskip
The commands for the rest of this section will be treated as a continuous Maple
session. In particular, the next command indicates that most of the functions
are in the {\tt linalg} package.

\smallskip
\goodbreak

\noindent A matrix may also be entered using the 
{\tt matrix}\index{matrix}
function (in the {\tt linalg} package).
\begin{maple}
> with(linalg):
> A:= matrix( 2,2,[[a11,a12], [a21,a22] ]);
                                    [ a11  a12 ]
                               A := [          ]
                                    [ a21  a22 ]
\end{maple} 
The first two arguments of this function (or the {\tt array} function above)
are the row and column dimensions of the array. The third argument is the set
of matrix entries (and we will see below that they are optional). 
The bracketed sets of expressions represent the rows of the matrix. 
To complete the definition of the matrix 
the bracketed row entries are nested inside brackets.
Shorter, but still valid Maple, are the following:
\begin{verbatim}
> A:= matrix([ [a11,a12], [a21,a22] ]):
> A:= matrix( 2,2,[a11,a12, a21,a22] ):
\end{verbatim}

\noindent Trying to display the matrix $A$ as you would a scalar
merely results in the letter {\tt A} being shown.
\begin{maple}
> A;
                                       A
\end{maple}
The array data structure is not displayed, only its name.
The matrix entries can, however, be displayed by using one of the following.
\begin{verbatim}
       print(A);                 op(A);                evalm(A);
\end{verbatim}

\noindent Maple can interchange the rows of a matrix.\index{swaprow}
\begin{maple}
> B:= swaprow( A,1,2 );
                                    [ a21  a22 ]
                               B := [          ]
                                    [ a11  a12 ]
\end{maple}
We will consider other row operations in connection with 
\cite{AR} Chapter 1, \S1.2. \newline  % both ed.
Similarly, the 
{\tt swapcol}\index{swapcol}
function is used to interchange two columns.

\medbreak
Arithmetic with matrices can be performed using the {\tt evalm} function,
which allows users to `overload' the usual + and * symbols in ways which might
appeal to people familiar with Mathematica or AXIOM.
(Operator overloading of this kind is used in C++ and in FORTRAN90.)

\smallskip
\noindent Thus Maple can add two matrices.
\begin{verbatim}
> evalm( A+A ):
\end{verbatim}
Here the matrix $A$ is added to itself.
This matrix can be saved (as the matrix $C$) for later use.
\begin{maple}
> C := ";
                                  [ 2 a11  2 a12 ]
                             C := [              ]
                                  [ 2 a21  2 a22 ]
\end{maple}

\noindent A matrix can be multiplied by a scalar.
\begin{maple}
> C2:= evalm( 2*A );
                                  [ 2 a11  2 a12 ]
                            C2 := [              ]
                                  [ 2 a21  2 a22 ]
\end{maple}
Notice that the last two matrices are the same.
This can also be seen using the 
{\tt equal}\index{equal}
function.
\begin{maple}
> equal( C,C2 );
                                      true
\end{maple}
This tells you whether the statement ``$C=C2$'' 
(where $C$ and $C2$ are matrices) is true or false.

\goodbreak
\smallskip

\noindent Addition and scalar multiplication can be combined to form linear
combinations.
\begin{maple}
> evalm( ca*A+cb*B );
                      [ ca a11 + cb a21  ca a12 + cb a22 ]
                      [                                  ]
                      [ ca a21 + cb a11  ca a22 + cb a12 ]
\end{maple}
The entries of $A$ are multiplied by $ca$ and
added to $cb$ times the entries of $B$.

\smallskip \goodbreak \smallskip
\noindent Matrices can be multiplied.
\begin{maple}
> evalm( A &* A );
                    [      2                               ]
                    [   a11  + a12 a21   a11 a12 + a12 a22 ]
                    [                                      ]
                    [                                   2  ]
                    [ a21 a11 + a22 a21    a12 a21 + a22   ]
\end{maple}
The {\tt \&} sign is used to inform Maple that the multiplication is not
commutative (i.e. it may not be true that $AB=BA$). There is a little-used
commutative multiplication of matrices which Maple will perform if the {\tt \&}
is omitted.

\smallskip
\noindent Maple can find the inverses of matrices.\index{inverse}
\begin{maple}
> inverse(A);
                  [         a22                   a12        ]
                  [  -----------------   - ----------------- ]
                  [  a11 a22 - a12 a21     a11 a22 - a12 a21 ]
                  [                                          ]
                  [          a21                 a11         ]
                  [ - -----------------   -----------------  ]
                  [   a11 a22 - a12 a21   a11 a22 - a12 a21  ]
\end{maple}
Maple has, cavalierly, assumed $A$ is invertible. 
You can CHECK the inverse computation.
\begin{maple}
> evalm( A &* " );
                                    [ 1  0 ]
                                    [      ]
                                    [ 0  1 ]
\end{maple}
As you would expect, a $2\times 2$ identity matrix is displayed. 
This is one way to create an identity matrix. Other ways are shown below
(where the {\tt equal} function is used to show they are the same).
\index{diag}
\begin{maple}
> Id:= diag(1,1);  # The symbol I cannot be used as it is reserved for sqrt(-1)
                                       [ 1  0 ]
                                 Id := [      ]
                                       [ 0  1 ]

# This can be generalised for any  n by n  matrix (Here n is 2):
> n:=2:                   diag( 1$n ):            equal( ",Id);
                                      true

> array(1..n,1..n,identity):        # This can be done outside linalg
> equal( ",Id);
                                      true

> band( [1],n ):                            equal( ",Id);
                                      true
\end{maple}

\smallskip
\goodbreak
\noindent Here is another attempt to compute the inverse of a matrix.
\begin{maple}
> C:= evalm( A+B );
                              [ a11 + a21  a12 + a22 ]
                         C := [                      ]
                              [ a11 + a21  a12 + a22 ]

> inverse(C);
Error, (in inverse) singular matrix
# This error is because the two rows of the matrix  are the same.
\end{maple}

\smallskip
%\goodbreak

\noindent Maple can transpose matrices.\index{transpose}
\begin{maple}
> Atr:= transpose(A);
                                     [ a11  a21 ]
                              Atr := [          ]
                                     [ a12  a22 ]
\end{maple}
(The rows of $A$ have become the columns of the transposed matrix.)

\medbreak
There are a number of commands for setting up particular special matrices.
The 
{\tt band}\index{band}
function is a useful command for creating ``band" matrices
of size $n\times n$, where $n$ is already known to Maple as is {\tt b},
a list of no more than $n$ elements.  For example, 

\begin{maple}
> n:=3:               b:= [-1,2,-1]:               A.n:= band([-1,2,-1],n);
                                    [  2  -1   0 ]
                                    [            ]
                              A3 := [ -1   2  -1 ]
                                    [            ]
                                    [  0  -1   2 ]
\end{maple}
We remark that the notation is not standardised.
Many linear algebra books, use the word `band' to refer to
matrices which are banded like the above, but where the nonzero entries on
and near the diagonal are not necessarily the same along lines parallel to
the diagonal.  We suggest `banded' for this more general sort of matrix. 

\smallskip
The band matrix function creates one sort of matrix striped parallel to the
main diagonal.  The 
{\tt toeplitz}\index{toeplitz}
function creates a matrix which is
striped parallel to the main diagonal but which is also symmetric.  Thus
the matrix {\tt A3} created with {\tt band} above could also be created with
\begin{maple}
> toeplitz([2,-1,0]);
                                 [  2  -1   0 ]
                                 [            ]
                                 [ -1   2  -1 ]
                                 [            ]
                                 [  0  -1   2 ]
\end{maple}

The Hilbert matrix is the matrix whose $(i,j)$-th entry is $1/(i+j-1)$.  When
$n$ is known to Maple (for example $n=3$), one can get a Hilbert matrix
{\tt h3} by\index{hilbert}
\begin{maple}
> h.n:=hilbert(n);
                                  [  1   1/2  1/3 ]
                                  [               ]
                            h3 := [ 1/2  1/3  1/4 ]
                                  [               ]
                                  [ 1/3  1/4  1/5 ]
\end{maple}

\smallskip
\noindent Given a list of variables or numbers (e.g. {\tt [11,12,13]}),
a Vandermonde matrix is created as follows\index{vandermonde}
\begin{maple}
> vandermonde([11,12,13]);
                                 [ 1  11  121 ]
                                 [            ]
                                 [ 1  12  144 ]
                                 [            ]
                                 [ 1  13  169 ]
\end{maple}
\goodbreak
Both Hilbert and Vandermonde matrices have uses in numerical methods.


\smallskip\noindent
The {\tt matrix} function allows a matrix to be defined in terms of any
function you wish.

\begin{maple}
# One can set up general matrices in the form given above:
> with(linalg):
> f:= proc(i,j)            a.i.j            end:
> A:= matrix(2,3,f); 
                                  [ a11  a12  a13 ]
                             A := [               ]
                                  [ a21  a22  a23 ]
\end{maple}
\headq{EXERCISE.} Show how to use this facility to find an alternative way of
creating a Hilbert matrix.

\medbreak
New vectors and matrices can also be formed from old ones. The 
{\tt col}\index{col}
(or 
{\tt row}\index{row}) command extracts a column (or row) from a matrix $A$.
For example (using the above general matrix)
\begin{maple}
> col(A,1);
                                  [ a11, a21 ]
\end{maple}

\noindent Given lists or ranges {\tt r} of rows and {\tt c} of columns,
a submatrix of $A$ consisting of those rows and columns of $A$ 
can be extracted.\index{submatrix}
\begin{maple}
> submatrix( A,1..2,[1,3] );
                                  [ a11  a13 ]
                                  [          ]
                                  [ a21  a23 ]
\end{maple}

There are many equivalent ways of setting up matrices and performing
operations on them. As your lecturer may not have the same style 
as the author of this document here are some of the alternatives taken from
part of a table in {\it First Leaves}. 
\bigskip

\index{add}\index{scalarmul}\index{multiply}\index{inverse}
\index{det}\index{nullspace}\index{kernel}\index{dotprod}\index{crossprod}
\index{linsolve}\index{vectdim} \index{coldim}\index{rowdim}
\begin{tabular}{|| l | l ||}        \hline
  Operation	&Maple notation \\ \hline
  $u + v$  (vector)	     &{\tt add(u,v)} or {\tt evalm(u + v)}\\
  $A + B$ (matrix)	    &{\tt add(A,B)} or {\tt evalm(A + B)}\\
  $ca A$	             &{\tt scalarmul(A,ca)} or {\tt evalm(ca*A)}\\
  $ca A + cb B$	&{\tt add(A,B,ca,cb)}\\
  $A v$		&{\tt multiply(A,v)} or {\tt evalm(A \&*  v)}\\
  $A B$	&{\tt multiply(A,B)} or {\tt evalm(A \&*  B)}\\
  $A^{-1}$	  	&{\tt inverse(A)} or {\tt evalm(1/A)}\\
  $\det(A)$ &{\tt det(A)}\\
  ${\rm nullspace}(A)$ or ${\rm kernel}(A)$	
          &{\tt nullspace(A)} or {\tt kernel(A)}\\
  $u\cdot v$		&{\tt dotprod(u,v)}\\
  $u \times v$	&{\tt crossprod(u,v)}\\
  solve $A x = b$	&{\tt linsolve(A,b)}\\
  number of components of a vector $v$	&{\tt vectdim(v)}\\
  number of columns of a matrix $A$	&{\tt coldim(A)}\\
  number of rows of a matrix $A$	&{\tt rowdim(A)}\\  \hline
\end{tabular}

\bigskip
Much of the preceding applies equally to some Maple versions prior to Maple V. 
In earlier versions of Maple, the dimensions of the matrix 
along with its row entries are displayed, but the output in Maple V is neater. 
The functions 
{\tt augment}\index{augment}
and 
{\tt stack}\index{stack}
were new at Maple V.
If $A$ and $B$ have the same number $m$ of rows,
so that $A$ is $m$ by $n_A$ and $B$ is $m$ by $n_B$,
{\tt augment(A,B)} creates the new $m$ by $(n_A +n_B)$ matrix,
whose left columns are from $A$ and right columns from $B$.
Thus {\tt augment} augments matrices horizontally.
Similarly {\tt stack} stacks matrices vertically.
Other functions in Maple V's {\tt linalg} can be found by typing
{\tt help(linalg)} and will be introduced as they are needed.

\medskip
\medbreak

Here is an excercise using {\tt matrix} with functions.
\smallskip
\par\noindent{\bf EXERCISE.}
Read, if you have access to an introductory Engineering
Statics or Mechanics text, their account of
moments and products of inertia, e.g.
Meriam and Kraige, Vol 1, {\it Statics},
Appendix A.
Let
$$A=\{(x_1,x_2)
\mid x_1 >0, x_2 >0, {x_1\over a} + {x_2\over b}<1\} .$$
The area moment of inertia matrix,
with moments about the origin, for $A$
is the 2 by 2 matrix $I_M$ with entries $I_{ij}$ defined by
$$
I_{ij}
= \int\int_A x_i x_j dx_1 dx_2,$$
or equivalently
$$I_{ij}
=\int_0^b \bigl(\int_0^{a(1-{x_2\over b})}
x_i x_j dx_1\bigr) dx_2.$$

(i) Verify, by running the Maple below
or otherwise, that the matrix $I$ is given by
$$I_M={1\over 24} \pmatrix{2a^3b&a^2b^2\cr
                                  a^2b^2&2ab^3\cr}.$$
Here is the Maple:
\begin{verbatim}
with(linalg,matrix):
a:='a': b:= 'b': i:='i'; j:='j'; func:=x[i]*x[j];
imij:=proc(i1,j1)
 int(int(subs(i=i1,j=j1,func),x[1]=0..a*(1-x[2]/b)),x[2]=0..b);
 end;
imij(1,2); # returned ((a*b)^2)/24 which checks
IM:=matrix(2,2,imij); # returns the matrix as required.
\end{verbatim}

(ii)  Consider the corresponding moment of
inertia matrix with moments taken about the centroid.
That is, let
$$x_1^\prime = x_1-{a\over 3}, \qquad
x^\prime_2 = x_2 - {b\over 3}$$
and
$$I^\prime_{ij} = \int\int_{A^\prime}
x^\prime_i x^\prime_j dx^\prime_1 dx^\prime_2 .$$
Verify, without doing any more integrals, that
$$I_M={1\over 72}\pmatrix{2a^3b&-a^2b^2\cr
                         -a^2b^2&2ab^3\cr}.$$


%\goodbreak
\vfill
\eject
\subsection*{Working with Vectors and Matrices}

Many Maple functions such as {\tt subs}, {\tt simplify}, which apply to scalar
expressions, may be applied to entries of a matrix, by using {\tt map}.
For example, for a matrix $A$,
\begin{verbatim}
  map( simplify,A );
  map( expand,A );
\end{verbatim}
will apply the {\tt simplify} and {\tt expand} functions 
respectively to the entries of the matrix. Here is an example.
\begin{maple}
> with(linalg):
> A:= band( [-x,2*x+x^2,-x],3 );
                          [        2                     ]
                          [ 2 x + x      - x        0    ]
                          [                              ]
                          [                  2           ]
                     A := [    - x    2 x + x      - x   ]
                          [                              ]
                          [                            2 ]
                          [     0        - x    2 x + x  ]

> B:= subs( x=a+y,op(A) ):
> Bs:= map( simplify,B );
             Bs :=                  2            2
                      [2 a + 2 y + a  + 2 a y + y , - a - y, 0]

                                          2            2
                   [- a - y, 2 a + 2 y + a  + 2 a y + y , - a - y]

                                                2            2
                      [0, - a - y, 2 a + 2 y + a  + 2 a y + y ]

> Be:= map( expand,B );
             Be :=                  2            2
                      [2 a + 2 y + a  + 2 a y + y , - a - y, 0]

                                          2            2
                   [- a - y, 2 a + 2 y + a  + 2 a y + y , - a - y]

                                                2            2
                      [0, - a - y, 2 a + 2 y + a  + 2 a y + y ]

# The entries in Be are, in this case, the same as in Bs.
#
> subs( y=1/10,a=3/10,op(B) ):
> Bf:= map( evalf," );
                     [  .9600000000  -.4000000000        0      ]
                     [                                          ]
               Bf := [ -.4000000000   .9600000000  -.4000000000 ]
                     [                                          ]
                     [       0       -.4000000000   .9600000000 ]
\end{maple}

%\goodbreak
\vfill
\eject
\subsection*{Remarks on matrices with general entries}
Besides working with numerical examples we can illustrate the
results of some of the theorems with general matrices of a given,
small, size.  Examples below are usually $2\times 2$ matrices.

%\goodbreak
\begin{maple}
> with(linalg):
# Maple can deal with matrices with general entries.  Set one up as before.
> f:= proc(i,j)            a.i.j            end:
> A:= matrix(2,2,f); 
                                    [ a11  a12 ]
                               A := [          ]
                                    [ a21  a22 ]

> type(A,matrix);
                                      true

> t:= trace(A);                                               d:= det(A);
                                 t := a11 + a22

                             d := a11 a22 - a12 a21

# The following yields a formula which is true for any  2 by 2  matrix
> map( simplify, evalm( A^2 - t*A + d) );
                                    [ 0  0 ]
                                    [      ]
                                    [ 0  0 ]
\end{maple}
Other examples will  occur later, e.g. in connection with
\cite{AR} Chapter 2. % both ed.

\vfill
\eject

