24 unsigned int ROWS, COLUMNS;
26 std::cout <<
"Enter the number of rows and columns: ";
27 std::cin >> ROWS >> COLUMNS;
29 std::cout <<
"Enter matrix elements row-wise:\n";
31 std::valarray<std::valarray<double>> A(ROWS);
32 std::valarray<std::valarray<double>> Q(ROWS);
33 std::valarray<std::valarray<double>> R(COLUMNS);
34 for (
int i = 0; i < std::max(ROWS, COLUMNS); i++) {
36 A[i] = std::valarray<double>(COLUMNS);
37 Q[i] = std::valarray<double>(COLUMNS);
40 R[i] = std::valarray<double>(COLUMNS);
44 for (
int i = 0; i < ROWS; i++)
45 for (
int j = 0; j < COLUMNS; j++) std::cin >> A[i][j];
47 std::cout << A <<
"\n";
50 qr_decompose(A, &Q, &R);
51 double dtime =
static_cast<double>(clock() - t1) / CLOCKS_PER_SEC;
53 std::cout << Q <<
"\n";
54 std::cout << R <<
"\n";
55 std::cout <<
"Time taken to compute: " << dtime <<
" sec\n ";