class Matrix (View source)

Matrix class.

Constants

POLYMORPHIC_ARGUMENT_EXCEPTION

ARGUMENT_TYPE_EXCEPTION

ARGUMENT_BOUNDS_EXCEPTION

MATRIX_DIMENSION_EXCEPTION

ARRAY_LENGTH_EXCEPTION

MATRIX_SPD_EXCEPTION

Properties

array $A Matrix storage.

Methods

__construct(...$args)

Polymorphic constructor.

array
getArray()

getArray.

int
getRowDimension()

getRowDimension.

int
getColumnDimension()

getColumnDimension.

mixed
get(int $i = null, int $j = null)

get.

getMatrix(...$args)

getMatrix.

bool
checkMatrixDimensions(Matrix $B = null)

checkMatrixDimensions.

mixed
set(int $i = null, int $j = null, mixed $c = null)

set.

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

identity.

diagonal(int $m = null, int $n = null, mixed $c = 1)

diagonal.

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

getMatrixByRow.

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

getMatrixByCol.

transpose()

transpose.

float
trace()

trace.

uminus()

uminus.

plus(...$args)

plus.

plusEquals(...$args)

plusEquals.

minus(...$args)

minus.

minusEquals(...$args)

minusEquals.

arrayTimes(...$args)

arrayTimes.

arrayTimesEquals(...$args)

arrayTimesEquals.

arrayRightDivide(...$args)

arrayRightDivide.

arrayRightDivideEquals(...$args)

arrayRightDivideEquals.

arrayLeftDivide(...$args)

arrayLeftDivide.

arrayLeftDivideEquals(...$args)

arrayLeftDivideEquals.

times(...$args)

times.

power(...$args)

power.

concat(...$args)

concat.

solve(Matrix $B)

Solve A*X = B.

inverse()

Matrix inverse or pseudoinverse.

float
det()

det.

Details

__construct(...$args)

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.

Parameters

...$args

array getArray()

getArray.

Return Value

array Matrix array

int getRowDimension()

getRowDimension.

Return Value

int Row dimension

int getColumnDimension()

getColumnDimension.

Return Value

int Column dimension

mixed get(int $i = null, int $j = null)

get.

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

Parameters

int $i Row position
int $j Column position

Return Value

mixed Element (int/float/double)

Matrix getMatrix(...$args)

getMatrix.

Get a submatrix

Parameters

...$args

Return Value

Matrix Submatrix

bool checkMatrixDimensions(Matrix $B = null)

checkMatrixDimensions.

Is matrix B the same size?

Parameters

Matrix $B Matrix B

Return Value

bool

mixed set(int $i = null, int $j = null, mixed $c = null)

set.

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

Parameters

int $i Row position
int $j Column position
mixed $c Int/float/double value

Return Value

mixed Element (int/float/double)

Matrix identity(int $m = null, int $n = null)

identity.

Generate an identity matrix.

Parameters

int $m Row dimension
int $n Column dimension

Return Value

Matrix Identity matrix

Matrix diagonal(int $m = null, int $n = null, mixed $c = 1)

diagonal.

Generate a diagonal matrix

Parameters

int $m Row dimension
int $n Column dimension
mixed $c Diagonal value

Return Value

Matrix Diagonal matrix

Matrix getMatrixByRow(int $i0 = null, int $iF = null)

getMatrixByRow.

Get a submatrix by row index/range

Parameters

int $i0 Initial row index
int $iF Final row index

Return Value

Matrix Submatrix

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

getMatrixByCol.

Get a submatrix by column index/range

Parameters

int $j0 Initial column index
int $jF Final column index

Return Value

Matrix Submatrix

Matrix transpose()

transpose.

Tranpose matrix

Return Value

Matrix Transposed matrix

float trace()

trace.

Sum of diagonal elements

Return Value

float Sum of diagonal elements

Matrix uminus()

uminus.

Unary minus matrix -A

Return Value

Matrix Unary minus matrix

Matrix plus(...$args)

plus.

A + B

Parameters

...$args

Return Value

Matrix Sum

Matrix plusEquals(...$args)

plusEquals.

A = A + B

Parameters

...$args

Return Value

Matrix Sum

Matrix minus(...$args)

minus.

A - B

Parameters

...$args

Return Value

Matrix Sum

Matrix minusEquals(...$args)

minusEquals.

A = A - B

Parameters

...$args

Return Value

Matrix Sum

Matrix arrayTimes(...$args)

arrayTimes.

Element-by-element multiplication Cij = Aij * Bij

Parameters

...$args

Return Value

Matrix Matrix Cij

Matrix arrayTimesEquals(...$args)

arrayTimesEquals.

Element-by-element multiplication Aij = Aij * Bij

Parameters

...$args

Return Value

Matrix Matrix Aij

Matrix arrayRightDivide(...$args)

arrayRightDivide.

Element-by-element right division A / B

Parameters

...$args

Return Value

Matrix Division result

Matrix arrayRightDivideEquals(...$args)

arrayRightDivideEquals.

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

Parameters

...$args

Return Value

Matrix Matrix Aij

Matrix arrayLeftDivide(...$args)

arrayLeftDivide.

Element-by-element Left division A / B

Parameters

...$args

Return Value

Matrix Division result

Matrix arrayLeftDivideEquals(...$args)

arrayLeftDivideEquals.

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

Parameters

...$args

Return Value

Matrix Matrix Aij

Matrix times(...$args)

times.

Matrix multiplication

Parameters

...$args

Return Value

Matrix Product

Matrix power(...$args)

power.

A = A ^ B

Parameters

...$args

Return Value

Matrix Sum

Matrix concat(...$args)

concat.

A = A & B

Parameters

...$args

Return Value

Matrix Sum

Matrix solve(Matrix $B)

Solve A*X = B.

Parameters

Matrix $B Right hand side

Return Value

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

Matrix inverse()

Matrix inverse or pseudoinverse.

Return Value

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

float det()

det.

Calculate determinant

Return Value

float Determinant