-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_MyLinearSystemSolver.cpp
More file actions
32 lines (32 loc) · 1.12 KB
/
Copy pathtest_MyLinearSystemSolver.cpp
File metadata and controls
32 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// Created by Chenxi Ma on 4/30/22.
//
#include <vector>
#include <iostream>
#include <cassert>
#include "MyLinearSystemSolver.h"
#include <math.h>
int main(){
std::cout<<"Now we verify the root solver of the matrix which appeared in 'Example of the algorithm' "
"section of wikipedia" << std::endl;
MyLinearSystemSolver x(3,4);
std::vector<double> container{2.0, 1.0, -1.0, 8.0, -3.0, -1.0, 2.0, -11.0,
-2.0, 1.0, 2.0, -3.0};
for (std::size_t row=0; row< x.nrows(); ++row){
for (std::size_t col=0; col < x.ncols(); ++col){
x(row,col)=container[row * (x.ncols())+col];
}
}
//this is the result of x,y, and z
//of above matrix, which is provided at wikipedia
std::vector<double> container2{2.0, 3.0, -1.0};
MyLinearSystemSolver y(3,1);
for (std::size_t row=0; row< y.nrows(); ++row){
y(row,0)=container2[row];
}
x.GaussianElimination();
MyLinearSystemSolver solution = x.BackSub();
std::cout<<"testing root finding"<<std::endl;
assert(solution==y);
std::cout << "all tests passed" << std::endl;
}