Constants

PolymorphicArgumentException

PolymorphicArgumentException = "Invalid argument pattern for polymorphic function."

ArgumentTypeException

ArgumentTypeException = "Invalid argument type."

ArgumentBoundsException

ArgumentBoundsException = "Invalid argument range."

MatrixDimensionException

MatrixDimensionException = "Matrix dimensions are not equal."

ArrayLengthException

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

Properties

$A

$A : array

Matrix storage

Type

array

$m

$m : integer

Matrix row dimension

Type

integer

$n

$n : integer

Matrix column dimension

Type

integer

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() : array

getArray

Returns

array —

Matrix array

getRowDimension()

getRowDimension() : integer

getRowDimension

Returns

integer —

Row dimension

getColumnDimension()

getColumnDimension() : integer

getColumnDimension

Returns

integer —

Column dimension

get()

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

get

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

Parameters

integer $i

Row position

integer $j

Column position

Returns

mixed —

Element (int/float/double)

getMatrix()

getMatrix() : \Matrix

getMatrix

Get a submatrix

Returns

\Matrix —

Submatrix

checkMatrixDimensions()

checkMatrixDimensions(\Matrix  $B = null) : boolean

checkMatrixDimensions

Is matrix B the same size?

Parameters

\Matrix $B

Matrix B

Returns

boolean

set()

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

set

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

Parameters

integer $i

Row position

integer $j

Column position

mixed $c

Int/float/double value

Returns

mixed —

Element (int/float/double)

identity()

identity(integer  $m = null, integer  $n = null) : \Matrix

identity

Generate an identity matrix.

Parameters

integer $m

Row dimension

integer $n

Column dimension

Returns

\Matrix —

Identity matrix

diagonal()

diagonal(integer  $m = null, integer  $n = null, mixed  $c = 1) : \Matrix

diagonal

Generate a diagonal matrix

Parameters

integer $m

Row dimension

integer $n

Column dimension

mixed $c

Diagonal value

Returns

\Matrix —

Diagonal matrix

getMatrixByRow()

getMatrixByRow(integer  $i0 = null, integer  $iF = null) : \Matrix

getMatrixByRow

Get a submatrix by row index/range

Parameters

integer $i0

Initial row index

integer $iF

Final row index

Returns

\Matrix —

Submatrix

getMatrixByCol()

getMatrixByCol(  $j0 = null,   $jF = null) : \Matrix

getMatrixByCol

Get a submatrix by column index/range

Parameters

$j0
$jF

Returns

\Matrix —

Submatrix

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() : \Matrix

plus

A + B

Returns

\Matrix —

Sum

plusEquals()

plusEquals() : \Matrix

plusEquals

A = A + B

Returns

\Matrix —

Sum

minus()

minus() : \Matrix

minus

A - B

Returns

\Matrix —

Sum

minusEquals()

minusEquals() : \Matrix

minusEquals

A = A - B

Returns

\Matrix —

Sum

arrayTimes()

arrayTimes() : \Matrix

arrayTimes

Element-by-element multiplication Cij = Aij * Bij

Returns

\Matrix —

Matrix Cij

arrayTimesEquals()

arrayTimesEquals() : \Matrix

arrayTimesEquals

Element-by-element multiplication Aij = Aij * Bij

Returns

\Matrix —

Matrix Aij

arrayRightDivide()

arrayRightDivide() : \Matrix

arrayRightDivide

Element-by-element right division A / B

Returns

\Matrix —

Division result

arrayRightDivideEquals()

arrayRightDivideEquals() : \Matrix

arrayRightDivideEquals

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

Returns

\Matrix —

Matrix Aij

arrayLeftDivide()

arrayLeftDivide() : \Matrix

arrayLeftDivide

Element-by-element Left division A / B

Returns

\Matrix —

Division result

arrayLeftDivideEquals()

arrayLeftDivideEquals() : \Matrix

arrayLeftDivideEquals

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

Returns

\Matrix —

Matrix Aij

times()

times() : \Matrix

times

Matrix multiplication

Returns

\Matrix —

Product

power()

power() : \Matrix

power

A = A ^ B

Returns

\Matrix —

Sum

concat()

concat() : \Matrix

concat

A = A & B

Returns

\Matrix —

Sum

solve()

solve(\Matrix  $B) : \Matrix

Solve A*X = B.

Parameters

\Matrix $B

Right hand side

Returns

\Matrix —

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

inverse()

inverse() : \Matrix

Matrix inverse or pseudoinverse.

Returns

\Matrix —

... Inverse(A) if A is square, pseudoinverse otherwise.

det()

det() : float

det

Calculate determinant

Returns

float —

Determinant