Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * basis for python code: https://github.com/AndrosovAS/QR-decomposition/blob/main/QR-decomposition.py
- * example: https://www.youtube.com/watch?v=MxZy0LLEDLY
- */
- #include <iostream>
- using namespace std;
- int main() {
- const int eps = 10000;
- const int N = 3;
- double A[N][N] = {
- {0., -1., 1.},
- {4., 2., 0.},
- {3., 4., 0.}
- };
- for (int col = 0; col < N; col++) {
- for (int row = col+1; row < N; row++) {
- if (A[row][col] != 0) {
- double r = sqrt(A[col][col] * A[col][col] + A[row][col] * A[row][col]);
- double c = A[col][col] / r;
- double s = -A[row][col] / r;
- for (int i = 0; i < N; i++) {
- double row_i, col_i;
- col_i = A[col][i] * c + A[row][i] * (-s);
- row_i = A[col][i] * s + A[row][i] * c;
- A[col][i] = col_i, A[row][i] = row_i;
- }
- }
- }
- }
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < N; j++) {
- cout << floor(A[i][j] * eps) / eps << '\t';
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement