本文整理匯總了PHP中Matrix::determinant方法的典型用法代碼示例。如果您正苦於以下問題:PHP Matrix::determinant方法的具體用法?PHP Matrix::determinant怎麽用?PHP Matrix::determinant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Matrix
的用法示例。
在下文中一共展示了Matrix::determinant方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: determinant
public function determinant()
{
if ($this->u_size !== $this->u_stride) {
return null;
}
switch ($this->u_size) {
case 0:
return 0.0;
case 1:
return $this->u_data[0];
case 2:
return $this->u_data[0] * $this->u_data[3] - $this->u_data[1] * $this->u_data[2];
default:
$result = 0.0;
$minor = new Matrix($this->u_size - 1, $this->u_stride - 1);
for ($n = 0; $n < $this->u_size; $n++) {
$a = ($n + 1) % 2 == 0 ? -1 : 1;
for ($i = 1; $i < $this->u_size; $i++) {
$offset = $i * $this->u_stride;
$minorOffset = ($i - 1) * $this->u_stride;
for ($j = 0; $j < $n; $j++) {
$minor->u_data[$minorOffset + $j] = $this->u_data[$offset + $j];
}
for ($j = $n + 1; $j < $this->u_stride; $j++) {
$minor->u_data[$minorOffset + $j - 1] = $this->u_data[$offset + $j];
}
}
$result += $this->u_data[$n] * $minor->determinant();
}
return $result;
}
}
示例2: testDeterminantException
public function testDeterminantException()
{
$matrix = new Matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]);
try {
$matrix->determinant();
} catch (MatrixException $exception) {
return;
}
$this->fail('MatrixException not raised.');
}
示例3: testDeterminantException
/**
* @expectedException \RangeException
*/
public function testDeterminantException()
{
$arr1 = [[1, 2], [3, 4], [5, 6]];
$mat1 = new Matrix($arr1);
$mat1->determinant();
}