diff --git a/src/Matrix.hpp b/src/Matrix.hpp index 1b9d97e..7b4d87f 100644 --- a/src/Matrix.hpp +++ b/src/Matrix.hpp @@ -216,8 +216,24 @@ public: return vec1.Get(0, 0) * vec2.Get(0, 0); } + /** + * @brief Performs QR decomposition on this matrix + * @param Q a buffer that will contain Q after the function completes + * @param R a buffer that will contain R after the function completes + */ void QRDecomposition(Matrix &Q, Matrix &R) const; + /** + * @brief Uses QR decomposition to efficiently calculate the eigenvectors and + * values of this matrix + * @param eigenVectors a buffer that will contain the eigenvectors fo this + * matrix + * @param eigenValues a buffer that will contain the eigenValues fo this + * matrix + * @param maxIterations the number of iterations to perform before giving up + * on reaching the given tolerance + * @param tolerance the level of accuracy to obtain before stopping. + */ void EigenQR(Matrix &eigenVectors, Matrix &eigenValues, uint16_t maxIterations = 1000, float tolerance = 1e-6f) const; diff --git a/unit-tests/matrix-tests.cpp b/unit-tests/matrix-tests.cpp index d1e6881..3b0737f 100644 --- a/unit-tests/matrix-tests.cpp +++ b/unit-tests/matrix-tests.cpp @@ -353,7 +353,9 @@ TEST_CASE("Elementary Matrix Operations", "Matrix") { REQUIRE(mat4.Get(0, 1) == 11); REQUIRE(mat4.Get(0, 2) == 12); } +} +TEST_CASE("Advanced Matrix Operations", "Matrix") { SECTION("2x2 QRDecomposition") { Matrix<2, 2> A{1.0f, 2.0f, 3.0f, 4.0f}; Matrix<2, 2> Q{}, R{}; @@ -392,13 +394,6 @@ TEST_CASE("Elementary Matrix Operations", "Matrix") { Matrix<3, 3> Q{}, R{}; A.QRDecomposition(Q, R); - std::string strBuf1 = ""; - Q.ToString(strBuf1); - std::cout << "Matrix Q:\n" << strBuf1 << std::endl; - strBuf1 = ""; - R.ToString(strBuf1); - std::cout << "Matrix R:\n" << strBuf1 << std::endl; - // Check that Q * R ≈ A Matrix<3, 3> QR{}; Q.Mult(R, QR);