Peano
Loading...
Searching...
No Matches
GramSchmidtTest.cpp
Go to the documentation of this file.
1#include "GramSchmidtTest.h"
2#include "tarch/la/Matrix.h"
6
7
8
9
11 TestCase ("tarch::la::GramSchmidtTest") {
12}
13
14
16 testMethod (testModifiedGramSchmidt);
17}
18
19
22
23 // Set values according to Hilbert matrix.
24 for (int i=0; i < 4; i++) {
25 for (int j=0; j < 4; j++) {
26 double entry = 1.0 / static_cast<double>(i + j + 1);
27 A(i,j) = entry;
28 }
29 }
30
31 Matrix<4,4,double> Acopy(A);
34 modifiedGramSchmidt (Acopy, Q, R);
35
36 Matrix<4,4,double> QTQ(0.0);
37 QTQ = multiply(transpose(Q), Q);
38
39 for (int i=0; i < 4; i++) {
40 for (int j=0; j < 4; j++) {
41 if (i == j) {
42 validate (equals(QTQ(i,j), 1.0, 1e-12));
43 }
44 else {
45 validate (equals(QTQ(i,j), 0.0, 1e-12));
46 }
47 }
48 }
49
50 for (int i=0; i < 4; i++) {
51 for (int j=0; j < 4; j++) {
52 double value = 0.0;
53 for ( int k=0; k < Q.cols(); k++ ) {
54 value += Q(i,k) * R(k,j);
55 }
56 validate (equals(value, A(i,j)));
57 value = 0.0;
58 }
59 }
60}
#define validate(booleanExpr)
Definition TestMacros.h:37
#define testMethod(name)
Run a test method and check for errors.
Definition TestMacros.h:24
Static (i.e.
Definition Matrix.h:42
virtual void run() override
This routine is triggered by the TestCaseCollection.
void testModifiedGramSchmidt()
Tests constructors.
DynamicMatrix transpose(const DynamicMatrix &matrix)
Matrix< Rows, Cols, Scalar > multiply(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
Performs a matrix x matrix multiplication.
void modifiedGramSchmidt(Matrix< Rows, Cols, Scalar > A, Matrix< Rows, Cols, Scalar > &Q, Matrix< Cols, Cols, Scalar > &R)
Produces an economy-size QR decomposition of a matrix A, A is changed.
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.