From 942a58b1dc842a57a955b71391401d5f57a7ea11 Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 17 Sep 2023 16:23:16 +0200 Subject: [PATCH] Create test for creating symmetric tridiagonals --- src/test_suite.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test_suite.cpp b/src/test_suite.cpp index e92af50..dc13845 100644 --- a/src/test_suite.cpp +++ b/src/test_suite.cpp @@ -1,6 +1,8 @@ #include #include +#include +#include "utils.hpp" #include "matrix.hpp" void test_create_symmetric_tridiagonal() { @@ -21,6 +23,28 @@ void test_create_symmetric_tridiagonal() { diff = eigval(i) - (d + 2.*a*std::cos(((i+1.)*M_PI)/(N+1.))); assert(std::abs(diff) < tol); } + + arma::vec v, res, analytic_vec = arma::vec(N); + for (int i=0; i < N; i++) { + v = eigvec.col(i); + + // Build the analytic vector + for (int j=0; j < N; j++) { + analytic_vec(j) = std::sin(((j+1.)*(i+1.)*M_PI) / (N+1.)); + } + + analytic_vec = arma::normalise(analytic_vec); + + // flip the sign of the analytic vector if they are different + if (analytic_vec(0)*v(0) < 0.) { + analytic_vec *= -1; + } + + res = v - analytic_vec; + for (int j=0; j < N; j++) { + assert(std::abs(res(j)) < tol); + } + } } void test_max_off_diag_symmetric() {