c# - 查找大于 3X3 C# 的矩阵的行列式
问题描述
在我的 Matrix 课程中,我能够为最大 3X3 的矩阵编写自己的代码
class Matrix
{
public float Determinant()
{
if (!isSquare())
return 0;
else if (_rows == 1)
return this[0, 0];
else if (_rows == 2)
{
/* |a b|
|c d|*/
float a = this[0, 0];
float b = this[0, 1];
float c = this[1, 0];
float d = this[1, 1];
return (a * d) - (b * c);
}
else
{
float sum = 0;
int i = 0;
for (int j = 0; j < _cols; j++)
{
//finding cofactor
float a = (float)Math.Pow(-1, i + j);
float b = (j % 2 == 0) ? - a * this[i,j] : a * this[i,j];
Matrix m = subMatrix(i, j);
//getting determinant by recursion
float d = m.Determinant();
sum += b * d;
}
return sum;
}
}
}
此代码对大于 3X3 的矩阵停止工作。我读过其他人发布的一些类似的帖子,但这些并没有真正帮助我。我不需要勺子喂食的代码,只需要一些解释或者描述我需要做什么的文章。
解决方案
推荐阅读
- monitoring - 如何从一段时间内获取 Couchbase 节点统计信息的样本
- tampermonkey - 如何获取网页中包含的文本并将其作为页面标题的一部分?
- apache-spark - 在配置单元表中交换分区时出错
- javascript - 使用 SELECT 附近的 sql sintaxis 出错,代码:'ER_PARSE_ERROR',errno:1064
- syntax - 在 OCaml 中,如何区分 * 和 ,?
- python-3.x - 如何解决错误“ValueError:时间数据'2019-07-01 07:00:00'与格式'%y-%m-%d %H:%M:%S'不匹配”
- java - 什么是hashmap入口类中的hashcode和equals
- javascript - 浏览器游戏保护
- r - 如何从R中的XML父节点中解析信息
- android - 由于违反垃圾邮件政策,我的 APP 被暂停