Matrix
Array<Vector>
rows, cols
.
n
.
m[i][j]
.
Array<Vector>
, plus numbers of rows and columns.)
Array<Vector>
)
Matrix(rows,columns)
e.g. matrix x(3,2);
or y = matrix(n,m);
.
Matrix(existing_matrix_to_copy)
e.g. Matrix y; cin >> y; Matrix x(y);
This should be faster than initialising a new matrix
Matrix(existing_array<Vector>_to_copy)
e.g. Array<Vector>y; cin >> y; Matrix x(y);
<<
and >>
operators can be used.
Data format:
rows columns For each row: For each column: valueThe class also provides
Read_elements
and Write_elements
methods
to read and write the elements only, without the number of rows and columns.)
e.g.
Matrix x; cin >> x; cout << x << endl; x.Write_elements(cout);
=
e.g. Matrix x,y; cin >> x; y = x;
int square() const
returns 1 if the matrix is square,
0 otherwise
int symmetric(const double eps = 0.0) const
returns 1 if the matrix is symmetric (elements reflected across the
main diagonal differ by not more than eps
),
0 otherwise
void symm_antisymm(Matrix& symm, Matrix& antisymm) const
returns the symmetric part in symm
and
the antisymmetric part in antisymm
Matrix submatrix( const int row0, // first row of submatrix const int row1 // last row of submatrix const int col0, // first column of submatrix const int col1 // last column of submatrix ) const
e.g. Matrix y = x.submatrix(0,4,1,3);
void nullmatrix()
: existing matrix
(rows and columns already set)
friend matrix nullmatrix(unsigned int reqrows, unsigned int reqcols)
: creates a new, null matrix
void identitymatrix()
: existing matrix
(rows and columns already set)
friend matrix identitymatrix(unsigned int reqrows,
unsigned int reqcols)
: creates a new identity matrix
friend double trace(const Matrix& a)
friend double norm(const Matrix& a)
friend Matrix diag(const Vector& v)
friend Vector inner_product(const Matrix& a, const Matrix& b)
friend Vector dot(const Matrix& a, const Matrix& b)
friend Vector operator*(const Matrix& a, const Matrix& b)
e.g.
Matrix x,y; cin >> x >> y; Matrix a = inner_product(x,y), b = dot(x,y), c = x * y; // a = b = c
friend double norm(const Matrix& a)
e.g.
Matrix a; cin >> a; double anorm = norm(a);
friend Matrix operator+(const Matrix& a, const Matrix& b)
friend Matrix operator-(const Matrix& a, const Matrix& b)
friend Matrix operator-(const Matrix& a)
friend Matrix operator*(const Matrix& a, const int s)
friend Matrix operator*(const int s, const Matrix& a)
friend Matrix operator*(const Matrix& a, const vector s)
friend Matrix operator*(const vector s, const Matrix& a)
friend Matrix operator/(const Matrix& a, const int s)
friend Matrix operator/(const Matrix& a, const vector s)
Matrix_fixed_dimension
matrix
Matrix_fixed_dimension
is exactly the same as a
Matrix
, except that the Read
and Write
methods are redefined to omit the number of elements.
(This means that the number of elements must be set before
a Matrix_fixed_dimension
is read.)
This class is the base for matrixs of a specific dimension.
Matrix6d
Matrix_fixed_dimension
Matrix5d
Matrix_fixed_dimension
Matrix4d
Matrix_fixed_dimension
Matrix3d
Matrix_fixed_dimension
Matrix2d
Matrix_fixed_dimension
friend vector operator^(const Matrix2d& a, const Matrix2d& b)
friend Matrix2d rotate( const Matrix2d& a, // initial matrix const vector phi // rotation angle in radians (anticlockwise) )
friend Matrix2d rotate_about( const Matrix2d& a, // initial matrix const Matrix2d& p, // point through which axis passes const vector phi // rotation angle in radians (anticlockwise) )
real_matrix
Arithmetic_matrix<Vector>