Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

   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  }