【发布时间】:2019-08-21 14:42:55
【问题描述】:
我正在用 PHP 开发一个行列式计算器
在 Matrix 类中,我创建了一些函数,其中包括函数 calc (order, matrix)。 该函数调用另一个函数将数组的顺序降低到$ order = 3,然后执行sarrus($matriz)函数。
注意:这个矩阵变量会随着顺序的降低而改变,即原来的矩阵会保存在另一个变量中!
好吧,我想知道将数组顺序降低到 3 的最佳方法,如果可能的话,我尝试使用 laplace 代码示例,但我在决定放弃一段时间的循环中感到很困惑。
public function calc ($order, $matriz)
{
// If the order equals 1: the element is the determinant
if ($order == 1) {
$ this->det = $matriz[0][0];
}
// If the order equals 2: call the @segOrder function
else if ($order == 2) {
segOrder($matriz);
}
// If the order is 3: call the function @sarrus
else if ($order == 3) {
sarrus($matriz);
}
// If the order is greater than 3: call the function @leaveOrder to lower the array order to 3 and then use @sarrus to have the determinant
else if ($order > 3) {
$matriz = lowerOrder($matriz, $order);
sarrus($matriz);
}
return $this->det;
}
数组布局:
$matriz = array (
array (1,2,3),
array (4,5,6),
array (7,8,9)
);
【问题讨论】:
标签: php performance matrix determinants