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++ 1.04 KB | None | 0 0
  1. template <typename T>
  2. AGHMatrix<T> AGHMatrix<T>::without_row_and_column(int row, int col) {
  3.     AGHMatrix<T> new_matrix = *this;
  4.  
  5.     new_matrix.rows--;
  6.     new_matrix.cols--;
  7.  
  8.     new_matrix.matrix.erase(new_matrix.matrix.begin() + row);
  9.  
  10.     for (int y = 0; y < new_matrix.rows; y++) {
  11.         new_matrix.matrix[y].erase(new_matrix.matrix[y].begin() + col);
  12.     }
  13.  
  14.     return new_matrix;
  15. }
  16.  
  17. template <typename T>
  18. T& AGHMatrix<T>::determinant() {
  19.     std::cout << "determinant: " << this->rows << "x" << this->cols
  20.               << std::endl;
  21.     if (this->cols == 1) return this->matrix[0][0];
  22.  
  23.     T retval = 0;
  24.     int coeff = 1;
  25.  
  26.     for (int x = 0; x < this->cols; x++) {
  27.         std::cout << x << " / " << this->cols << std::endl;
  28.         T det = this->without_row_and_column(0, x).determinant();
  29.         retval += coeff * this->matrix[0][x] * det;
  30.         coeff *= -1;
  31.     }
  32.  
  33.     std::cout << "returning from " << this->rows << "x" << this->cols
  34.               << " with value of " << retval << std::endl;
  35.     return retval;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement