%% Created by Maple 6 (SUN SPARC SOLARIS)
%% Source Worksheet: lin-alg.mws
%% Generated: Tue Feb  6 10:05:02 2001
\documentclass[12pt]{article}
\usepackage{maple2e}
 \def\emptyline{\vspace{12pt}}
\DefineParaStyle{Heading 1}
\DefineParaStyle{Maple Output}
\DefineParaStyle{Warning}
\DefineCharStyle{2D Comment}
\DefineCharStyle{2D Math}
\DefineCharStyle{2D Output}
\begin{document}
\pagestyle{empty}
\begin{Heading 1}
Linear Algebra in Maple
\end{Heading 1}

\emptyline
You \textbf{must }load the linear algebra package.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{with(linalg):}{%
}
\end{mapleinput}

\mapleresult
\begin{maplettyout}
Warning, the protected names norm and trace have been redefined and
unprotected
\end{maplettyout}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{A := matrix([[1,I],[-I,1]]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{A := matrix([[1, I], [-I, 1]]);}{%
\[
A :=  \left[ 
{\begin{array}{cc}
1 & I \\
 - I & 1
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
Use the command \textbf{conjugate} to conjugate the entries of the
matrix.  You have to use \textbf{evalm} (evaluation in matrices) for
operations on matrices to be executed.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{evalm(conjugate(A));}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{matrix([[1, -I], [I, 1]]);}{%
\[
 \left[ 
{\begin{array}{cc}
1 &  - I \\
I & 1
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
The command \textbf{htranspose} calculates the conjugate transpose
(adjoint) of a matrix.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{htranspose(A);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{matrix([[1, I], [-I, 1]]);}{%
\[
 \left[ 
{\begin{array}{cc}
1 & I \\
 - I & 1
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
The comand \textbf{map} applies a procedure to each operand of an
expression.  Use it, for example, to differentiate entries of a
matrix.

\emptyline
Here is the matrix of problem 26, p. 357.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{psi :=
matrix([[exp(t),exp(-2*t),exp(3*t)],[-4*exp(t),-exp(-2*t),2*exp(3*t)],
[-exp(t),-exp(-2*t),exp(3*t)]]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{psi := matrix([[exp(t), exp(-2*t), exp(3*t)], [-4*exp(t), -exp(-2*t),
2*exp(3*t)], [-exp(t), -exp(-2*t), exp(3*t)]]);}{%
\[
\psi  :=  \left[ 
{\begin{array}{ccc}
e^{t} & e^{( - 2\,t)} & e^{(3\,t)} \\
 - 4\,e^{t} &  - e^{( - 2\,t)} & 2\,e^{(3\,t)} \\
 - e^{t} &  - e^{( - 2\,t)} & e^{(3\,t)}
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
We calculate the derivative of 
\mapleinline{inert}{2d}{psi;}{%
$\psi $%
}.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{map(diff,psi,t);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{matrix([[exp(t), -2*exp(-2*t), 3*exp(3*t)], [-4*exp(t), 2*exp(-2*t),
6*exp(3*t)], [-exp(t), 2*exp(-2*t), 3*exp(3*t)]]);}{%
\[
 \left[ 
{\begin{array}{ccc}
e^{t} &  - 2\,e^{( - 2\,t)} & 3\,e^{(3\,t)} \\
 - 4\,e^{t} & 2\,e^{( - 2\,t)} & 6\,e^{(3\,t)} \\
 - e^{t} & 2\,e^{( - 2\,t)} & 3\,e^{(3\,t)}
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
We verify that 
\mapleinline{inert}{2d}{psi;}{%
$\psi $%
} satisfies the differential equation in problem 26.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{B := matrix([[1,-1,4],[3,2,-1],[2,1,-1]]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{B := matrix([[1, -1, 4], [3, 2, -1], [2, 1, -1]]);}{%
\[
B :=  \left[ 
{\begin{array}{rrr}
1 & -1 & 4 \\
3 & 2 & -1 \\
2 & 1 & -1
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
Matrix multiplication is indicated by \textbf{\&*.}

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{evalm(B&*psi);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{matrix([[exp(t), -2*exp(-2*t), 3*exp(3*t)], [-4*exp(t), 2*exp(-2*t),
6*exp(3*t)], [-exp(t), 2*exp(-2*t), 3*exp(3*t)]]);}{%
\[
 \left[ 
{\begin{array}{ccc}
e^{t} &  - 2\,e^{( - 2\,t)} & 3\,e^{(3\,t)} \\
 - 4\,e^{t} & 2\,e^{( - 2\,t)} & 6\,e^{(3\,t)} \\
 - e^{t} & 2\,e^{( - 2\,t)} & 3\,e^{(3\,t)}
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
This is the same as the derivative of 
\mapleinline{inert}{2d}{psi;}{%
$\psi $%
}.

\emptyline
Similarly, we can use map to integrate.  For example, to integrate
each term of 
\mapleinline{inert}{2d}{psi;}{%
$\psi $%
} from 0 to 1:

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{map(int,psi,t=0..1);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{matrix([[exp(1)-1, -1/2*exp(-2)+1/2, 1/3*exp(3)-1/3], [-4*exp(1)+4,
1/2*exp(-2)-1/2, 2/3*exp(3)-2/3], [-exp(1)+1, 1/2*exp(-2)-1/2,
1/3*exp(3)-1/3]]);}{%
\[
 \left[ 
{\begin{array}{ccc}
e - 1 &  - {\displaystyle \frac {1}{2}} \,e^{(-2)} + 
{\displaystyle \frac {1}{2}}  & {\displaystyle \frac {1}{3}} \,e
^{3} - {\displaystyle \frac {1}{3}}  \\ [2ex]
 - 4\,e + 4 & {\displaystyle \frac {1}{2}} \,e^{(-2)} - 
{\displaystyle \frac {1}{2}}  & {\displaystyle \frac {2}{3}} \,e
^{3} - {\displaystyle \frac {2}{3}}  \\ [2ex]
 - e + 1 & {\displaystyle \frac {1}{2}} \,e^{(-2)} - 
{\displaystyle \frac {1}{2}}  & {\displaystyle \frac {1}{3}} \,e
^{3} - {\displaystyle \frac {1}{3}} 
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
The command \textbf{basis} lets you find a basis for the span of a set
of vectors.  You can use the command \textbf{vector} to create the
vectors.  For example, here are the vectors of problem 10 on p. 366.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{x[1] := vector([1,2,-2]); x[2] := vector([3,1,0]); x[3]:=
vector([2,-1,1]); x[4] := vector([4,3,-2]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{x[1] := vector([1, 2, -2]);}{%
\[
{x_{1}} := [1, \,2, \,-2]
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{x[2] := vector([3, 1, 0]);}{%
\[
{x_{2}} := [3, \,1, \,0]
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{x[3] := vector([2, -1, 1]);}{%
\[
{x_{3}} := [2, \,-1, \,1]
\]
%
}
\end{maplelatex}

\begin{maplelatex}
\mapleinline{inert}{2d}{x[4] := vector([4, 3, -2]);}{%
\[
{x_{4}} := [4, \,3, \,-2]
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{basis([x[1],x[2],x[3],x[4]]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{[x[1], x[2], x[3]];}{%
\[
[{x_{1}}, \,{x_{2}}, \,{x_{3}}]
\]
%
}
\end{maplelatex}

\end{maplegroup}
To write 
\mapleinline{inert}{2d}{x[4];}{%
${x_{4}}$%
} as a linear combination of 
\mapleinline{inert}{2d}{x[1],x[2],x[3]:;}{%
${x_{1}}, \,{x_{2}}, \,{x_{3}}$%
}:

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{v := evalm(x[4]-a*x[1]-b*x[2]-c*x[3]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{v := vector([4-a-3*b-2*c, 3-2*a-b+c, -2+2*a-c]);}{%
\[
v := [4 - a - 3\,b - 2\,c, \,3 - 2\,a - b + c, \, - 2 + 2\,a - c]
\]
%
}
\end{maplelatex}

\end{maplegroup}
We need to extract the components of 
\mapleinline{inert}{2d}{v;}{%
$v$%
}, then set them equal to 0 and solve the resulting equations.  The
\textit{i}th component is v[i].

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{solve(\{v[1],v[2],v[3]\},\{a,b,c\});}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{\{a = 1, c = 0, b = 1\};}{%
\[
\{a=1, \,c=0, \,b=1\}
\]
%
}
\end{maplelatex}

\end{maplegroup}
The command \textbf{eigenvects} allows you to calculate the
eigenvectors of a matrix.  The answer comes in the form of a list. 
Each item in the list consists of an eigenvector, its multiplicity,
and a basis for the eigenspace.  As an example, here is problem 17 on
p. 367.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{C := matrix([[-2,1],[1,-2]]);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{C := matrix([[-2, 1], [1, -2]]);}{%
\[
C :=  \left[ 
{\begin{array}{rr}
-2 & 1 \\
1 & -2
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{e := eigenvects(C);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{e := [-3, 1, \{vector([-1, 1])\}], [-1, 1, \{vector([1, 1])\}];}{%
\[
e := [-3, \,1, \,\{[-1, \,1]\}], \,[-1, \,1, \,\{[1, \,1]\}]
\]
%
}
\end{maplelatex}

\end{maplegroup}
To make a matrix 
\mapleinline{inert}{2d}{T;}{%
$T$%
} whose columns are the eigenvectors we just found, we first have to
extract the eigenvectors.  For example, [-1,1] is the first thing in
\{[-1,1]\}, which is the third in the second element of 
\mapleinline{inert}{2d}{e;}{%
$e$%
}, i.e., it is e[2][3][1].

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{T := transpose(matrix([e[1][3][1],e[2][3][1]]));}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{T := matrix([[-1, 1], [1, 1]]);}{%
\[
T :=  \left[ 
{\begin{array}{rr}
-1 & 1 \\
1 & 1
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
The command \textbf{diag} produces a diagonal matrix with the given
entries on the diagonal.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{Diag := diag(-1,-3);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{Diag := matrix([[-1, 0], [0, -3]]);}{%
\[
\mathit{Diag} :=  \left[ 
{\begin{array}{rr}
-1 & 0 \\
0 & -3
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
The command \textbf{inverse} finds the inverse of a matrix.  We use it
in checking that 
\mapleinline{inert}{2d}{T^(-1)*C*T = Diag;}{%
$T^{(-1)}\,C\,T=\mathit{Diag}$%
}.

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{evalm(inverse(T)&*C&*T);}{%
}
\end{mapleinput}

\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{matrix([[-3, 0], [0, -1]]);}{%
\[
 \left[ 
{\begin{array}{rr}
-3 & 0 \\
0 & -1
\end{array}}
 \right] 
\]
%
}
\end{maplelatex}

\end{maplegroup}
\textbf{Warning:} You cannot use either Psi or D as a name in Maple,
because both are built in.

\begin{maplegroup}
\begin{mapleinput}
\end{mapleinput}

\end{maplegroup}
\end{document}
%% End of Maple 6 Output
