This is an example on how to use gaussSeidel.
#include "../../Test.h"
#include <vector>
class GaussSeidelTestCase : public Test
{
bool TestGaussSeidel() {
std::vector<double> expectedX = { -0.5f, 0.5f, 1.0f };
for(size_t i = 0; i < expectedX.size(); i++) { AssertEqual(result(i, 0), expectedX[i]); }
return true;
}
bool TestGaussSeidel2() {
std::vector<double> expectedX = { 1.0f, -2.0f };
for(size_t i = 0; i < expectedX.size(); i++) { AssertEqual(result(i, 0), expectedX[i]); }
return true;
}
bool TestGaussSeidelInverse() {
AssertEqual(out, A);
A = {
{
-1,
1,
1,
},
{
1,
-1,
1,
},
{
1,
1,
-1,
},
};
B = {
{
0,
1. / 2,
1. / 2,
},
{
1. / 2,
0,
1. / 2,
},
{
1. / 2,
1. / 2,
0,
},
};
std::cout << out;
AssertEqual(out, B);
A = {
{ -1, 1, 1, 1 },
{ 1, -1, 1, 1 },
{ 1, 1, -1, 1 },
{ 1, 1, 1, -1 },
};
B = {
{ -1. / 4, 1. / 4, 1. / 4, 1. / 4 },
{ 1. / 4, -1. / 4, 1. / 4, 1. / 4 },
{ 1. / 4, 1. / 4, -1. / 4, 1. / 4 },
{ 1. / 4, 1. / 4, 1. / 4, -1. / 4 },
};
AssertEqual(out, B);
A = {
{
-1,
1,
},
{
1,
-1,
},
};
B = { { INFINITY, INFINITY }, { INFINITY, INFINITY } };
AssertEqual(out, B);
return true;
}
public:
void run() override {
TestGaussSeidel();
TestGaussSeidel2();
TestGaussSeidelInverse();
}
};
int main() {
GaussSeidelTestCase().run();
return 0;
}
Matrix< double > gaussJordan(const Matrix< double > &A)
Definition: gaussJordan.h:27
Matrix< double > gaussSeidel(const Matrix< double > &A, const Matrix< double > &b)
Definition: gaussSeidel.h:29
Matrix< double > eye(size_t rows, size_t columns=0)