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 39 and 311]

(no description)

File Size: 1202 lines (37 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Matrix:: (31 methods):
  __construct()
  getArray()
  getRowDimension()
  getColumnDimension()
  get()
  getMatrix()
  checkMatrixDimensions()
  set()
  identity()
  diagonal()
  getMatrixByRow()
  getMatrixByCol()
  transpose()
  trace()
  uminus()
  plus()
  plusEquals()
  minus()
  minusEquals()
  arrayTimes()
  arrayTimesEquals()
  arrayRightDivide()
  arrayRightDivideEquals()
  arrayLeftDivide()
  arrayLeftDivideEquals()
  times()
  power()
  concat()
  solve()
  inverse()
  det()


Class: Matrix  - X-Ref

Matrix class.

__construct(...$args)   X-Ref
Polymorphic constructor.

As PHP has no support for polymorphic constructors, we use tricks to make our own sort of polymorphism using func_num_args, func_get_arg, and gettype. In essence, we're just implementing a simple RTTI filter and calling the appropriate constructor.

getArray()   X-Ref
getArray.

return: array Matrix array

getRowDimension()   X-Ref
getRowDimension.

return: int Row dimension

getColumnDimension()   X-Ref
getColumnDimension.

return: int Column dimension

get($i = null, $j = null)   X-Ref
get.

Get the i,j-th element of the matrix.

param: int $i Row position
param: int $j Column position
return: mixed Element (int/float/double)

getMatrix(...$args)   X-Ref
getMatrix.

Get a submatrix

return: Matrix Submatrix

checkMatrixDimensions($B = null)   X-Ref
checkMatrixDimensions.

Is matrix B the same size?

param: Matrix $B Matrix B
return: bool

set($i = null, $j = null, $c = null)   X-Ref
set.

Set the i,j-th element of the matrix.

param: int $i Row position
param: int $j Column position
param: mixed $c Int/float/double value
return: mixed Element (int/float/double)

identity($m = null, $n = null)   X-Ref
identity.

Generate an identity matrix.

param: int $m Row dimension
param: int $n Column dimension
return: Matrix Identity matrix

diagonal($m = null, $n = null, $c = 1)   X-Ref
diagonal.

Generate a diagonal matrix

param: int $m Row dimension
param: int $n Column dimension
param: mixed $c Diagonal value
return: Matrix Diagonal matrix

getMatrixByRow($i0 = null, $iF = null)   X-Ref
getMatrixByRow.

Get a submatrix by row index/range

param: int $i0 Initial row index
param: int $iF Final row index
return: Matrix Submatrix

getMatrixByCol($j0 = null, $jF = null)   X-Ref
getMatrixByCol.

Get a submatrix by column index/range

param: int $j0 Initial column index
param: int $jF Final column index
return: Matrix Submatrix

transpose()   X-Ref
transpose.

Tranpose matrix

return: Matrix Transposed matrix

trace()   X-Ref
trace.

Sum of diagonal elements

return: float Sum of diagonal elements

uminus()   X-Ref
uminus.

Unary minus matrix -A

return: Matrix Unary minus matrix

plus(...$args)   X-Ref
plus.

A + B

return: Matrix Sum

plusEquals(...$args)   X-Ref
plusEquals.

A = A + B

return: $this

minus(...$args)   X-Ref
minus.

A - B

return: Matrix Sum

minusEquals(...$args)   X-Ref
minusEquals.

A = A - B

return: $this

arrayTimes(...$args)   X-Ref
arrayTimes.

Element-by-element multiplication
Cij = Aij * Bij

return: Matrix Matrix Cij

arrayTimesEquals(...$args)   X-Ref
arrayTimesEquals.

Element-by-element multiplication
Aij = Aij * Bij

return: $this

arrayRightDivide(...$args)   X-Ref
arrayRightDivide.

Element-by-element right division
A / B

return: Matrix Division result

arrayRightDivideEquals(...$args)   X-Ref
arrayRightDivideEquals.

Element-by-element right division
Aij = Aij / Bij

return: Matrix Matrix Aij

arrayLeftDivide(...$args)   X-Ref
arrayLeftDivide.

Element-by-element Left division
A / B

return: Matrix Division result

arrayLeftDivideEquals(...$args)   X-Ref
arrayLeftDivideEquals.

Element-by-element Left division
Aij = Aij / Bij

return: Matrix Matrix Aij

times(...$args)   X-Ref
times.

Matrix multiplication

return: Matrix Product

power(...$args)   X-Ref
power.

A = A ^ B

return: $this

concat(...$args)   X-Ref
concat.

A = A & B

return: $this

solve($B)   X-Ref
Solve A*X = B.

param: Matrix $B Right hand side
return: Matrix ... Solution if A is square, least squares solution otherwise

inverse()   X-Ref
Matrix inverse or pseudoinverse.

return: Matrix ... Inverse(A) if A is square, pseudoinverse otherwise.

det()   X-Ref
det.

Calculate determinant

return: float Determinant