Non-member functions
The following non-member functions are avaiable for the matrix class object.
1. matrix<T> pow (const matrix<T>& m, size_t n);
2. matrix<T> abs (const matrix<T>& m);
3. matrix<T> floor (const matrix<T>& m);
4. matrix<T> ceil (const matrix<T>& m);
5. void mswap (matrix<T>& x, matrix<T>& y);
- Returns m to the power n, i.e., m is self multiplied n times. Here m must be a square matrix, otherwise, it throws invalid_argument exception if range checking is enabled. This function uses minimum number of matrix multiplication to compute the power.
- Returns a matrix class object each of whose elements is an absolute value of corresponding element of the matrix m.
- Returns a matrix class object each of whose elements is a floating-point value representing the largest integer that is less than or equal to corresponding element of the matrix m
- Returns a matrix class object each of whose elements is a floating-point value representing smallest integer that is greater than or equal to corresponding element of the matrix m
- Swaps values of two matrix objects. You can also use this function to swap rows, columns, or elements of the same or two different matrices.
Examples
typedef techsoft::matrix<double> Matrix;
Matrix A(4,4), B(4,4);
A.rand();
B = techsoft::abs( A);
B = techsoft::floor( A);
B = techsoft::ceil( A);
B = techsoft::pow( A, 9); // Calculates A9
using techsoft::mswap;
mswap( A, B);
mswap( A[1], B[1]); // Swaps row A[1] and row B[1]
mswap( A(1), A(2)); // Swaps column A(1) and column A(2)
mswap( A.diag(1), A.diag(-1)); // Swaps the upper and lower diagonals just below the main diagonal
mswap( A[2][3], A[3][2]);
mswap( A(2,3), B(3,2));