inverse does not work yet

This commit is contained in:
Marc Wäckerlin
2016-08-22 07:07:22 +00:00
parent 8985f1a5e8
commit 549db697b7
3 changed files with 200 additions and 80 deletions

View File

@@ -169,6 +169,53 @@ class TemplateMatrixTest: public CppUnit::TestFixture {
3, 6);
CPPUNIT_ASSERT_EQUAL(res, m.t());
}
template<typename T>
void gauss() {
Matrix<T,3,3> m(2, -2, 4,
-2, 1, -6,
1, 0, -2);
const Matrix<T,3,3> res(1, -1, 2,
0, -1, -2,
0, 0, -6);
T lambda(m.gauss());
CPPUNIT_ASSERT_EQUAL(res, m);
CPPUNIT_ASSERT_EQUAL((T)2, lambda);
}
template<typename T>
void det() {
Matrix<T,3,3> m(2, -2, 4,
-2, 1, -6,
1, 0, -2);
CPPUNIT_ASSERT_EQUAL((T)12, m.det());
}
template<typename T>
void i() {
const Matrix<T,3,3> m1(1, 0, 0,
0, 1, 0,
0, 0, 1);
const Matrix<T,3,2> m2(1, 0,
0, 1,
0, 0);
const Matrix<T,2,3> m3(1, 0, 0,
0, 1, 0);
CPPUNIT_ASSERT_EQUAL(m1, m1.i());
CPPUNIT_ASSERT_EQUAL(m2, m2.i());
CPPUNIT_ASSERT_EQUAL(m3, m3.i());
}
template<typename T>
void inv() {
Matrix<T,3,3> m(2, -1, 0,
1, 2, -2,
0, -1, 1);
const Matrix<T,3,3> res(0.5, 0, 0,
-0.2, 0.4, 0,
-1, 2, 5);
// const Matrix<T,3,3> res(0, 1, 2,
// -1, 2, 4,
// -1, 2, 5);
m.inv();
CPPUNIT_ASSERT_EQUAL(res, m);
}
CPPUNIT_TEST_SUITE(TemplateMatrixTest);
CPPUNIT_TEST(initFromArray1<int>);
CPPUNIT_TEST(initFromArray1<long>);
@@ -236,6 +283,22 @@ class TemplateMatrixTest: public CppUnit::TestFixture {
CPPUNIT_TEST(transpose<unsigned long>);
CPPUNIT_TEST(transpose<float>);
CPPUNIT_TEST(transpose<double>);
CPPUNIT_TEST(gauss<int>);
CPPUNIT_TEST(gauss<long>);
CPPUNIT_TEST(gauss<float>);
CPPUNIT_TEST(gauss<double>);
CPPUNIT_TEST(det<int>);
CPPUNIT_TEST(det<long>);
CPPUNIT_TEST(det<float>);
CPPUNIT_TEST(det<double>);
CPPUNIT_TEST(i<int>);
CPPUNIT_TEST(i<long>);
CPPUNIT_TEST(i<unsigned>);
CPPUNIT_TEST(i<unsigned long>);
CPPUNIT_TEST(i<float>);
CPPUNIT_TEST(i<double>);
CPPUNIT_TEST(inv<float>);
CPPUNIT_TEST(inv<double>);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(TemplateMatrixTest);
@@ -400,6 +463,45 @@ class VariableMatrixTest: public CppUnit::TestFixture {
3, 6);
CPPUNIT_ASSERT_EQUAL(res, m.t());
}
template<typename T>
void gauss() {
Matrix<T> m(3, 3,
2, -2, 4,
-2, 1, -6,
1, 0, -2);
const Matrix<T> res(3,3,
1, -1, 2,
0, -1, -2,
0, 0, -6);
T lambda(m.gauss());
CPPUNIT_ASSERT_EQUAL(res, m);
CPPUNIT_ASSERT_EQUAL((T)2, lambda);
}
template<typename T>
void det() {
Matrix<T> m(3, 3,
2, -2, 4,
-2, 1, -6,
1, 0, -2);
CPPUNIT_ASSERT_EQUAL((T)12, m.det());
}
template<typename T>
void i() {
const Matrix<T> m1(3, 3,
1, 0, 0,
0, 1, 0,
0, 0, 1);
const Matrix<T> m2(3, 2,
1, 0,
0, 1,
0, 0);
const Matrix<T> m3(2, 3,
1, 0, 0,
0, 1, 0);
CPPUNIT_ASSERT_EQUAL(m1, m1.i());
CPPUNIT_ASSERT_EQUAL(m2, m2.i());
CPPUNIT_ASSERT_EQUAL(m3, m3.i());
}
CPPUNIT_TEST_SUITE(VariableMatrixTest);
CPPUNIT_TEST(initFromArray1<int>);
CPPUNIT_TEST(initFromArray1<long>);
@@ -467,6 +569,20 @@ class VariableMatrixTest: public CppUnit::TestFixture {
CPPUNIT_TEST(transpose<unsigned long>);
CPPUNIT_TEST(transpose<float>);
CPPUNIT_TEST(transpose<double>);
CPPUNIT_TEST(gauss<int>);
CPPUNIT_TEST(gauss<long>);
CPPUNIT_TEST(gauss<float>);
CPPUNIT_TEST(gauss<double>);
CPPUNIT_TEST(det<int>);
CPPUNIT_TEST(det<long>);
CPPUNIT_TEST(det<float>);
CPPUNIT_TEST(det<double>);
CPPUNIT_TEST(i<int>);
CPPUNIT_TEST(i<long>);
CPPUNIT_TEST(i<unsigned>);
CPPUNIT_TEST(i<unsigned long>);
CPPUNIT_TEST(i<float>);
CPPUNIT_TEST(i<double>);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(VariableMatrixTest);