-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeterminant.php
48 lines (40 loc) · 1.08 KB
/
determinant.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
include '../_include/matrix.function.php';
/**
* Determinant pro jeden prvek v poli
*/
function determinantElement($matrix, $coord_x, $coord_y)
{
if ( ($coord_x + $coord_y) % 2 == 0) {
$result = 1;
} else {
$result = -1;
}
$result *= $matrix[$coord_y][$coord_x];
foreach ($matrix as $matrix_coord_y => $row) {
$submatrix_row = Array();
unset($submatrix_row);
foreach ($row as $matrix_coord_x => $value) {
if (($matrix_coord_y != $coord_y) AND ($matrix_coord_x != $coord_x)) {
$submatrix_row[] = $value*1;
}
}
if ($submatrix_row != NULL) {
$submatrix[] = $submatrix_row;
}
}
if (isset($submatrix[1][1])) {
$result *= determinantElement($submatrix, 1, 1);
}
return $result;
}
function determinant($matrix, $coord_y)
{
foreach ($matrix[$coord_y] as $coord_x => $value) {
$result += determinantElement($matrix, $coord_x, $coord_y);
echo determinantElement($matrix, $coord_x, $coord_y).";";
}
return $result;
}
echo determinant(parseCSV("./matice2.csv"),0);
?>