Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
qr_decomposition.cpp File Reference

Program to compute the QR decomposition of a given matrix. More...

#include <array>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include "./qr_decompose.h"
Include dependency graph for qr_decomposition.cpp:

Functions

int main (void)
 

Detailed Description

Program to compute the QR decomposition of a given matrix.

Author
Krishna Vedala

Function Documentation

◆ main()

int main ( void )

main function

23 {
24 unsigned int ROWS, COLUMNS;
25
26 std::cout << "Enter the number of rows and columns: ";
27 std::cin >> ROWS >> COLUMNS;
28
29 std::cout << "Enter matrix elements row-wise:\n";
30
34 for (int i = 0; i < std::max(ROWS, COLUMNS); i++) {
35 if (i < ROWS) {
36 A[i] = std::valarray<double>(COLUMNS);
37 Q[i] = std::valarray<double>(COLUMNS);
38 }
39 if (i < COLUMNS) {
40 R[i] = std::valarray<double>(COLUMNS);
41 }
42 }
43
44 for (int i = 0; i < ROWS; i++)
45 for (int j = 0; j < COLUMNS; j++) std::cin >> A[i][j];
46
47 std::cout << A << "\n";
48
49 clock_t t1 = clock();
50 qr_decompose(A, &Q, &R);
51 double dtime = static_cast<double>(clock() - t1) / CLOCKS_PER_SEC;
52
53 std::cout << Q << "\n";
54 std::cout << R << "\n";
55 std::cout << "Time taken to compute: " << dtime << " sec\n ";
56
57 return 0;
58}
T clock(T... args)
T max(T... args)
Here is the call graph for this function: