The purpose of this page is to test the MODIFIED Gram-Schmidt process on various sizes of Hilbert matrices. To summarize the results presented below, the Modified Gram-Schmidt procedure produces orthogonal QR decompositions up n = 10 whereas the Classical Gram-Schmidt process failed to produce orthogonal matrices at n = 6. The function being used for the following tests is QRDecomp_MGS. For Hilbert matrices of size 4 we have the following:
The QR decomposition for the Hilbert matrix of size 4 is:
0.8381 -0.5226 0.1540 -0.0263
0.4191 0.4417 -0.7278 0.3157
0.2794 0.5288 0.1395 -0.7892
0.2095 0.5021 0.6536 0.5261
The product (Q^T)Q is:
1.0000 0.0000 -0.0000 0.0000
0.0000 1.0000 0.0000 -0.0000
-0.0000 0.0000 1.0000 -0.0000
0.0000 -0.0000 -0.0000 1.0000
This data shows that Q is orthogonal. For the Hilbert matrix of size 6 we have the following:
The QR decomposition for the Hilbert matrix of size 6 is:
0.8189 -0.5397 0.1893 -0.0482 0.0090 -0.0011
0.4094 0.3320 -0.7024 0.4489 -0.1617 0.0331
0.2730 0.4219 -0.1529 -0.5723 0.5854 -0.2320
0.2047 0.4067 0.2015 -0.3866 -0.4687 0.6188
0.1638 0.3735 0.3963 0.0915 -0.4285 -0.6961
0.1365 0.3399 0.4998 0.5574 0.4773 0.2785
The product (Q^T)Q is:
1.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000
-0.0000 1.0000 -0.0000 0.0000 -0.0000 0.0000
0.0000 -0.0000 1.0000 -0.0000 0.0000 -0.0000
-0.0000 0.0000 -0.0000 1.0000 0.0000 -0.0000
0.0000 -0.0000 0.0000 0.0000 1.0000 0.0000
0.0000 0.0000 -0.0000 -0.0000 0.0000 1.0000
This data shows that Q orthogonal. For the Hilbert matrix of size 8 we have the following:
The QR decomposition for the Hilbert matrix of size 8 is:
0.8091 -0.5467 0.2064 -0.0605 0.0144 -0.0028 0.0004 -0.0000
0.4046 0.2825 -0.6766 0.4934 -0.2236 0.0713 -0.0161 0.0023
0.2697 0.3736 -0.2413 -0.4274 0.6135 -0.3854 0.1444 -0.0313
0.2023 0.3636 0.0543 -0.4519 -0.1109 0.5920 -0.4762 0.1738
0.1618 0.3354 0.2226 -0.2124 -0.4481 0.0758 0.5760 -0.4778
0.1349 0.3059 0.3161 0.0579 -0.3360 -0.4428 0.0508 0.6881
0.1156 0.2792 0.3669 0.2932 0.0292 -0.3318 -0.5746 -0.4969
0.1011 0.2559 0.3929 0.4813 0.4965 0.4289 0.2959 0.1420
The product (Q^T)Q is:
1.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000
-0.0000 1.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000
0.0000 0.0000 1.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000
-0.0000 -0.0000 0.0000 1.0000 -0.0000 0.0000 -0.0000 0.0000
0.0000 -0.0000 0.0000 -0.0000 1.0000 0.0000 -0.0000 0.0000
-0.0000 0.0000 -0.0000 0.0000 0.0000 1.0000 -0.0000 -0.0000
0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 1.0000 0.0000
-0.0000 0.0000 -0.0000 0.0000 0.0000 -0.0000 0.0000 1.0000
This data shows that Q is orthogonal. For the Hilbert matrix of size 10 we have the following:
The QR decomposition for the Hilbert matrix of size 10 is:
0.8033 -0.5503 0.2165 -0.0683 0.0183 -0.0042 0.0008 -0.0001 0.0000 -0.0001
0.4016 0.2544 -0.6577 0.5136 -0.2592 0.0977 -0.0287 0.0066 -0.0011 0.0002
0.2678 0.3461 -0.2809 -0.3399 0.5977 -0.4499 0.2198 -0.0761 0.0187 -0.0028
0.2008 0.3390 -0.0159 -0.4411 0.0574 0.4711 -0.5481 0.3293 -0.1229 0.0271
0.1607 0.3136 0.1384 -0.2974 -0.3151 0.3096 0.2862 -0.5685 0.3882 -0.1315
0.1339 0.2866 0.2263 -0.1080 -0.3863 -0.1288 0.4097 0.1763 -0.5802 0.3685
0.1148 0.2618 0.2759 0.0658 -0.2638 -0.3766 -0.0270 0.4397 0.2350 -0.6141
0.1004 0.2401 0.3029 0.2094 -0.0461 -0.3289 -0.3968 -0.0963 0.3973 0.6016
0.0893 0.2213 0.3162 0.3230 0.2056 -0.0275 -0.3025 -0.4969 -0.5052 -0.3195
0.0803 0.2049 0.3213 0.4108 0.4577 0.4505 0.3887 0.2863 0.1704 0.0711
The product (Q^T)Q is:
1.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000
0.0000 1.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0002
-0.0000 -0.0000 1.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000
0.0000 0.0000 0.0000 1.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 1.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000
0.0000 0.0000 -0.0000 -0.0000 -0.0000 1.0000 0.0000 -0.0000 0.0000 -0.0000
-0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 -0.0000 -0.0000 0.0000
-0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 1.0000 0.0000 0.0000
0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 1.0000 -0.0000
0.0000 0.0002 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 1.0000
This data shows that Q is very nearly orthogonal.
This data was generated using the code below:
int m = 4;
array2D A,QR;
A = HilbertMat(m);
QR = QRDecomp_MGS(A);
std::cout << std::endl << "The QR decomposition for the Hilbert matrix of size " << m << " is:" << std::endl;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
std::cout << std::fixed << std::setw(7) << std::setprecision(4) << QR(i,j) << " ";
}
std::cout << std::endl;
}
std::cout << std::endl << "The product (Q^T)Q is:" << std::endl;
double sum = 0.0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
sum = 0.0;
for (int k = 0; k < m; k++) {
sum += QR(k, i) * QR(k, j);
}
std::cout << std::fixed << std::setw(7) << std::setprecision(4) << sum << " ";
}
std::cout << std::endl;
}