ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Matrix\Operators\Subtraction Class Reference
+ Inheritance diagram for Matrix\Operators\Subtraction:
+ Collaboration diagram for Matrix\Operators\Subtraction:

Public Member Functions

 execute ($value)
 Execute the subtraction. More...
 
- Public Member Functions inherited from Matrix\Operators\Operator
 __construct (Matrix $matrix)
 Create an new handler object for the operation. More...
 
 result ()
 Return the result of the operation. More...
 

Protected Member Functions

 subtractScalar ($value)
 Execute the subtraction for a scalar. More...
 
 subtractMatrix (Matrix $value)
 Execute the subtraction for a matrix. More...
 
- Protected Member Functions inherited from Matrix\Operators\Operator
 validateMatchingDimensions (Matrix $matrix)
 Compare the dimensions of the matrices being operated on to see if they are valid for addition/subtraction. More...
 
 validateReflectingDimensions (Matrix $matrix)
 Compare the dimensions of the matrices being operated on to see if they are valid for multiplication/division. More...
 

Additional Inherited Members

- Protected Attributes inherited from Matrix\Operators\Operator
 $matrix
 
 $rows
 Number of rows in the matrix. More...
 
 $columns
 Number of columns in the matrix. More...
 

Detailed Description

Definition at line 8 of file Subtraction.php.

Member Function Documentation

◆ execute()

Matrix\Operators\Subtraction::execute (   $value)

Execute the subtraction.

Parameters
mixed$valueThe matrix or numeric value to subtract from the current base value
Exceptions
ExceptionIf the provided argument is not appropriate for the operation
Returns
$this The operation object, allowing multiple subtractions to be chained

Definition at line 17 of file Subtraction.php.

17 : Operator
18 {
19 if (is_array($value)) {
20 $value = new Matrix($value);
21 }
22
23 if (is_object($value) && ($value instanceof Matrix)) {
24 return $this->subtractMatrix($value);
25 } elseif (is_numeric($value)) {
26 return $this->subtractScalar($value);
27 }
28
29 throw new Exception('Invalid argument for subtraction');
30 }
subtractMatrix(Matrix $value)
Execute the subtraction for a matrix.
Definition: Subtraction.php:56
subtractScalar($value)
Execute the subtraction for a scalar.
Definition: Subtraction.php:38
Class for the creating "special" Matrices.
Definition: Builder.php:11

References Matrix\Operators\Subtraction\subtractMatrix(), and Matrix\Operators\Subtraction\subtractScalar().

+ Here is the call graph for this function:

◆ subtractMatrix()

Matrix\Operators\Subtraction::subtractMatrix ( Matrix  $value)
protected

Execute the subtraction for a matrix.

Parameters
Matrix$valueThe numeric value to subtract from the current base value
Returns
$this The operation object, allowing multiple subtractions to be chained
Exceptions
ExceptionIf the provided argument is not appropriate for the operation

Definition at line 56 of file Subtraction.php.

56 : Operator
57 {
58 $this->validateMatchingDimensions($value);
59
60 for ($row = 0; $row < $this->rows; ++$row) {
61 for ($column = 0; $column < $this->columns; ++$column) {
62 $this->matrix[$row][$column] -= $value->getValue($row + 1, $column + 1);
63 }
64 }
65
66 return $this;
67 }
getValue(int $row, int $column)
Return a value from this matrix, from the "cell" identified by the row and column numbers Note that r...
Definition: Matrix.php:268
validateMatchingDimensions(Matrix $matrix)
Compare the dimensions of the matrices being operated on to see if they are valid for addition/subtra...
Definition: Operator.php:49
$rows
Number of rows in the matrix.
Definition: Operator.php:22
$columns
Number of columns in the matrix.
Definition: Operator.php:29
$row

References Matrix\Operators\Operator\$columns, $row, Matrix\Operators\Operator\$rows, Matrix\Matrix\getValue(), and Matrix\Operators\Operator\validateMatchingDimensions().

Referenced by Matrix\Operators\Subtraction\execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subtractScalar()

Matrix\Operators\Subtraction::subtractScalar (   $value)
protected

Execute the subtraction for a scalar.

Parameters
mixed$valueThe numeric value to subtracted from the current base value
Returns
$this The operation object, allowing multiple additions to be chained

Definition at line 38 of file Subtraction.php.

38 : Operator
39 {
40 for ($row = 0; $row < $this->rows; ++$row) {
41 for ($column = 0; $column < $this->columns; ++$column) {
42 $this->matrix[$row][$column] -= $value;
43 }
44 }
45
46 return $this;
47 }

References Matrix\Operators\Operator\$columns, $row, and Matrix\Operators\Operator\$rows.

Referenced by Matrix\Operators\Subtraction\execute().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: