Using the Matrix class
The Matrix class is a template class designed to represent and manipulate matrices. It provides various operations for matrix-matrix and matrix-scalar computations, as well as utilities for input/output, transposition, singular value decomposition (SVD), and pseudo-inverse computation.
This tutorial provided a basic overview of how to use the Matrix class. For more advanced usage and additional features, please refer to the Matrix class API in matrix.hpp.
Instantiate the Class: Instantiate an object of the Matrix class with the desired template parameter (ValueType).
Matrix<double> mat;
Initialize the Matrix: Initialize the matrix with its dimensions and optionally with data.
Matrix<double> mat(3, 3); // Creates a 3x3 matrix filled with default-initialized values.
Perform Matrix Operations: You can perform various matrix operations such as addition, subtraction, multiplication, and element-wise operations.
Matrix<double> A(3, 3); Matrix<double> B(3, 3); Matrix<double> C = A + B; // Addition Matrix<double> D = A * B; // Matrix multiplication Matrix<double> E = A * 2.0; // Scalar multiplication
Access Matrix Elements: You can access individual elements of the matrix using the operator() or operator[].
double val = mat(0, 0); // Access element at row 0, column 0 mat(1, 2) = 10.0; // Assign a new value to the element at row 1, column 2
Transpose the Matrix: Transpose the matrix using the Transpose method.
Matrix<double> transposed = mat.Transpose();