@@ 484-520 (lines=37) @@ | ||
481 | * |
|
482 | * @return float |
|
483 | */ |
|
484 | public static function MDETERM($matrixValues) |
|
485 | { |
|
486 | $matrixData = []; |
|
487 | if (!is_array($matrixValues)) { |
|
488 | $matrixValues = [[$matrixValues]]; |
|
489 | } |
|
490 | ||
491 | $row = $maxColumn = 0; |
|
492 | foreach ($matrixValues as $matrixRow) { |
|
493 | if (!is_array($matrixRow)) { |
|
494 | $matrixRow = [$matrixRow]; |
|
495 | } |
|
496 | $column = 0; |
|
497 | foreach ($matrixRow as $matrixCell) { |
|
498 | if ((is_string($matrixCell)) || ($matrixCell === null)) { |
|
499 | return Functions::VALUE(); |
|
500 | } |
|
501 | $matrixData[$column][$row] = $matrixCell; |
|
502 | ++$column; |
|
503 | } |
|
504 | if ($column > $maxColumn) { |
|
505 | $maxColumn = $column; |
|
506 | } |
|
507 | ++$row; |
|
508 | } |
|
509 | if ($row != $maxColumn) { |
|
510 | return Functions::VALUE(); |
|
511 | } |
|
512 | ||
513 | try { |
|
514 | $matrix = new Matrix($matrixData); |
|
515 | ||
516 | return $matrix->det(); |
|
517 | } catch (PhpSpreadsheetException $ex) { |
|
518 | return Functions::VALUE(); |
|
519 | } |
|
520 | } |
|
521 | ||
522 | /** |
|
523 | * MINVERSE. |
|
@@ 536-574 (lines=39) @@ | ||
533 | * |
|
534 | * @return array |
|
535 | */ |
|
536 | public static function MINVERSE($matrixValues) |
|
537 | { |
|
538 | $matrixData = []; |
|
539 | if (!is_array($matrixValues)) { |
|
540 | $matrixValues = [[$matrixValues]]; |
|
541 | } |
|
542 | ||
543 | $row = $maxColumn = 0; |
|
544 | foreach ($matrixValues as $matrixRow) { |
|
545 | if (!is_array($matrixRow)) { |
|
546 | $matrixRow = [$matrixRow]; |
|
547 | } |
|
548 | $column = 0; |
|
549 | foreach ($matrixRow as $matrixCell) { |
|
550 | if ((is_string($matrixCell)) || ($matrixCell === null)) { |
|
551 | return Functions::VALUE(); |
|
552 | } |
|
553 | $matrixData[$column][$row] = $matrixCell; |
|
554 | ++$column; |
|
555 | } |
|
556 | if ($column > $maxColumn) { |
|
557 | $maxColumn = $column; |
|
558 | } |
|
559 | ++$row; |
|
560 | } |
|
561 | foreach ($matrixValues as $matrixRow) { |
|
562 | if (count($matrixRow) != $maxColumn) { |
|
563 | return Functions::VALUE(); |
|
564 | } |
|
565 | } |
|
566 | ||
567 | try { |
|
568 | $matrix = new Matrix($matrixData); |
|
569 | ||
570 | return $matrix->inverse()->getArray(); |
|
571 | } catch (PhpSpreadsheetException $ex) { |
|
572 | return Functions::VALUE(); |
|
573 | } |
|
574 | } |
|
575 | ||
576 | /** |
|
577 | * MMULT. |