#include "matrix.h"
Public Member Functions | |
matrix () | |
Constructs an empty matrix. | |
matrix (int numberRows, int numberColumns, double value=0) | |
Constructs a matrix with given number of rows and columns. | |
int | numRows () const |
Returns the current number of rows for the matrix. | |
int | numColumns () const |
Returns the current number of columns for the matrix. | |
matrix | size () const |
Returns a row-vector whose entries designate the current dimensions of the matrix. | |
bool | operator== (const matrix &other) const |
Tests if two matrices have identical dimension and content. | |
bool | operator!= (const matrix &other) const |
The converse of the equivalence test. | |
double | operator() (int r, int c) const |
Provides read-only access to a specific matrix element. | |
double & | operator() (int r, int c) |
Provides a live reference to a specific matrix element. | |
double | operator() (int k) const |
Provides read-only access to a matrix element specified with a linear index. | |
double & | operator() (int k) |
Provides a live reference to a matrix element specified with a linear index. | |
matrix | operator- () const |
Generates a matrix that is the negated form of the current one. | |
matrix | operator~ () const |
Generates a matrix that is the transpose form of the current one. | |
matrix | operator+ (const matrix &other) const |
Generates a matrix that is the element-by-element sum of two matrices. | |
matrix & | operator+= (const matrix &other) |
Mutates a matrix by doing an element-by-element addition with another matrix. | |
matrix | operator+ (double scalar) const |
Generates a matrix by adding a scalar constant to each element of another matrix. | |
matrix & | operator+= (double scalar) |
Mutates a matrix by adding a scalar constant to each element. | |
matrix | operator- (const matrix &other) const |
Generates a matrix that is the element-by-element difference of two matrices. | |
matrix & | operator-= (const matrix &other) |
Mutates a matrix by doing an element-by-element addition with another matrix. | |
matrix | operator- (double scalar) const |
Generates a matrix by subtracting a scalar constant from each element of another matrix. | |
matrix & | operator-= (double scalar) |
Mutates a matrix by subtracting a scalar constant from each element. | |
matrix | operator* (const matrix &other) const |
Generates a matrix that is the product of two matrices. | |
matrix & | operator*= (const matrix &other) |
Mutates a matrix by multiplying it with another. | |
matrix | operator* (double scalar) const |
Generates a matrix by multiplying each element of another matrix by a scalar constant. | |
matrix & | operator*= (double scalar) |
Mutates a matrix by multiplying each element by a scalar constant. |
This represents a two-dimensional matrix of double precision floating-point numbers. It may be that the span of one or both of the dimensions is one, in which case this represents a row vector or column vector. One or both of the dimensions might be zero, in which case it represents an empty matrix.
When linearized, the matrix is stored in column-major order.
matrix | ( | int | numberRows, | |
int | numberColumns, | |||
double | value = 0 | |||
) |
int numRows | ( | ) | const |
Returns the current number of rows for the matrix.
int numColumns | ( | ) | const |
Returns the current number of columns for the matrix.
matrix size | ( | ) | const |
bool operator== | ( | const matrix & | other | ) | const |
Tests if two matrices have identical dimension and content.
other | the second matrix in an expression (m == other) |
bool operator!= | ( | const matrix & | other | ) | const |
The converse of the equivalence test.
other | the second matrix in an expression (m != other) |
double operator() | ( | int | r, | |
int | c | |||
) | const |
Provides read-only access to a specific matrix element.
As a simple example, assume that matrix m has contents:
5 15 3 8 20 2 14 3
double v = m(1,2);
r | the indicated row (with 0 designating the top row) | |
c | the indicated column (with 0 designating the leftmost column) |
double& operator() | ( | int | r, | |
int | c | |||
) |
Provides a live reference to a specific matrix element.
The caller may use the reference to directly mutate the content of the cell. As a simple example, assume that matrix m has contents:
5 15 3 8 20 2 14 3
m(1,2) = 25;
5 15 3 8 20 2 25 3
Note that if a row or column is indicated beyond the current extent of the matrix, the matrix is automatically reized to make room for the new entry, with other new cells getting value 0. For example the syntax This method is invoked when using the syntax
m(3,2) = 50;
5 15 3 8 20 2 25 3 0 0 0 0 0 0 50 0
r | the indicated row (with 0 designating the top row) | |
c | the indicated column (with 0 designating the leftmost column) |
double operator() | ( | int | k | ) | const |
Provides read-only access to a matrix element specified with a linear index.
Matrices are linearized using the column-major convention. As a simple example, assume that matrix m has contents:
5 15 3 8 20 2 14 3
double v = m(5);
k | the zero-indexed location in column-major order |
double& operator() | ( | int | k | ) |
Provides a live reference to a matrix element specified with a linear index.
Matrices are linearized using the column-major convention. As a simple example, assume that matrix m has contents:
5 15 3 8 20 2 14 3
m(5) = 25
5 15 3 8 20 2 25 3
Note: unlike the (row,column) form of this assignment, a matrix cannot be resized using the linearized index. Use of an index that is beyond the extent of the matrix will result in a runtime error.
k | the zero-indexed location in column-major order |
matrix operator- | ( | ) | const |
matrix operator~ | ( | ) | const |
Generates a matrix that is the element-by-element sum of two matrices.
As a simple example, assume that matrix A has contents:
5 15 3 8 20 2 14 3
2 14 23 10 11 12 5 9
C = A + B
7 29 26 18 31 14 19 12
Note that the contents of both A and B remain unchanged, although one could be reassigned using a syntax such as
A = A + B;
Note: a runtime error occurs if the two matrices do not have equivalent dimensions.
Mutates a matrix by doing an element-by-element addition with another matrix.
As a simple example, assume that matrix A has contents:
5 15 3 8 20 2 14 3
2 14 23 10 11 12 5 9
A += B
7 29 26 18 31 14 19 12
Note: a runtime error occurs if the two matrices do not have equivalent dimensions.
matrix operator+ | ( | double | scalar | ) | const |
matrix& operator+= | ( | double | scalar | ) |
Generates a matrix that is the element-by-element difference of two matrices.
As a simple example, assume that matrix A has contents:
5 15 3 8 20 2 14 3
2 14 23 10 11 12 5 9
C = A - B
3 1 -20 -2 9 -10 9 -6
Note that the contents of both A and B remain unchanged, although one could be reassigned using a syntax such as
A = A - B;
Note: a runtime error occurs if the two matrices do not have equivalent dimensions.
Mutates a matrix by doing an element-by-element addition with another matrix.
As a simple example, assume that matrix A has contents:
5 15 3 8 20 2 14 3
2 14 23 10 11 12 5 9
A -= B
3 1 -20 -2 9 -10 9 -6
Note: a runtime error occurs if the two matrices do not have equivalent dimensions.
matrix operator- | ( | double | scalar | ) | const |
matrix& operator-= | ( | double | scalar | ) |
Generates a matrix that is the product of two matrices.
As a simple example, assume that matrix A has contents:
5 15 3 8 20 2 14 3
3 10 2 14
C = A * B
283 150
Note: the inner dimensions of the product must agree or else a runtime error occurs. That is the number of columns in A must match the number of rows in B when computing A*B. The resulting product has the same number of rows as A and the same number of columns as B.
Mutates a matrix by multiplying it with another.
As a simple example, assume that matrix A has contents:
5 15 3 8 20 2 14 3
3 10 2 14
A *= B
283 150
Note: the inner dimensions of the product must agree or else a runtime error occurs. That is the number of columns in A must match the number of rows in B when computing A*B. The resulting product has the same number of rows as A and the same number of columns as B.
matrix operator* | ( | double | scalar | ) | const |
matrix& operator*= | ( | double | scalar | ) |