int main() { int m = m, n = 4; array double a[4][4] = {1, 5, -7, 4, 3, 2, 5, 2, 3, 2, 5, 2, 3, 9, 5, 2}; /* a[m][n] */ array double q[n][n]; array double r[n][n]; qrdecomp(a, q, r); printf("q = \n%f\n", q); printf("r = \n%f\n", r); printf("q*r = \n%f\n", q*r); m = 2; n = 4; array double a1[2][4] = {1, 5, -7, 4, 3, 2, 5, 2}; /* a[m][n] */ array double q1[m][m]; // m<n array double r1[m][n]; qrdecomp(a1, q1, r1); printf("q1^T*q1 = \n%f\n", transpose(q1)*q1); printf("q1 = \n%f\n", q1); printf("r1 = \n%f\n", r1); printf("q1*r1 = \n%f\n", q1*r1); array double a2[4][2] = {1, 5, -7, 4, 3, 2, 5, 2}; /* a[m][n] */ m = 4; n = 2; array double q2[m][n], q21[m][m]; // m>=n array double r2[n][n], r21[m][n]; int status; status = qrdecomp(a2, q21, r21); if(status == 0) { printf("q21^T*q21 = \n%f\n", transpose(q21)*q21); printf("q21 = \n%f\n", q21); printf("r21 = \n%f\n", r21); printf("q21*r21 = \n%f\n", q21*r21); } else printf("error: numerical error in qrdecomp()\n"); status = qrdecomp(a2, q2, r2); if(status == 0) { printf("q2^T*q2 = \n%f\n", transpose(q2)*q2); printf("q2 = \n%f\n", q2); printf("r2 = \n%f\n", r2); printf("q2*r2 = \n%f\n", q2*r2); } else printf("error: numerical error in qrdecomp()\n"); }
q = -0.188982 0.511914 0.837991 0.000000 -0.566947 -0.405266 0.119713 0.707107 -0.566947 -0.405266 0.119713 -0.707107 -0.566947 0.639893 -0.518756 -0.000000 r = -5.291503 -8.315218 -7.181325 -4.157609 0.000000 6.697548 -4.436592 1.706382 0.000000 0.000000 -7.262591 2.793304 0.000000 0.000000 0.000000 0.000000 q*r = 1.000000 5.000000 -7.000000 4.000000 3.000000 2.000000 5.000000 2.000000 3.000000 2.000000 5.000000 2.000000 3.000000 9.000000 5.000000 2.000000 q1^T*q1 = 1.000000 0.000000 0.000000 1.000000 q1 = -0.316228 -0.948683 -0.948683 0.316228 r1 = -3.162278 -3.478505 -2.529822 -3.162278 0.000000 -4.110961 8.221922 -3.162278 q1*r1 = 1.000000 5.000000 -7.000000 4.000000 3.000000 2.000000 5.000000 2.000000 q21^T*q21 = 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 q21 = -0.109109 -0.730552 -0.408074 -0.536530 0.763763 -0.491027 0.173257 0.381499 -0.327327 -0.323359 0.873744 -0.157694 -0.545545 -0.347312 -0.200072 0.736021 r21 = -9.165151 0.763763 0.000000 -6.958209 0.000000 0.000000 0.000000 0.000000 q21*r21 = 1.000000 5.000000 -7.000000 4.000000 3.000000 2.000000 5.000000 2.000000 q2^T*q2 = 1.000000 0.000000 0.000000 1.000000 q2 = -0.109109 -0.730552 0.763763 -0.491027 -0.327327 -0.323359 -0.545545 -0.347312 r2 = -9.165151 0.763763 0.000000 -6.958209 q2*r2 = 1.000000 5.000000 -7.000000 4.000000 3.000000 2.000000 5.000000 2.000000