@@ 544-580 (lines=37) @@ | ||
541 | * |
|
542 | * @return float |
|
543 | */ |
|
544 | public static function MDETERM($matrixValues) |
|
545 | { |
|
546 | $matrixData = []; |
|
547 | if (!is_array($matrixValues)) { |
|
548 | $matrixValues = [[$matrixValues]]; |
|
549 | } |
|
550 | ||
551 | $row = $maxColumn = 0; |
|
552 | foreach ($matrixValues as $matrixRow) { |
|
553 | if (!is_array($matrixRow)) { |
|
554 | $matrixRow = [$matrixRow]; |
|
555 | } |
|
556 | $column = 0; |
|
557 | foreach ($matrixRow as $matrixCell) { |
|
558 | if ((is_string($matrixCell)) || ($matrixCell === null)) { |
|
559 | return Functions::VALUE(); |
|
560 | } |
|
561 | $matrixData[$column][$row] = $matrixCell; |
|
562 | ++$column; |
|
563 | } |
|
564 | if ($column > $maxColumn) { |
|
565 | $maxColumn = $column; |
|
566 | } |
|
567 | ++$row; |
|
568 | } |
|
569 | if ($row != $maxColumn) { |
|
570 | return Functions::VALUE(); |
|
571 | } |
|
572 | ||
573 | try { |
|
574 | $matrix = new Matrix($matrixData); |
|
575 | ||
576 | return $matrix->det(); |
|
577 | } catch (PhpSpreadsheetException $ex) { |
|
578 | return Functions::VALUE(); |
|
579 | } |
|
580 | } |
|
581 | ||
582 | /** |
|
583 | * MINVERSE. |
|
@@ 596-634 (lines=39) @@ | ||
593 | * |
|
594 | * @return array |
|
595 | */ |
|
596 | public static function MINVERSE($matrixValues) |
|
597 | { |
|
598 | $matrixData = []; |
|
599 | if (!is_array($matrixValues)) { |
|
600 | $matrixValues = [[$matrixValues]]; |
|
601 | } |
|
602 | ||
603 | $row = $maxColumn = 0; |
|
604 | foreach ($matrixValues as $matrixRow) { |
|
605 | if (!is_array($matrixRow)) { |
|
606 | $matrixRow = [$matrixRow]; |
|
607 | } |
|
608 | $column = 0; |
|
609 | foreach ($matrixRow as $matrixCell) { |
|
610 | if ((is_string($matrixCell)) || ($matrixCell === null)) { |
|
611 | return Functions::VALUE(); |
|
612 | } |
|
613 | $matrixData[$column][$row] = $matrixCell; |
|
614 | ++$column; |
|
615 | } |
|
616 | if ($column > $maxColumn) { |
|
617 | $maxColumn = $column; |
|
618 | } |
|
619 | ++$row; |
|
620 | } |
|
621 | foreach ($matrixValues as $matrixRow) { |
|
622 | if (count($matrixRow) != $maxColumn) { |
|
623 | return Functions::VALUE(); |
|
624 | } |
|
625 | } |
|
626 | ||
627 | try { |
|
628 | $matrix = new Matrix($matrixData); |
|
629 | ||
630 | return $matrix->inverse()->getArray(); |
|
631 | } catch (PhpSpreadsheetException $ex) { |
|
632 | return Functions::VALUE(); |
|
633 | } |
|
634 | } |
|
635 | ||
636 | /** |
|
637 | * MMULT. |