Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

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