Constants

POLYMORPHIC_ARGUMENT_EXCEPTION

POLYMORPHIC_ARGUMENT_EXCEPTION = "Invalid argument pattern for polymorphic function."

ARGUMENT_TYPE_EXCEPTION

ARGUMENT_TYPE_EXCEPTION = "Invalid argument type."

ARGUMENT_BOUNDS_EXCEPTION

ARGUMENT_BOUNDS_EXCEPTION = "Invalid argument range."

MATRIX_DIMENSION_EXCEPTION

MATRIX_DIMENSION_EXCEPTION = "Matrix dimensions are not equal."

ARRAY_LENGTH_EXCEPTION

ARRAY_LENGTH_EXCEPTION = "Array length must be a multiple of m."

Properties

$A

$A : 

Matrix storage

@var array

Type

$m

$m : 

Matrix row dimension

@var int

Type

$n

$n : 

Matrix column dimension

@var int

Type

Methods

__construct()

__construct() 

Polymorphic constructor

As PHP has no support for polymorphic constructors, we hack 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()

getArray() 

getArray

@return array Matrix array

getRowDimension()

getRowDimension() 

getRowDimension

@return int Row dimension

getColumnDimension()

getColumnDimension() 

getColumnDimension

@return int Column dimension

get()

get(integer  $i = null,   $j = null) 

get

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

Parameters

integer $i

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

$j

getMatrix()

getMatrix() 

getMatrix

Get a submatrix

checkMatrixDimensions()

checkMatrixDimensions(\Matrix  $B = null) 

checkMatrixDimensions

Is matrix B the same size?

Parameters

\Matrix $B

Matrix B @return boolean

set()

set(integer  $i = null,   $j = null,   $c = null) 

set

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

Parameters

integer $i

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

$j
$c

identity()

identity(integer  $m = null,   $n = null) 

identity

Generate an identity matrix.

Parameters

integer $m

Row dimension @param int $n Column dimension @return Matrix Identity matrix

$n

diagonal()

diagonal(integer  $m = null,   $n = null,   $c = 1) 

diagonal

Generate a diagonal matrix

Parameters

integer $m

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

$n
$c

getMatrixByRow()

getMatrixByRow(integer  $i0 = null,   $iF = null) 

getMatrixByRow

Get a submatrix by row index/range

Parameters

integer $i0

Initial row index @param int $iF Final row index @return Matrix Submatrix

$iF

getMatrixByCol()

getMatrixByCol(  $j0 = null,   $jF = null) 

getMatrixByCol

Get a submatrix by column index/range

Parameters

$j0
$jF

transpose()

transpose() : \Matrix

transpose

Tranpose matrix

Returns

\Matrix —

Transposed matrix

trace()

trace() : float

trace

Sum of diagonal elements

Returns

float —

Sum of diagonal elements

uminus()

uminus() : \Matrix

uminus

Unary minus matrix -A

Returns

\Matrix —

Unary minus matrix

plus()

plus() 

plus

A + B

plusEquals()

plusEquals() 

plusEquals

A = A + B

minus()

minus() 

minus

A - B

minusEquals()

minusEquals() 

minusEquals

A = A - B

arrayTimes()

arrayTimes() 

arrayTimes

Element-by-element multiplication Cij = Aij * Bij

arrayTimesEquals()

arrayTimesEquals() 

arrayTimesEquals

Element-by-element multiplication Aij = Aij * Bij

arrayRightDivide()

arrayRightDivide() 

arrayRightDivide

Element-by-element right division A / B

arrayRightDivideEquals()

arrayRightDivideEquals() 

arrayRightDivideEquals

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

arrayLeftDivide()

arrayLeftDivide() 

arrayLeftDivide

Element-by-element Left division A / B

arrayLeftDivideEquals()

arrayLeftDivideEquals() 

arrayLeftDivideEquals

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

times()

times() 

times

Matrix multiplication

power()

power() 

power

A = A ^ B

concat()

concat() 

concat

A = A & B

solve()

solve(  $B) : \Matrix

Solve A*X = B.

@param Matrix $B Right hand side

Parameters

$B

Returns

\Matrix —

... Solution if A is square, least squares solution otherwise

inverse()

inverse() 

Matrix inverse or pseudoinverse.

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

det()

det() : float

det

Calculate determinant

Returns

float —

Determinant