Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- AGHMatrix<T> AGHMatrix<T>::without_row_and_column(int row, int col) {
- AGHMatrix<T> new_matrix = *this;
- new_matrix.rows--;
- new_matrix.cols--;
- new_matrix.matrix.erase(new_matrix.matrix.begin() + row);
- for (int y = 0; y < new_matrix.rows; y++) {
- new_matrix.matrix[y].erase(new_matrix.matrix[y].begin() + col);
- }
- return new_matrix;
- }
- template <typename T>
- T& AGHMatrix<T>::determinant() {
- std::cout << "determinant: " << this->rows << "x" << this->cols
- << std::endl;
- if (this->cols == 1) return this->matrix[0][0];
- T retval = 0;
- int coeff = 1;
- for (int x = 0; x < this->cols; x++) {
- std::cout << x << " / " << this->cols << std::endl;
- T det = this->without_row_and_column(0, x).determinant();
- retval += coeff * this->matrix[0][x] * det;
- coeff *= -1;
- }
- std::cout << "returning from " << this->rows << "x" << this->cols
- << " with value of " << retval << std::endl;
- return retval;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement