Utility methods
The following utility methods are available in the matrix class.
1. size_t size () const;
2. size_t typesize () const;
3. size_t rowno () const;
4. size_t colno () const;
5. T sum () const;
6. T min () const;
7. T max () const;
8. T trace (int i=0) const;
9. void resize (size_t nRow, size_t nCol);
10. void free ();
11. void null ();
12. void unit ();
13. void rand (int rmin=-1, int rmax=1, int rseed=0);
14. matrix<T> adj () const;
15. T cofact (size_t row, size_t col) const;
16. T det () const;
17. T cond () const;
18. size_t rank () const;
19. T norm1 () const;
20. T norm2 () const;
21. T normI () const;
22. T normF () const;
23. matrix<T> apply (T (*fn)(T v)) const;
24. matrix<T> apply (T (*fn)(const T& v)) const;
25. matrix<T> apply (T (*fn)(size_t i, size_t j, T v)) const;
26. matrix<T> apply (T (*fn)(size_t i, size_t j, const T& v)) const;
- Returns the number of elements in a matrix object.
- Returns the type size of the matrix elements.
- Returns the row number of a matrix.
- Returns the column number of a matrix.
- Returns the sum of all elements of a matrix.
- Returns the minimum value of all matrix elements.
- Returns the maximum value of all matrix elements.
- Returns the sum of diagonal elements of a matrix. The default diagonal is the main diagonal of the matrix.
- Resizes a matrix to a nRow by nCol matrix. It is provided only for completeness, and you do not normally need to use this function.
- Frees the memory associated with a matrix object and sets its size as zero by zero matrix. Note that you can't use a zero size matrix in any operation.
- Sets all elements of a matrix equal to zero.
- Sets the matrix as a unit matrix, i.e., its main diagonal elements will be equal to 1.0 and the rest zero.
- Generates a random number matrix. By default the random numbers will be in the range of -1.0 to 1.0, but you can provide a different minimum and maximum range, as well as the initial seed value for the random number generator.
- Returns the adjoin of a matrix. This is an expensive operation and only of academic interest.
- Returns the cofactor of ith row and jth column of a matrix.
- Returns the determinant of a matrix.
- Returns the condition number of a matrix.
- Returns the rank of a matrix.
- Returns the one norm of a matrix.
- Returns the two norm of a matrix.
- Returns the infinity norm of a matrix.
- Returns the Frobenius norm of a matrix.
- Applies the function fn to all elements of a matrix and returns the new matrix object.
- Applies the function fn to all elements of a matrix and returns the new matrix object.
- Applies the function fn to all elements of a matrix and returns the new matrix object.
- Applies the function fn to all elements of a matrix and returns the new matrix object.
Examples
typedef techsoft::matrix<double> Matrix;
Matrix A(6,4);
double x;
size_t i,j;
A.rand( 100); // Generates a random matrix with elements 0 to 100
i = A.size(); // i = 6 x 4 = 24
j = A.rowno(); // Row number equal to 6
j = A.colno(); // Column number equal to 4
A.resize( 4, 4); // Resize the matrix to a 4 x 4 one
x = A.sum(); // Sum of all elements
x = A.trace(-1); // Sum of the diagonal elements just below the main diagonal
x = A.det(); // Determinant of A
x = A.cond(); // Condition number of A
x = A.normF(); // Frobenius norm of A
Matrix B = A.apply(sin);// Apply sin function to A
A.unit(); // A is now a unit matrix