$matrix
$matrix
Stored internally as a 2-dimension array of values
execute(mixed $value) : $this
Execute the division
mixed | $value | The matrix or numeric value to divide the current base value by |
If the provided argument is not appropriate for the operation
The operation object, allowing multiple divisions to be chained
multiplyMatrix(\Matrix\Matrix $value) : $this
Execute the multiplication for a matrix
\Matrix\Matrix | $value | The numeric value to multiply with the current base value |
If the provided argument is not appropriate for the operation
The operation object, allowing multiple mutiplications to be chained
validateMatchingDimensions(\Matrix\Matrix $matrix) : void
Compare the dimensions of the matrices being operated on to see if they are valid for addition/subtraction
\Matrix\Matrix | $matrix | The second Matrix object on which the operation will be performed |
validateReflectingDimensions(\Matrix\Matrix $matrix) : void
Compare the dimensions of the matrices being operated on to see if they are valid for multiplication/division
\Matrix\Matrix | $matrix | The second Matrix object on which the operation will be performed |
<?php
namespace Matrix\Operators;
use \Matrix\Matrix;
use \Matrix\Functions;
use Matrix\Exception;
class Division extends Multiplication
{
/**
* Execute the division
*
* @param mixed $value The matrix or numeric value to divide the current base value by
* @throws Exception If the provided argument is not appropriate for the operation
* @return $this The operation object, allowing multiple divisions to be chained
**/
public function execute($value): Operator
{
if (is_array($value)) {
$value = new Matrix($value);
}
if (is_object($value) && ($value instanceof Matrix)) {
try {
$value = Functions::inverse($value);
} catch (Exception $e) {
throw new Exception('Division can only be calculated using a matrix with a non-zero determinant');
}
return $this->multiplyMatrix($value);
} elseif (is_numeric($value)) {
return $this->multiplyScalar(1 / $value);
}
throw new Exception('Invalid argument for division');
}
}