Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. template <typename T>
  2. std::pair<AGHMatrix<T>, AGHMatrix<T>> AGHMatrix<T>::LU() {
  3.     std::vector<std::vector<T>> U = this->matrix;
  4.  
  5.     std::vector<std::vector<T>> L;
  6.     for (int y = 0; y < this->rows; y++) {
  7.         std::vector<T> L_row(this->cols, 0);
  8.         L_row[y] = 1;
  9.         L.push_back(L_row);
  10.     }
  11.  
  12.     for (int x = 0; x < this->cols; x++) {
  13.         for (int i = x + 1; i < this->cols; i++) {
  14.             T l = -U[i][x] / U[x][x];
  15.  
  16.             for (int j = x; j < this->cols; j++) {
  17.                 U[i][j] += l * U[x][j];
  18.             }
  19.  
  20.             L[i][x] = -l;
  21.         }
  22.     }
  23.  
  24.     return std::make_pair(AGHMatrix<T>(L), AGHMatrix<T>(U));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement