Concept

Matrix

Definition

An instance of data type Matrix is a matrix of variables of number type NT. The types Matrix and Vector together realize many functions of basic linear algebra.

Types

Matrix::NT
the ring type of the components.


Matrix::iterator
bidirectional iterator for accessing all components row-wise.


Matrix::row_iterator
random access iterator for accessing row entries.


Matrix::column_iterator
random access iterator for accessing column entries.

There also constant versions of the above iterators: const_iterator, row_const_iterator, and column_const_iterator.

Matrix::Identity
a tag class for identity initialization


Matrix::Vector
the vector type used.

Creation

Matrix M;
creates an instance M of type Matrix.


Matrix M ( int n);
creates an instance M of type Matrix of dimension n × n initialized to the zero matrix.


Matrix M ( int m, int n);
creates an instance M of type Matrix of dimension m × n initialized to the zero matrix.


Matrix M ( std::pair<int,int> p);
creates an instance M of type Matrix of dimension p.first × p.second initialized to the zero matrix.


Matrix M ( int n, Identity, NT x = NT(1));
creates an instance M of type Matrix of dimension n × n initialized to the identity matrix (times x).


Matrix M ( int m, int n, NT x);
creates an instance M of type Matrix of dimension m × n initialized to the matrix with x entries.


template <class Forward_iterator>
Matrix M ( Forward_iterator first, Forward_iterator last);
creates an instance M of type Matrix. Let S be the ordered set of n column-vectors of common dimension m as given by the iterator range [first,last). M is initialized to an m × n matrix with the columns as specified by S.
Precondition: Forward_iterator has a value type V from which we require to provide a iterator type V::const_iterator, to have V::value_type == NT.
Note that Vector or std::vector<NT> fulfill these requirements.


Matrix M ( std::vector< Vector > A);
creates an instance M of type Matrix. Let A be an array of n column-vectors of common dimension m. M is initialized to an m × n matrix with the columns as specified by A.

Operations

int M.row_dimension () returns n, the number of rows of M.

int M.column_dimension () returns m, the number of columns of M.

std::pair<int,int> M.dimension () returns (m,n), the dimension pair of M.

Vector M.row ( int i) returns the i-th row of M (an m - vector).
Precondition: 0 i m - 1.

Vector M.column ( int i) returns the i-th column of M (an n - vector).
Precondition: 0 i n - 1.

NT& M ( int i , int j ) returns Mi,j.
Precondition: 0 i m-1 and 0 j n-1.

void M.swap_rows ( int i, int j) swaps rows i and j.
Precondition: 0 i m-1 and 0 j m-1.

void M.swap_columns ( int i, int j) swaps columns i and j.
Precondition: 0 i n-1 and 0 j n-1.

row_iterator M.row_begin ( int i) an iterator pointing to the first entry of the ith row.
Precondition: 0 i m-1.

row_iterator M.row_end ( int i) an iterator pointing beyond the last entry of the ith row.
Precondition: 0 i m-1.

column_iterator M.column_begin ( int i) an iterator pointing to the first entry of the ith column.
Precondition: 0 i n-1.

column_iterator M.column_end ( int i) an iterator pointing beyond the last entry of the ith column.
Precondition: 0 i n-1.

iterator M.begin () an iterator pointing to the first entry of M.

terator M.end () an iterator pointing beyond the last entry of M.

The same operations exist for row_const_iterator, column_const_iterator and const_iterator.

bool M == M1 Test for equality.

bool M != M1 Test for inequality.

Arithmetic Operators

Matrix M + M1 Addition.
Precondition: 
M.row_dimension() == M1.row_dimension() and
M.column_dimension() == M1.column_dimension().

Matrix M - M1 Subtraction.
Precondition: 
M.row_dimension() == M1.row_dimension() and
M.column_dimension() == M1.column_dimension().

Matrix - M Negation.

Matrix M * M1 Multiplication.
Precondition: 
M.column_dimension() = M1.row_dimension().

Vector M * Vector vec Multiplication with vector.
Precondition: 
M.column_dimension() = vec.dimension().

Matrix NT x * M Multiplication of every entry with x.

Matrix M * NT x Multiplication of every entry with x.