Create test for creating symmetric tridiagonals

This commit is contained in:
Cory Balaton 2023-09-17 16:23:16 +02:00
parent 514cb20064
commit 942a58b1dc
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B

View File

@ -1,6 +1,8 @@
#include <cassert>
#include <cmath>
#include <iostream>
#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() {