home *** CD-ROM | disk | FTP | other *** search
- \bigskip
- \bigskip
- {\magonebf 2.5 Real-Valued Matrices (matrix)}
-
- An instance of the data type $matrix$ is a matrix of real variables.
-
- \def\name{$matrix$}
- \def\type{$matrix$}
-
- \bigskip
- {\bf 1. Creation of a matrix }
-
- \create M (int\ n,\ int\ m)
-
-
- creates an instance $M$ of type $matrix$, $M$ is initialized to the $n\times m$
- - zero matrix.
-
-
- \bigskip
- {\bf 2. Operations on a matrix M}
-
- \medskip
- \+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
- \+\op int dim1 {}
- { returns $n$, the number of rows of $M$.}
- \smallskip
- \+\op int dim2 {}
- { returns $m$, the number of cols of $M$.}
- \smallskip
- \+\op vector row {int\ i}
- { returns the $i$-th row of $M$ (an $m$-vector).}
- \+\nop { \precond $0 \le i \le n-1$.}
- \smallskip
- \+\op vector col {int\ i}
- { returns the $i$-th column of $M$ (an $n$-vector).}
- \+\nop { \precond $0 \le i \le m-1$.}
- \smallskip
- \+\op matrix trans {}
- { returns $M^T$ ($m\times n$ - matrix). }
- \smallskip
- \+\op real det {}
- { returns the determinant of $M$.}
- \+\nop { \precond $M$ is quadratic.}
- \smallskip
- \+\op matrix inv {}
- { returns the inverse matrix of $M$. }
- \+\nop { \precond $M$.det() $\neq$ 0.}
- \smallskip
- \+\op vector solve {vector\ b}
- { returns vector $x$ with $M\cdot x = b$. }
- \+\nop { \precond $M$.dim1() = $M$.dim2() = $b$.dim()}
- \+\nop { and $M$.det() $\neq$ 0.}
- \medskip
- \+\opf real\& {int\ i,\ int\ j}
- {returns $M_{i,j}$.}
- \+\nop {\precond $0\le i\le n-1$ and $0\le j\le m-1$.}
- \smallskip
- \+\opb matrix\& = M_1
- {Assignment; returns $M$.}
- \smallskip
- \+\opb matrix + M_1
- {Addition}
- \+\nop {\precond $M$.dim1() = $M_1$.dim1() and}
- \+\nop { $M$.dim2() = $M_1$.dim2().}
- \smallskip
- \+\opb matrix - M_1
- {Subtraktion}
- \+\nop {\precond $M$.dim1() = $M_1$.dim1() and}
- \+\nop { $M$.dim2() = $M_1$.dim2().}
- \smallskip
- \+\opb matrix * M_1
- {Multiplication}
- \+\nop {\precond $M$.dim2() = $M_1$.dim1().}
- \smallskip
- \+\opb matrix * r
- {Multiplication with real}
- \smallskip
- \+\opb vector * v
- {Multiplication with vector}
- \+\nop {\precond $M$.dim2() = $v$.dim().}
- \medskip
- \+\ops ostream\& << O
- {writes matrix $M$ to the output stream $O$}
- \smallskip
- \+\ops istream\& >> I
- {reads matrix $M$ from the input stream $I$}
-
- \bigskip
- {\bf 3. Implementation }
- \medskip
- Data type $matrix$ is implemented by two-dimensional arrays of real numbers.
- Operations det and solve take time $O(n^2)$, inv takes time $O(n^3)$, dim1,
- dim2, row, and col take constant time, all other operations take time $O(nm)$.
- The space requirement is $O(nm)$.
-
-