Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250530) (c39b7370636)
Matrix Class Reference

A simple 2D-Matrix class. More...

Public Member Functions

 __construct ($a=1, $b=0, $c=0, $d=1, $e=0, $f=0)
 
 __construct (array $grid)
 
 __call (string $functionName, $arguments)
 Returns the result of the function call or operation.
 
 __get (string $propertyName)
 Access specific properties as read-only (no setters)
 
 columns ()
 Returns a Generator that will yield each column of the matrix in turn as a vector matrix or the value of each cell if the matrix is a row vector.
 
 dropColumns (int $column, int $columnCount=1)
 Return a new matrix as a subset of columns from this matrix, dropping columns starting at column number $column, and $columnCount columns A negative $columnCount value will drop columns until that many columns from the end of the matrix A $columnCount value of 0 will remove all columns of the matrix from $column.
 
 dropRows (int $row, int $rowCount=1)
 Return a new matrix as a subset of rows from this matrix, dropping rows starting at row number $row, and $rowCount rows A negative $rowCount value will drop rows until that many rows from the end of the matrix A $rowCount value of 0 will remove all rows of the matrix from $row.
 
 getColumns (int $column, int $columnCount=1)
 Return a new matrix as a subset of columns from this matrix, starting at column number $column, and $columnCount columns A $columnCount value of 0 will return all columns of the matrix from $column A negative $columnCount value will return columns until that many columns from the end of the matrix.
 
 getRows (int $row, int $rowCount=1)
 Return a new matrix as a subset of rows from this matrix, starting at row number $row, and $rowCount rows A $rowCount value of 0 will return all rows of the matrix from $row A negative $rowCount value will return rows until that many rows from the end of the matrix.
 
 getValue (int $row, int $column)
 Return a value from this matrix, from the "cell" identified by the row and column numbers Note that row and column numbers start from 1, not from 0.
 
 getValues ()
 
 isSquare ()
 Identify if the row and column dimensions of this matrix are equal, i.e.
 
 isVector ()
 Identify if this matrix is a vector i.e.
 
 multiply (self $by)
 
 rows ()
 Returns a Generator that will yield each row of the matrix in turn as a vector matrix or the value of each cell if the matrix is a column vector.
 
 solve (Matrix $B)
 Solve A*X = B.
 
 toArray ()
 Return the matrix as a 2-dimensional array.
 

Static Public Member Functions

static validateColumn (int $column)
 Validate that a column number is a positive integer.
 
static validateRow (int $row)
 Validate that a row number is a positive integer.
 

Protected Member Functions

 buildFromArray (array $grid)
 
 validateColumnInRange (int $column)
 Validate that a column number falls within the set of columns for this matrix.
 
 validateRowInRange (int $row)
 Validate that a row number falls within the set of rows for this matrix.
 

Protected Attributes

float $a
 
float $b
 
float $c
 
 $columns
 
float $d
 
float $e
 
float $f
 
 $grid = []
 
 $rows
 

Static Protected Attributes

static $functions
 
static $getters
 
static $operations
 

Detailed Description

A simple 2D-Matrix class.

Constructor & Destructor Documentation

◆ __construct()

Matrix::__construct ( $a = 1,
$b = 0,
$c = 0,
$d = 1,
$e = 0,
$f = 0 )
Parameters
int | float$a
int | float$b
int | float$c
int | float$d
int | float$e
int | float$f

Member Function Documentation

◆ __call()

Matrix::__call ( string $functionName,
$arguments )

Returns the result of the function call or operation.

Parameters
string$functionName
mixed[]$arguments
Return values
Matrix|float
Exceptions
Exception

◆ __get()

Matrix::__get ( string $propertyName)

Access specific properties as read-only (no setters)

Parameters
string$propertyName
Return values
mixed
Exceptions
Exception

◆ columns()

Matrix::columns ( )

Returns a Generator that will yield each column of the matrix in turn as a vector matrix or the value of each cell if the matrix is a row vector.

Return values
Generator|Matrix[]|mixed[]

◆ dropColumns()

Matrix::dropColumns ( int $column,
int $columnCount = 1 )

Return a new matrix as a subset of columns from this matrix, dropping columns starting at column number $column, and $columnCount columns A negative $columnCount value will drop columns until that many columns from the end of the matrix A $columnCount value of 0 will remove all columns of the matrix from $column.

Note that column numbers start from 1, not from 0

Parameters
int$column
int$columnCount
Return values
static
Exceptions
Exception

◆ dropRows()

Matrix::dropRows ( int $row,
int $rowCount = 1 )

Return a new matrix as a subset of rows from this matrix, dropping rows starting at row number $row, and $rowCount rows A negative $rowCount value will drop rows until that many rows from the end of the matrix A $rowCount value of 0 will remove all rows of the matrix from $row.

Note that row numbers start from 1, not from 0

Parameters
int$row
int$rowCount
Return values
static
Exceptions
Exception

◆ getColumns()

Matrix::getColumns ( int $column,
int $columnCount = 1 )

Return a new matrix as a subset of columns from this matrix, starting at column number $column, and $columnCount columns A $columnCount value of 0 will return all columns of the matrix from $column A negative $columnCount value will return columns until that many columns from the end of the matrix.

Note that column numbers start from 1, not from 0

Parameters
int$column
int$columnCount
Return values
Matrix
Exceptions
Exception

◆ getRows()

Matrix::getRows ( int $row,
int $rowCount = 1 )

Return a new matrix as a subset of rows from this matrix, starting at row number $row, and $rowCount rows A $rowCount value of 0 will return all rows of the matrix from $row A negative $rowCount value will return rows until that many rows from the end of the matrix.

Note that row numbers start from 1, not from 0

Parameters
int$row
int$rowCount
Return values
static
Exceptions
Exception

◆ getValue()

Matrix::getValue ( int $row,
int $column )

Return a value from this matrix, from the "cell" identified by the row and column numbers Note that row and column numbers start from 1, not from 0.

Parameters
int$row
int$column
Return values
mixed
Exceptions
Exception

◆ getValues()

Matrix::getValues ( )
Return values
float[]

◆ isSquare()

Matrix::isSquare ( )

Identify if the row and column dimensions of this matrix are equal, i.e.

if it is a "square" matrix

Return values
bool

◆ isVector()

Matrix::isVector ( )

Identify if this matrix is a vector i.e.

if it comprises only a single row or a single column

Return values
bool

◆ multiply()

Matrix::multiply ( self $by)
Parameters
Matrix$by
Return values
Matrix

◆ rows()

Matrix::rows ( )

Returns a Generator that will yield each row of the matrix in turn as a vector matrix or the value of each cell if the matrix is a column vector.

Return values
Generator|Matrix[]|mixed[]

◆ solve()

Matrix::solve ( Matrix $B)

Solve A*X = B.

Parameters
Matrix$BRight hand side
Exceptions
Exception
Return values
Matrix... Solution if A is square, least squares solution otherwise

◆ toArray()

Matrix::toArray ( )

Return the matrix as a 2-dimensional array.

Return values
array

◆ validateColumn()

static Matrix::validateColumn ( int $column)
static

Validate that a column number is a positive integer.

Parameters
int$column
Return values
int
Exceptions
Exception

◆ validateColumnInRange()

Matrix::validateColumnInRange ( int $column)
protected

Validate that a column number falls within the set of columns for this matrix.

Parameters
int$column
Return values
int
Exceptions
Exception

◆ validateRow()

static Matrix::validateRow ( int $row)
static

Validate that a row number is a positive integer.

Parameters
int$row
Return values
int
Exceptions
Exception

◆ validateRowInRange()

Matrix::validateRowInRange ( int $row)
protected

Validate that a row number falls within the set of rows for this matrix.

Parameters
int$row
Return values
int
Exceptions
Exception

Member Data Documentation

◆ $functions

Matrix::$functions
staticprotected
Initial value:
= [
'adjoint',
'antidiagonal',
'cofactors',
'determinant',
'diagonal',
'identity',
'inverse',
'minors',
'trace',
'transpose',
]

◆ $getters

Matrix::$getters
staticprotected
Initial value:
= [
'rows',
'columns',
]

◆ $operations

Matrix::$operations
staticprotected
Initial value:
= [
'add',
'subtract',
'multiply',
'divideby',
'divideinto',
'directsum',
]

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