Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400]

   1  <?php
   2  
   3  namespace Matrix\Operators;
   4  
   5  use Matrix\Div0Exception;
   6  use Matrix\Exception;
   7  use \Matrix\Matrix;
   8  use \Matrix\Functions;
   9  
  10  class Division extends Multiplication
  11  {
  12      /**
  13       * Execute the division
  14       *
  15       * @param mixed $value The matrix or numeric value to divide the current base value by
  16       * @throws Exception If the provided argument is not appropriate for the operation
  17       * @return $this The operation object, allowing multiple divisions to be chained
  18       **/
  19      public function execute($value, string $type = 'division'): Operator
  20      {
  21          if (is_array($value)) {
  22              $value = new Matrix($value);
  23          }
  24  
  25          if (is_object($value) && ($value instanceof Matrix)) {
  26              $value = Functions::inverse($value, $type);
  27  
  28              return $this->multiplyMatrix($value, $type);
  29          } elseif (is_numeric($value)) {
  30              return $this->multiplyScalar(1 / $value, $type);
  31          }
  32  
  33          throw new Exception('Invalid argument for division');
  34      }
  35  }