## `Cat::Matrix` -- the category of matrices

#### Introduction

``Cat::Matrix`(R)` represents the category of matrices over the rng `R`.

#### Generating the category

`Cat::Matrix(R)`

#### Parameters

`R` | - | A domain which must be from the category `Cat::Rng` (a ring without unit).

#### Categories

`Cat::BaseCategory`

#### Details

- A ``Cat::Matrix`(R)` is a matrix of arbitrary dimension over a component ring `R`.
- In the following description of the methods, we use the following notations for a matrix A from a domain of category `Cat::Matrix``(R)`:

  nrows(A) denotes the number of rows and ncols(A) the number of columns of A.

  Further on, a row index is an integer ranges from 1 to nrows(A), and a column index is an integer ranges from 1 to ncols(A).

#### Entries

coeffRing

  is set to `R`.

#### Method _index: matrix indexing

- `_index(dom A, row index i, column index j)`
- - Must return the (i,j)-th component of the matrix `A`.

#### Method matdim: matrix dimension

- `matdim(dom A)`
- - Must return the number of rows and columns of the matrix `A` in form of a list of two positive integers.

#### Method new: matrix definition

- `new(positive integers m, n)`
- - Must return the m x n zero matrix.
  - Of course, this method may implement further possibilites to create matrices (for example, see the method `"new"` of the domain constructor `Dom::Matrix`).

#### Method set_index: setting matrix components

- `set_index(dom A, row index i, column index j, R x)`
- - Must replace the (i,j)-th component of the matrix `A` by `x`.

#### Method _negate: negates a matrix

- `_negate(dom A)`
- - Computes -A.

#### Method _plus: adds matrices

- `_plus(dom A1, dom A2..., dom An)`
- - Returns the sum A1 + A2 + ... + An of the n matrices A1, A2, ..., An.

    An error message is issued if the given matrices do not have the same dimension.

  - The matrices must be of the same domain type, otherwise `FAIL` is returned.

#### Method _subtract: subtract two matrices

- `_subtract(dom A, dom B)`
- - The matrix A-B is returned.

#### Method equal: test on equality of matrices

- `equal(dom A, dom B)`
- - This method tests if the two matrices `A` and `B` are equal and returns `TRUE`, `FALSE` or `UNKNOWN`, respectively.

#### Method identity: identity matrix

- `identity(positive integer n)`
- - This method returns the n x n identity matrix.
  - It only exists if `R` is of category `Cat::Ring`, i.e., a ring with unit.

#### Method iszero: test on zero matrices

- `iszero(dom A)`
- - This method checks whether `A` is a zero matrix and returns `TRUE` or `FALSE`, respectively.
  - Note that there may be more than one representation of the zero matrix of a given dimension if `R` does not have the axiom `Ax::canonicalRep`.

#### Method transpose: transpose of a matrix

- `transpose(dom A)`
- - This method returns the tranposed matrix A^T of `A`.

#### Method col: extracting columns

- `col(dom A, column index c)`
- - This method extracts the column with index `c` of the matrix `A` and returns it as a column vector, i.e., a nrows(A) x 1 matrix.

#### Method concatMatrix: appending of matrices horizontally

- `concatMatrix(dom A, dom B)`
- - This method appends the matrix `B` to the right side of the matrix `A`.
  - An error message is issued if the two matrices do not have the same number of rows.

#### Method delCol: deleting columns

- `delCol(dom A, column index c)`
- - This method returns the matrix obtained by deleting the column with index `c` of the matrix `A`.
  - If `A` only consists of one column then `NIL` is returned.

#### Method delRow: deleting rows

- `delRow(dom A, row index r)`
- - This method returns the matrix obtained by deleting the row with index `r` of the matrix `A`.
  - If `A` only consists of one row then `NIL` is returned.

#### Method row: extracting rows

- `row(dom A, row index r)`
- - This method extracts the row with index `r` of the matrix `A` and returns it as a row vector, i.e., a 1 x ncols(A) matrix.

#### Method setCol: replacing columns

- `setCol(dom A, column index c, dom v)`
- - This method replaces the column with index `c` of the matrix `A` by the column vector `v`. The vector `v` must be a nrows(A) x 1 matrix.

#### Method setRow: replacing rows

- `setRow(dom A, row index r, dom v)`
- - This method replaces the row with index `r` of the matrix `A` by the row vector `v`. The vector `v` must be a 1 x ncols(A) matrix.

#### Method stackMatrix: appending of matrices vertically

- `stackMatrix(dom A, dom B)`
- - This method appends the matrix `B` to the lower end of the matrix `A`.
  - An error message is issued if the two matrices do not have the same number of columns.

#### Method swapCol: swapping matrix columns

- `swapCol(dom A, column indices c1, c2)`
- - Returns the matrix which results from swapping the column with index `c1` with the column with index `c2` of `A`.

#### Method swapRow: swapping matrix rows

- `swapRow(dom A, row indices r1, r2)`
- - Returns the matrix which results from swapping the row with index `r1` with the row with index `r2` of `A`.

#### Changes

- used to be called `Cat::MatrixCat`
- The method `"dimen"` was renamed to `"matdim"`.
- The method `"create"` was removed (in `Cat::Matrix` the default implementation was set to the method `"new"`). You may implement this method in the corresponding domain if necessary.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000