25 #ifndef WLINEARALGEBRAFUNCTIONS_TEST_H
26 #define WLINEARALGEBRAFUNCTIONS_TEST_H
30 #include <cxxtest/TestSuite.h>
32 #include "../../WException.h"
33 #include "../../WLimits.h"
34 #include "../WLinearAlgebraFunctions.h"
35 #include "../WMatrix.h"
36 #include "../linearAlgebra/WVectorFixed.h"
37 #include "WVector3dTraits.h"
54 for(
size_t r = 0; r < 3; ++r)
56 for(
size_t c = 0; c < 3; ++c, ++i )
61 WVector3d result = multMatrixWithVector3D( m, v );
63 TS_ASSERT_EQUALS( result, expected );
73 for(
size_t r = 0; r < 3; ++r)
75 for(
size_t c = 0; c < 3; ++c, ++i )
82 expected( 0, 0 ) = 1./6 * -8;
83 expected( 0, 1 ) = 1./6 * 8;
84 expected( 0, 2 ) = 1./6 * -3;
85 expected( 1, 0 ) = 1./6 * 6;
86 expected( 1, 1 ) = 1./6 * -12;
87 expected( 1, 2 ) = 1./6 * 6;
88 expected( 2, 0 ) = 1./6 * 0;
89 expected( 2, 1 ) = 1./6 * 6;
90 expected( 2, 2 ) = 1./6 * -3;
91 TS_ASSERT_EQUALS( invertMatrix3x3( m ), expected );
101 for(
size_t r = 0; r < 3; ++r)
103 for(
size_t c = 0; c < 3; ++c, ++i )
108 TS_ASSERT_THROWS( invertMatrix3x3( m ),
WException& e );
120 for(
size_t r = 0; r < 4; ++r)
122 for(
size_t c = 0; c < 4; ++c )
124 m( c, r ) = r + c * 4 + 1;
136 TS_ASSERT( m_m_inv ==
id );
146 TS_ASSERT( linearIndependent( u, v ) );
147 TS_ASSERT( linearIndependent( v, u ) );
148 TS_ASSERT( !linearIndependent( v, v ) );
158 TS_ASSERT( !linearIndependent( u, v ) );
159 TS_ASSERT( !linearIndependent( v, u ) );
160 TS_ASSERT( !linearIndependent( u, u ) );
170 TS_ASSERT( !linearIndependent( u, v ) );
171 TS_ASSERT( !linearIndependent( v, u ) );
172 TS_ASSERT( !linearIndependent( u, u ) );
174 TS_ASSERT( linearIndependent( u, v ) );
175 TS_ASSERT( linearIndependent( v, u ) );
176 TS_ASSERT( !linearIndependent( u, u ) );
184 const size_t nbRows = 3, nbCols = 3;
185 const double a = 1.2, b = 2.3, c = 3.4,
186 d = 4.5, e = 5.6, f = 6.7,
187 g = 3.4, h = 1.2, i = 7.0;
201 computeSVD( A, U, V, Svec );
204 for(
size_t i = 0; i < Svec.size(); ++i )
206 S( i, i ) = Svec[ i ];
211 for(
size_t row = 0; row < A.
getNbRows(); ++row )
213 for(
size_t col = 0; col < A.
getNbCols(); ++col )
215 TS_ASSERT_DELTA( A( row, col ), A2( row, col ), 0.0001 );
226 const size_t nbRows = 3, nbCols = 3;
227 const double a = 1.2, b = 2.3, c = 3.4,
228 d = 4.5, e = 5.6, f = 6.7,
229 g = 3.4, h = 1.2, i = 7.0;
244 for(
size_t row = 0; row < I.
getNbRows(); row++ )
246 for(
size_t col = 0; col < I.
getNbCols(); col++ )
250 TS_ASSERT_DELTA( I( row, col ), 1.0, 0.0001 );
254 TS_ASSERT_DELTA( I( row, col ), 0.0, 0.0001 );
261 for(
int j = 0; j < 6; ++j )
263 for(
int i = 0; i < 6; ++i )
265 m( i, j ) = pow( i + 1, j );
268 m = m * pseudoInverse( m );
269 for(
int j = 0; j < 6; ++j )
271 for(
int i = 0; i < 6; ++i )
273 TS_ASSERT_DELTA( m( i, j ), i == j ? 1.0 : 0.0, 0.0001 );
280 #endif // WLINEARALGEBRAFUNCTIONS_TEST_H
void testMatrixVectorMultiply(void)
The vector multiplied with the matrix is just a new vector where each component is the dot product of...
Base class for all higher level values like tensors, vectors, matrices and so on. ...
size_t getNbCols() const
Get number of columns.
void test3x3MatrixInversionOnSingularMatrix(void)
On singular matrices no inverse exists!
void testPseudoInverse(void)
Test pseudoInverse calculation.
void testLinearIndependeceOfTheNullVector(void)
Two vectors are linear independent if the are not parallel.
void testLinearIndependenceOnNumericalStability(void)
Small changes should nothing do to correctness.
const double DBL_EPS
Smallest double such: 1.0 + DBL_EPS == 1.0 is still true.
void test4x4Inverse()
Test the inversion of 4x4 matrices.
void testComputeSVD(void)
Test SVD calculation.
size_t getNbRows() const
Get number of rows.
void test3x3MatrixInversion(void)
If the matrix is not singular then an inverse should exist and be definite.
void testLinearIndependeceOfTwoVectors(void)
Two vectors are linear independent if the are not parallel.