Tell me how to implement the construction of the matrix in the degree. Thank.
Closed due to the fact that the essence of the question is incomprehensible by the participants Vladimir Martianov , aleksandr barakin , user194374, Denis , Alex Nov 30 '16 at 14:26 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
1 answer
Look, here is an excerpt from my decision, it may come in handy.
First, we implement a method that multiplies two matrices, which is used further in the involution method.
Matrix Matrix::mul(Matrix &matrix, bool flag) { Matrix matrixC(this->str, matrix.stolb); if (this->stolb == matrix.str) { for (size_t i = 0; i < this->str; i++) for (size_t j = 0; j < matrix.stolb; j++) { matrixC.matrix[i][j] = 0; for (size_t k = 0; k < this->stolb; k++) matrixC.matrix[i][j] += this->matrix[i][k] * matrix.matrix[k][j]; } if(!flag) matrix.str = this->str; return matrixC; } else std::cout << "Количество столбцов первой матрицы должно быть равно числу строк второй!" << std::endl; return *this; } Then a method that implements the exponentiation itself. In my case, only the construction to a negative degree does not work (this can be solved by converting the matrix to the inverse and associated self-multiplication of it as many times as the degree requires))) My solution is simplified.
Matrix Matrix::involution(int n) { bool flag; if (str == stolb) { Matrix matrixC(str, stolb); if (n == 0) { for (size_t i = 0; i < str; i++) { for (size_t j = 0; j < stolb; j++) matrixC.matrix[i][j] = 0; matrixC.matrix[i][i] = 1; } return matrixC; } else if (n == 1) { matrixC = *this; } else { flag = false; matrixC = mul(*this, flag); for (size_t i = 3; i <= n; i++) matrixC = mul(matrixC, flag); } return matrixC; } else { throw 202; std::cout << "Матрица не квадратная!" << std::endl; } Good luck!)
ntimes. - VladD