double を含む行列 (ここでは 2 次元配列) の行列式を計算するメソッドを作成しています。ここに私が書いたものがあります:
/// <summary>
/// Checks to see if a matrix is square, and then computes its determinant
/// </summary>
/// <returns></returns>
public double Determinant()
{
// Check to make sure the matrix is square. Only square matrices
// have determinants.
if (!this.isSquare())
{
throw new Exception("The matrix does not have a determinant");
}
// Check to see if the matrix has dimensions 1x1.
// The determinant of a 1x1 matrix is equal to the value stored at (0,0).
if (this.NumberOfRows == 1)
{
return this.GetElement(0, 0);
}
double determinant = 0;
// Loop through the top row of the matrix.
for (int columnIndex = 0; columnIndex < this.NumberOfColumns; columnIndex++)
{
Matrix cofactor = new Matrix(this.NumberOfRows - 1, this.NumberOfColumns - 1);
//fill cofactor
//I dont Know what to do here?
determinant += this.GetElement(1, columnIndex) * cofactor.Determinant();
}
return determinant;
}
私が見逃しているのは、行に何が必要かということですfill cofactor
。
誰かが私がそこで何をすべきかを提案できますか? 基本的に、マトリックス内の現在の位置の行または列に表示される要素を無視しながら、元のマトリックスから補因子に要素を追加する最良の方法は何ですか?