diff --git a/src/main.cpp b/src/main.cpp index 3a55c90..1a1b1d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ #include "jacobi.hpp" -void write_transformation(int N, bool dense) +void write_transformation_dense(int N) { std::ofstream ofile; @@ -39,14 +39,14 @@ void write_transformation(int N, bool dense) jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged); - // Write size, number of iterations, and converge status to file + // Write size, and number of iterations to file ofile << i << "," << iters << std::endl; } ofile.close(); } -void write_transformation(int N) +void write_transformation_tridiag(int N) { std::ofstream ofile; @@ -54,6 +54,7 @@ void write_transformation(int N) double a, d; ofile.open("../latex/output/transform_tridiag.csv"); + // Write header line to file ofile << "N,T" << std::endl; // Increase size of matrix, start at 5 to avoid logic_error of N=4 @@ -70,7 +71,7 @@ void write_transformation(int N) jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged); - // Write size, number of iterations, and converge status to file + // Write size, and number of iterations to file ofile << i << "," << iters << std::endl; } ofile.close(); @@ -84,6 +85,7 @@ void write_eigenvec(int N) double d = 2. / (h*h); double x = 0.; + // Create tridiagonal matrix arma::mat A = create_symmetric_tridiagonal(N, a, d); arma::vec eigval; arma::mat eigvec; @@ -91,17 +93,21 @@ void write_eigenvec(int N) int iters; bool converged; + // Solve using Jacobi rotation method jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged); std::ofstream ofile; + // Create file based on matrix size, and write header line to file ofile.open("../latex/output/eigenvector_" + std::to_string(N) + ".csv"); ofile << "x,Vector 1,Vector 2,Vector 3" << std::endl; + // Add boundary value for x=0 ofile << scientific_format(0., 16) << "," << scientific_format(0., 16) << "," << scientific_format(0., 16) << "," << scientific_format(0., 16) << std::endl; + // Add x-value and element i of each eigenvector to same line for (int i = 0; i < N; i++) { x += h; ofile << scientific_format(x, 16)<< "," @@ -109,6 +115,7 @@ void write_eigenvec(int N) << scientific_format(eigvec(i,1), 16) << "," << scientific_format(eigvec(i,2), 16) << std::endl; } + // Add boundary value for x=1 ofile << scientific_format(1., 16) << "," << scientific_format(0., 16) << "," << scientific_format(0., 16) << "," @@ -119,8 +126,8 @@ void write_eigenvec(int N) int main() { - write_transformation(100); - write_transformation(100, true); + write_transformation_tridiag(100); + write_transformation_dense(100); write_eigenvec(6); write_eigenvec(100); return 0;