-1
我正在嘗試計算矩陣recursevily的行列式。矩陣在C++中遞歸的行列式
我寫的函數不帶任何參數(因爲它是一個類中的函數,所以矩陣由「this->」命令定義)。 所以最小的情況下,我想這是一個矩陣2x2可以解決。在這種情況下,在矩陣3x3中,它可以通過將第一個元素與行列式2x2(2x2 * 3x3 - 2x3 * 3x2)相乘來解決,但當然它必須進行遞歸處理......您不能只寫那些值。
我此刻的代碼是這一個:
int Matriz::calcularDeterminante()
{
int numero=0;
int signo = 1;
if (n_filas == 1) {
return (this->matriz[0][0]);
}
else if (n_filas == 2) {
return (this->matriz[0][0] * this->matriz[1][1]) - (this->matriz[0][1] * this->matriz[1][0]);
}
else {
for (int i = 0; i < n_filas; i++) {
if (signo == 0) {
numero += -1* matriz[0][i] * calcularDeterminante();
signo++;
}
else if (signo == 1) {
numero += signo * matriz[0][i] * calcularDeterminante();
signo--;
}
}
}
return numero;
}
但遞歸調用是錯誤的。
你的問題是什麼? – UnholySheep
如何做遞歸調用,以便它可以解決行列式問題 –
你試過做什麼?展示您的代碼並解釋問題所在。現在聽起來好像你要求我們爲你寫代碼 – UnholySheep