Definition
An instance of the data type real_matrix is a matrix of variables of type real.
#include < LEDA/numbers/real_matrix.h >
Creation
real_matrix | M(int n=0, int m=0) | creates an instance M of type real_matrix, M is initialized to the n x m - zero matrix. |
real_matrix | M(int n, int m, real* D) | creates the n x m matrix M with M(i, j) = D[i*m + j] for 0 < = i < = n - 1 and 0 < = j < = m - 1. Precondition D points to an array of at least n*m numbers of type real. |
Operations
int | M.dim1() | returns n, the number of rows of M. |
int | M.dim2() | returns m, the number of columns of M. |
real_vector& | M.row(int i) | returns the i-th row of M (an m-vector).
Precondition 0 < = i < = n - 1. |
real_vector | M.col(int i) | returns the i-th column of M (an n-vector).
Precondition 0 < = i < = m - 1. |
real_matrix | M.trans() | returns M^{T} (m x n - matrix). |
real_matrix | M.inv() | returns the inverse matrix of M.
Precondition M is quadratic and M.det() ! = 0. |
real | M.det() | returns the determinant of M.
Precondition M is quadratic. |
real_vector | M.solve(const real_vector& b) | |
returns vector x with M*x = b.
Precondition M.dim1() == M.dim2() = =b.dim() and M.det() ! = 0. |
||
real& | M(int i, int j) | returns M_{i, j}. Precondition 0 < = i < = n - 1 and 0 < = j < = m - 1. |
real_matrix | M + const real_matrix& M1 | Addition. Precondition M.dim1() == M1.dim1() and M.dim2() == M1.dim2(). |
real_matrix | M - const real_matrix& M1 | Subtraction. Precondition M.dim1() == M1.dim1() and M.dim2() == M1.dim2(). |
real_matrix | M * const real_matrix& M1 | Multiplication. Precondition M.dim2() == M1.dim1(). |
real_vector | M * const real_vector& vec | |
Multiplication with vector.
Precondition M.dim2() == vec.dim(). |
||
real_matrix | M * real x | Multiplication with real x. |
void | M.print(ostream& O) | prints M row by row to ostream O. |
void | M.print() | prints M cout. |
void | M.read(istream& I) | reads M.dim1() x M.dim2() numbers from input stream I and writes them row by row into matrix M. |
void | M.read() | prints M from cin. |
ostream& | ostream& O « const real_matrix& M | |
writes matrix M row by row to the output stream O. | ||
istream& | istream& I » real_matrix& M | |
reads a matrix row by row from the input stream I and assigns it to M. |
Implementation
Data type real_matrix is implemented by two-dimensional arrays of real numbers. Operations det, solve, and inv take time O(n^{3}) operations on reals, dim1, dim2, row, and col take constant time, all other operations perform O(nm) operations on reals. The space requirement is O(nm) plus the space for the nm entries of type real.