我正在编写一个方法,用于计算包含双精度浮点数的矩阵(这里是二维数组)的行列式。以下是我的代码:
/// <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
这一行应该填什么。有人能否建议我在那里做些什么?基本上,从原矩阵中添加元素到余子式的最佳方法是什么,同时忽略出现在当前位置所在行或列中的元素?
Matrix.Determinant
不能满足你的需求,有什么原因吗?(http://msdn.microsoft.com/en-us/library/system.windows.media.matrix.determinant(v=vs.110).aspx) - GjeltemaMatrix.Determinant
需要应用程序始终能够访问 Silverlight 命名空间,截至 .NET 4.5 版本。若要查看不可移植代码的示例,请将 DLL 加载到 Xamarin Scan 中。 - jth41