Added comments and renamed functions
This commit is contained in:
parent
0a2ca3c0cf
commit
97e6b35112
19
src/main.cpp
19
src/main.cpp
@ -20,7 +20,7 @@
|
|||||||
#include "jacobi.hpp"
|
#include "jacobi.hpp"
|
||||||
|
|
||||||
|
|
||||||
void write_transformation(int N, bool dense)
|
void write_transformation_dense(int N)
|
||||||
{
|
{
|
||||||
std::ofstream ofile;
|
std::ofstream ofile;
|
||||||
|
|
||||||
@ -39,14 +39,14 @@ void write_transformation(int N, bool dense)
|
|||||||
|
|
||||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
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 << i << "," << iters << std::endl;
|
||||||
}
|
}
|
||||||
ofile.close();
|
ofile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void write_transformation(int N)
|
void write_transformation_tridiag(int N)
|
||||||
{
|
{
|
||||||
std::ofstream ofile;
|
std::ofstream ofile;
|
||||||
|
|
||||||
@ -54,6 +54,7 @@ void write_transformation(int N)
|
|||||||
double a, d;
|
double a, d;
|
||||||
|
|
||||||
ofile.open("../latex/output/transform_tridiag.csv");
|
ofile.open("../latex/output/transform_tridiag.csv");
|
||||||
|
// Write header line to file
|
||||||
ofile << "N,T" << std::endl;
|
ofile << "N,T" << std::endl;
|
||||||
|
|
||||||
// Increase size of matrix, start at 5 to avoid logic_error of N=4
|
// 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);
|
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 << i << "," << iters << std::endl;
|
||||||
}
|
}
|
||||||
ofile.close();
|
ofile.close();
|
||||||
@ -84,6 +85,7 @@ void write_eigenvec(int N)
|
|||||||
double d = 2. / (h*h);
|
double d = 2. / (h*h);
|
||||||
double x = 0.;
|
double x = 0.;
|
||||||
|
|
||||||
|
// Create tridiagonal matrix
|
||||||
arma::mat A = create_symmetric_tridiagonal(N, a, d);
|
arma::mat A = create_symmetric_tridiagonal(N, a, d);
|
||||||
arma::vec eigval;
|
arma::vec eigval;
|
||||||
arma::mat eigvec;
|
arma::mat eigvec;
|
||||||
@ -91,17 +93,21 @@ void write_eigenvec(int N)
|
|||||||
int iters;
|
int iters;
|
||||||
bool converged;
|
bool converged;
|
||||||
|
|
||||||
|
// Solve using Jacobi rotation method
|
||||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||||
|
|
||||||
std::ofstream ofile;
|
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.open("../latex/output/eigenvector_" + std::to_string(N) + ".csv");
|
||||||
ofile << "x,Vector 1,Vector 2,Vector 3" << std::endl;
|
ofile << "x,Vector 1,Vector 2,Vector 3" << std::endl;
|
||||||
|
|
||||||
|
// Add boundary value for x=0
|
||||||
ofile << scientific_format(0., 16) << ","
|
ofile << scientific_format(0., 16) << ","
|
||||||
<< scientific_format(0., 16) << ","
|
<< scientific_format(0., 16) << ","
|
||||||
<< scientific_format(0., 16) << ","
|
<< scientific_format(0., 16) << ","
|
||||||
<< scientific_format(0., 16) << std::endl;
|
<< 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++) {
|
for (int i = 0; i < N; i++) {
|
||||||
x += h;
|
x += h;
|
||||||
ofile << scientific_format(x, 16)<< ","
|
ofile << scientific_format(x, 16)<< ","
|
||||||
@ -109,6 +115,7 @@ void write_eigenvec(int N)
|
|||||||
<< scientific_format(eigvec(i,1), 16) << ","
|
<< scientific_format(eigvec(i,1), 16) << ","
|
||||||
<< scientific_format(eigvec(i,2), 16) << std::endl;
|
<< scientific_format(eigvec(i,2), 16) << std::endl;
|
||||||
}
|
}
|
||||||
|
// Add boundary value for x=1
|
||||||
ofile << scientific_format(1., 16) << ","
|
ofile << scientific_format(1., 16) << ","
|
||||||
<< scientific_format(0., 16) << ","
|
<< scientific_format(0., 16) << ","
|
||||||
<< scientific_format(0., 16) << ","
|
<< scientific_format(0., 16) << ","
|
||||||
@ -119,8 +126,8 @@ void write_eigenvec(int N)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
write_transformation(100);
|
write_transformation_tridiag(100);
|
||||||
write_transformation(100, true);
|
write_transformation_dense(100);
|
||||||
write_eigenvec(6);
|
write_eigenvec(6);
|
||||||
write_eigenvec(100);
|
write_eigenvec(100);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user