@@ 519-563 (lines=45) @@ | ||
516 | * |
|
517 | * @return Matrix Sum |
|
518 | */ |
|
519 | public function plusEquals(...$args) |
|
520 | { |
|
521 | if (count($args) > 0) { |
|
522 | $match = implode(',', array_map('gettype', $args)); |
|
523 | ||
524 | switch ($match) { |
|
525 | case 'object': |
|
526 | if ($args[0] instanceof self) { |
|
527 | $M = $args[0]; |
|
528 | } else { |
|
529 | throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); |
|
530 | } |
|
531 | ||
532 | break; |
|
533 | case 'array': |
|
534 | $M = new self($args[0]); |
|
535 | ||
536 | break; |
|
537 | default: |
|
538 | throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); |
|
539 | break; |
|
540 | } |
|
541 | $this->checkMatrixDimensions($M); |
|
542 | for ($i = 0; $i < $this->m; ++$i) { |
|
543 | for ($j = 0; $j < $this->n; ++$j) { |
|
544 | $validValues = true; |
|
545 | $value = $M->get($i, $j); |
|
546 | if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { |
|
547 | $this->A[$i][$j] = trim($this->A[$i][$j], '"'); |
|
548 | $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); |
|
549 | } |
|
550 | if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { |
|
551 | $value = trim($value, '"'); |
|
552 | $validValues &= StringHelper::convertToNumberIfFraction($value); |
|
553 | } |
|
554 | if ($validValues) { |
|
555 | $this->A[$i][$j] += $value; |
|
556 | } else { |
|
557 | $this->A[$i][$j] = Functions::NAN(); |
|
558 | } |
|
559 | } |
|
560 | } |
|
561 | ||
562 | return $this; |
|
563 | } |
|
564 | ||
565 | throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); |
|
566 | } |
|
@@ 621-665 (lines=45) @@ | ||
618 | * |
|
619 | * @return Matrix Sum |
|
620 | */ |
|
621 | public function minusEquals(...$args) |
|
622 | { |
|
623 | if (count($args) > 0) { |
|
624 | $match = implode(',', array_map('gettype', $args)); |
|
625 | ||
626 | switch ($match) { |
|
627 | case 'object': |
|
628 | if ($args[0] instanceof self) { |
|
629 | $M = $args[0]; |
|
630 | } else { |
|
631 | throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); |
|
632 | } |
|
633 | ||
634 | break; |
|
635 | case 'array': |
|
636 | $M = new self($args[0]); |
|
637 | ||
638 | break; |
|
639 | default: |
|
640 | throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); |
|
641 | break; |
|
642 | } |
|
643 | $this->checkMatrixDimensions($M); |
|
644 | for ($i = 0; $i < $this->m; ++$i) { |
|
645 | for ($j = 0; $j < $this->n; ++$j) { |
|
646 | $validValues = true; |
|
647 | $value = $M->get($i, $j); |
|
648 | if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { |
|
649 | $this->A[$i][$j] = trim($this->A[$i][$j], '"'); |
|
650 | $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); |
|
651 | } |
|
652 | if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { |
|
653 | $value = trim($value, '"'); |
|
654 | $validValues &= StringHelper::convertToNumberIfFraction($value); |
|
655 | } |
|
656 | if ($validValues) { |
|
657 | $this->A[$i][$j] -= $value; |
|
658 | } else { |
|
659 | $this->A[$i][$j] = Functions::NAN(); |
|
660 | } |
|
661 | } |
|
662 | } |
|
663 | ||
664 | return $this; |
|
665 | } |
|
666 | ||
667 | throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); |
|
668 | } |
|
@@ 725-769 (lines=45) @@ | ||
722 | * |
|
723 | * @return Matrix Matrix Aij |
|
724 | */ |
|
725 | public function arrayTimesEquals(...$args) |
|
726 | { |
|
727 | if (count($args) > 0) { |
|
728 | $match = implode(',', array_map('gettype', $args)); |
|
729 | ||
730 | switch ($match) { |
|
731 | case 'object': |
|
732 | if ($args[0] instanceof self) { |
|
733 | $M = $args[0]; |
|
734 | } else { |
|
735 | throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); |
|
736 | } |
|
737 | ||
738 | break; |
|
739 | case 'array': |
|
740 | $M = new self($args[0]); |
|
741 | ||
742 | break; |
|
743 | default: |
|
744 | throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); |
|
745 | break; |
|
746 | } |
|
747 | $this->checkMatrixDimensions($M); |
|
748 | for ($i = 0; $i < $this->m; ++$i) { |
|
749 | for ($j = 0; $j < $this->n; ++$j) { |
|
750 | $validValues = true; |
|
751 | $value = $M->get($i, $j); |
|
752 | if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { |
|
753 | $this->A[$i][$j] = trim($this->A[$i][$j], '"'); |
|
754 | $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); |
|
755 | } |
|
756 | if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { |
|
757 | $value = trim($value, '"'); |
|
758 | $validValues &= StringHelper::convertToNumberIfFraction($value); |
|
759 | } |
|
760 | if ($validValues) { |
|
761 | $this->A[$i][$j] *= $value; |
|
762 | } else { |
|
763 | $this->A[$i][$j] = Functions::NAN(); |
|
764 | } |
|
765 | } |
|
766 | } |
|
767 | ||
768 | return $this; |
|
769 | } |
|
770 | ||
771 | throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); |
|
772 | } |