-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateQRs.cpp
78 lines (73 loc) · 1.61 KB
/
generateQRs.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<iostream>
#include<armadillo> //see http://arma.sourceforge.net/, better than lapack alone
using namespace std;
using namespace arma;
void print_matrixWithMorePrecision(const mat &A);
int main(int argc, char** argv){
/*
mat A = randu<mat>(4,4);
mat B = randu<mat>(4,4);
cout << "A is: " << endl << A;
cout << "B is: " << endl << B << endl;
cout << "A*B is: " << endl;
cout << A*B << endl;
cout << "B transposed is:" << endl;
cout << B.t() << endl;
cout << "A * Btransposed is:" << endl;
cout << A*B.t() << endl;
*/
/*
4 5 4
4 8 8
2 6 6
1 7 4
6 1 7
*/
mat A = mat(6,3);
A(0,0) = 4;
A(0,1) = 5;
A(0,2) = 4;
A(1,0) = 4;
A(1,1) = 8;
A(1,2) = 8;
A(2,0) = 2;
A(2,1) = 6;
A(2,2) = 6;
A(3,0) = 1;
A(3,1) = 7;
A(3,2) = 4;
A(4,0) = 6;
A(4,1) = 1;
A(4,2) = 7;
A(5,0) = 9;
A(5,1) = 0;
A(5,2) = 2;
cout << "Matrix A:" << endl << A << endl;
cout << "QR factorization according to Armadillo++ lib (using lapack under the hood):" << endl;
mat Q, R;
qr(Q,R,A);
cout << "Q:" << endl;
//does not have desired effect
//cout.precision(9);
//cout << Q;
//cout << "R:" << endl << R;
//mat * const pMatQ = &Q;
//const mat * const pMatR = &R;
print_matrixWithMorePrecision(Q);
cout << "R:" << endl;
print_matrixWithMorePrecision(R);
return 0;
}
void print_matrixWithMorePrecision(const mat &A){
cout.precision(9);
cout.width(9);
double temp = 0.0;
for(int i = 0; i < A.n_rows; i++){
for(int j = 0; j < A.n_cols; j++){
temp = A(i,j);
cout<<(temp);
cout<<("\t");
}
cout<<("\n");
}
}