Class CommonOps
- java.lang.Object
-
- org.ejml.ops.CommonOps
-
public class CommonOps extends java.lang.ObjectCommon matrix operations are contained here. Which specific underlying algorithm is used is not specified just the out come of the operation. Nor should calls to these functions reply on the underlying implementation. Which algorithm is used can depend on the matrix being passed in.
For more exotic and specialized generic operations see
SpecializedOps.- See Also:
MatrixMatrixMult,MatrixVectorMult,SpecializedOps,MatrixFeatures
-
-
Constructor Summary
Constructors Constructor and Description CommonOps()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static voidadd(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)Performs the following operation:
c = a + b
cij = aij + bijstatic voidadd(D1Matrix64F a, double val)Performs an in-place scalar addition:
a = a + val
aij = aij + valstatic voidadd(D1Matrix64F a, double val, D1Matrix64F c)Performs scalar addition:
c = a + val
cij = aij + valstatic voidadd(D1Matrix64F a, double beta, D1Matrix64F b, D1Matrix64F c)Performs the following operation:
c = a + β * b
cij = aij + β * bijstatic voidadd(double alpha, D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)Performs the following operation:
c = α * a + b
cij = α * aij + bijstatic voidadd(double alpha, D1Matrix64F a, double beta, D1Matrix64F b, D1Matrix64F c)Performs the following operation:
c = α * a + β * b
cij = α * aij + β * bijstatic voidaddEquals(D1Matrix64F a, D1Matrix64F b)Performs the following operation:
a = a + b
aij = aij + bijstatic voidaddEquals(D1Matrix64F a, double beta, D1Matrix64F b)Performs the following operation:
a = a + β * b
aij = aij + β * bijstatic voidchangeSign(D1Matrix64F a)Changes the sign of every element in the matrix.
aij = -aijstatic voidchangeSign(D1Matrix64F input, D1Matrix64F output)Changes the sign of every element in the matrix.
outputij = -inputijstatic DenseMatrix64F[]columnsToVector(DenseMatrix64F A, DenseMatrix64F[] v)Converts the columns in a matrix into a set of vectors.static doubledet(DenseMatrix64F mat)Returns the determinant of the matrix.static DenseMatrix64Fdiag(DenseMatrix64F ret, int width, double... diagEl)static DenseMatrix64Fdiag(double... diagEl)Creates a new square matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = jstatic DenseMatrix64FdiagR(int numRows, int numCols, double... diagEl)Creates a new rectangular matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = jstatic voiddivide(D1Matrix64F a, double alpha)Performs an in-place element by element scalar division with the scalar on bottom.
aij = aij/αstatic voiddivide(D1Matrix64F a, double alpha, D1Matrix64F b)Performs an element by element scalar division with the scalar on botton.
bij = aij /αstatic voiddivide(double alpha, D1Matrix64F a)Performs an in-place element by element scalar division with the scalar on top.
aij = &alpha/aij;static voiddivide(double alpha, D1Matrix64F a, D1Matrix64F b)Performs an element by element scalar division with the scalar on top.
bij = &alpha/aij;static doubledot(D1Matrix64F a, D1Matrix64F b)static voidelementDiv(D1Matrix64F a, D1Matrix64F b)Performs the an element by element division operation:
aij = aij / bijstatic voidelementDiv(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)Performs the an element by element division operation:
cij = aij / bijstatic voidelementExp(D1Matrix64F A, D1Matrix64F C)Element-wise exp operation
cij = Math.log(aij)static voidelementLog(D1Matrix64F A, D1Matrix64F C)Element-wise log operation
cij = Math.log(aij)static doubleelementMax(D1Matrix64F a)Returns the value of the element in the matrix that has the largest value.
Max{ aij } for all i and jstatic doubleelementMaxAbs(D1Matrix64F a)Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and jstatic doubleelementMin(D1Matrix64F a)Returns the value of the element in the matrix that has the minimum value.
Min{ aij } for all i and jstatic doubleelementMinAbs(D1Matrix64F a)Returns the absolute value of the element in the matrix that has the smallest absolute value.
Min{ |aij| } for all i and jstatic voidelementMult(D1Matrix64F a, D1Matrix64F b)Performs the an element by element multiplication operation:
aij = aij * bijstatic voidelementMult(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)Performs the an element by element multiplication operation:
cij = aij * bijstatic voidelementPower(D1Matrix64F A, D1Matrix64F B, D1Matrix64F C)Element-wise power operation
cij = aij ^ bijstatic voidelementPower(D1Matrix64F A, double b, D1Matrix64F C)Element-wise power operation
cij = aij ^ bstatic voidelementPower(double a, D1Matrix64F B, D1Matrix64F C)Element-wise power operation
cij = a ^ bijstatic doubleelementSum(D1Matrix64F mat)Computes the sum of all the elements in the matrix:
sum(i=1:m , j=1:n ; aij)static doubleelementSumAbs(D1Matrix64F mat)Computes the sum of the absolute value all the elements in the matrix:
sum(i=1:m , j=1:n ; |aij|)static DenseMatrix64Fextract(DenseMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1)Creates a new matrix which is the specified submatrix of 'src'static voidextract(RealMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1, RealMatrix64F dst, int dstY0, int dstX0)Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'.static DenseMatrix64FextractColumn(DenseMatrix64F a, int column, DenseMatrix64F out)Extracts the column from a matrix.static voidextractDiag(DenseMatrix64F src, DenseMatrix64F dst)Extracts the diagonal elements 'src' write it to the 'dst' vector.static DenseMatrix64FextractRow(DenseMatrix64F a, int row, DenseMatrix64F out)Extracts the row from a matrix.static voidfill(D1Matrix64F a, double value)Sets every element in the matrix to the specified value.
aij = valuestatic DenseMatrix64Fidentity(int width)Creates an identity matrix of the specified size.
aij = 0 if i ≠ j
aij = 1 if i = jstatic DenseMatrix64Fidentity(int numRows, int numCols)Creates a rectangular matrix which is zero except along the diagonals.static voidinsert(RealMatrix64F src, RealMatrix64F dest, int destY0, int destX0)Inserts matrix 'src' into matrix 'dest' with the (0,0) of src at (row,col) in dest.static booleaninvert(DenseMatrix64F mat)Performs a matrix inversion operation on the specified matrix and stores the results in the same matrix.
a = a-1static booleaninvert(DenseMatrix64F mat, DenseMatrix64F result)Performs a matrix inversion operation that does not modify the original and stores the results in another matrix.static voidkron(DenseMatrix64F A, DenseMatrix64F B, DenseMatrix64F C)The Kronecker product of two matrices is defined as:
Cij = aijB
where Cij is a sub matrix inside of C ∈ ℜ m*k × n*l, A ∈ ℜ m × n, and B ∈ ℜ k × l.static voidmult(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * a * b
cij = α ∑k=1:n { * aik * bkj}static voidmult(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = a * b
cij = ∑k=1:n { aik * bkj}static voidmultAdd(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * a * b
cij = cij + α * ∑k=1:n { aik * bkj}static voidmultAdd(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + a * b
cij = cij + ∑k=1:n { aik * bkj}static voidmultAddTransA(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * aT * b
cij =cij + α * ∑k=1:n { aki * bkj}static voidmultAddTransA(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + aT * b
cij = cij + ∑k=1:n { aki * bkj}static voidmultAddTransAB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * aT * bT
cij = cij + α * ∑k=1:n { aki * bjk}static voidmultAddTransAB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + aT * bT
cij = cij + ∑k=1:n { aki * bjk}static voidmultAddTransB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * a * bT
cij = cij + α * ∑k=1:n { aik * bjk}static voidmultAddTransB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + a * bT
cij = cij + ∑k=1:n { aik * bjk}static voidmultInner(RowD1Matrix64F a, RowD1Matrix64F c)Computes the matrix multiplication inner product:
c = aT * a
cij = ∑k=1:n { aki * akj}static voidmultOuter(RowD1Matrix64F a, RowD1Matrix64F c)Computes the matrix multiplication outer product:
c = a * aT
cij = ∑k=1:m { aik * ajk}static voidmultTransA(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * aT * b
cij = α ∑k=1:n { aki * bkj}static voidmultTransA(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = aT * b
cij = ∑k=1:n { aki * bkj}static voidmultTransAB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * aT * bT
cij = α ∑k=1:n { aki * bjk}static voidmultTransAB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = aT * bT
cij = ∑k=1:n { aki * bjk}static voidmultTransB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * a * bT
cij = α ∑k=1:n { aik * bjk}static voidmultTransB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = a * bT
cij = ∑k=1:n { aik * bjk}static voidpinv(DenseMatrix64F A, DenseMatrix64F invA)Computes the Moore-Penrose pseudo-inverse:
pinv(A) = (ATA)-1 AT
or
pinv(A) = AT(AAT)-1static DenseMatrix64F[]rowsToVector(DenseMatrix64F A, DenseMatrix64F[] v)Converts the rows in a matrix into a set of vectors.static DenseMatrix64Frref(DenseMatrix64F A, int numUnknowns, DenseMatrix64F reduced)Puts the augmented system matrix into reduced row echelon form (RREF) using Gauss-Jordan elimination with row (partial) pivots.static voidscale(double alpha, D1Matrix64F a)Performs an in-place element by element scalar multiplication.
aij = α*aijstatic voidscale(double alpha, D1Matrix64F a, D1Matrix64F b)Performs an element by element scalar multiplication.
bij = α*aijstatic voidsetIdentity(RowD1Matrix64F mat)Sets all the diagonal elements equal to one and everything else equal to zero.static booleansolve(DenseMatrix64F a, DenseMatrix64F b, DenseMatrix64F x)Solves for x in the following equation:
A*x = bstatic voidsubtract(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)Performs the following subtraction operation:
c = a - b
cij = aij - bijstatic voidsubtract(D1Matrix64F a, double val, D1Matrix64F c)Performs matrix scalar subtraction:
c = a - val
cij = aij - valstatic voidsubtract(double val, D1Matrix64F a, D1Matrix64F c)Performs matrix scalar subtraction:
c = val - a
cij = val - aijstatic voidsubtractEquals(D1Matrix64F a, D1Matrix64F b)Performs the following subtraction operation:
a = a - b
aij = aij - bijstatic DenseMatrix64FsumCols(DenseMatrix64F input, DenseMatrix64F output)Computes the sum of each column in the input matrix and returns the results in a vector:
bj = sum(i=1:m ; |aij|)static DenseMatrix64FsumRows(DenseMatrix64F input, DenseMatrix64F output)Computes the sum of each row in the input matrix and returns the results in a vector:
bj = sum(i=1:n ; |aji|)static doubletrace(RowD1Matrix64F a)This computes the trace of the matrix:
trace = ∑i=1:n { aii }
where n = min(numRows,numCols)static voidtranspose(DenseMatrix64F mat)Performs an "in-place" transpose.static DenseMatrix64Ftranspose(DenseMatrix64F A, DenseMatrix64F A_tran)Transposes matrix 'a' and stores the results in 'b':
bij = aji
where 'b' is the transpose of 'a'.
-
-
-
Method Detail
-
mult
public static void mult(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = a * b
cij = ∑k=1:n { aik * bkj}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
mult
public static void mult(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * a * b
cij = α ∑k=1:n { * aik * bkj}- Parameters:
alpha- Scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multTransA
public static void multTransA(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = aT * b
cij = ∑k=1:n { aki * bkj}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multTransA
public static void multTransA(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * aT * b
cij = α ∑k=1:n { aki * bkj}- Parameters:
alpha- Scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multTransB
public static void multTransB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = a * bT
cij = ∑k=1:n { aik * bjk}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multTransB
public static void multTransB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * a * bT
cij = α ∑k=1:n { aik * bjk}- Parameters:
alpha- Scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multTransAB
public static void multTransAB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = aT * bT
cij = ∑k=1:n { aki * bjk}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multTransAB
public static void multTransAB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = α * aT * bT
cij = α ∑k=1:n { aki * bjk}- Parameters:
alpha- Scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
dot
public static double dot(D1Matrix64F a, D1Matrix64F b)
Computes the dot product or inner product between two vectors. If the two vectors are columns vectors then it is defined as:
dot(a,b) = a<sup>T</sup> * b
If the vectors are column or row or both is ignored by this function.- Parameters:
a- Vectorb- Vector- Returns:
- Dot product of the two vectors
-
multInner
public static void multInner(RowD1Matrix64F a, RowD1Matrix64F c)
Computes the matrix multiplication inner product:
c = aT * a
cij = ∑k=1:n { aki * akj}Is faster than using a generic matrix multiplication by taking advantage of symmetry. For vectors there is an even faster option, see
VectorVectorMult.innerProd(org.ejml.data.D1Matrix64F, org.ejml.data.D1Matrix64F)- Parameters:
a- The matrix being multiplied. Not modified.c- Where the results of the operation are stored. Modified.
-
multOuter
public static void multOuter(RowD1Matrix64F a, RowD1Matrix64F c)
Computes the matrix multiplication outer product:
c = a * aT
cij = ∑k=1:m { aik * ajk}Is faster than using a generic matrix multiplication by taking advantage of symmetry.
- Parameters:
a- The matrix being multiplied. Not modified.c- Where the results of the operation are stored. Modified.
-
multAdd
public static void multAdd(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = c + a * b
cij = cij + ∑k=1:n { aik * bkj}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAdd
public static void multAdd(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * a * b
cij = cij + α * ∑k=1:n { aik * bkj}- Parameters:
alpha- scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAddTransA
public static void multAddTransA(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = c + aT * b
cij = cij + ∑k=1:n { aki * bkj}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAddTransA
public static void multAddTransA(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * aT * b
cij =cij + α * ∑k=1:n { aki * bkj}- Parameters:
alpha- scaling factora- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAddTransB
public static void multAddTransB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = c + a * bT
cij = cij + ∑k=1:n { aik * bjk}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAddTransB
public static void multAddTransB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * a * bT
cij = cij + α * ∑k=1:n { aik * bjk}- Parameters:
alpha- Scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAddTransAB
public static void multAddTransAB(RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)
Performs the following operation:
c = c + aT * bT
cij = cij + ∑k=1:n { aki * bjk}- Parameters:
a- The left matrix in the multiplication operation. Not Modified.b- The right matrix in the multiplication operation. Not Modified.c- Where the results of the operation are stored. Modified.
-
multAddTransAB
public static void multAddTransAB(double alpha, RowD1Matrix64F a, RowD1Matrix64F b, RowD1Matrix64F c)Performs the following operation:
c = c + α * aT * bT
cij = cij + α * ∑k=1:n { aki * bjk}- Parameters:
alpha- Scaling factor.a- The left matrix in the multiplication operation. Not Modified.b- The right matrix in the multiplication operation. Not Modified.c- Where the results of the operation are stored. Modified.
-
solve
public static boolean solve(DenseMatrix64F a, DenseMatrix64F b, DenseMatrix64F x)
Solves for x in the following equation:
A*x = bIf the system could not be solved then false is returned. If it returns true that just means the algorithm finished operating, but the results could still be bad because 'A' is singular or nearly singular.
If repeat calls to solve are being made then one should consider using
LinearSolverFactoryinstead.It is ok for 'b' and 'x' to be the same matrix.
- Parameters:
a- A matrix that is m by n. Not modified.b- A matrix that is n by k. Not modified.x- A matrix that is m by k. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
transpose
public static void transpose(DenseMatrix64F mat)
Performs an "in-place" transpose.
For square matrices the transpose is truly in-place and does not require additional memory. For non-square matrices, internally a temporary matrix is declared and
transpose(org.ejml.data.DenseMatrix64F, org.ejml.data.DenseMatrix64F)is invoked.- Parameters:
mat- The matrix that is to be transposed. Modified.
-
transpose
public static DenseMatrix64F transpose(DenseMatrix64F A, DenseMatrix64F A_tran)
Transposes matrix 'a' and stores the results in 'b':
bij = aji
where 'b' is the transpose of 'a'.- Parameters:
A- The original matrix. Not modified.A_tran- Where the transpose is stored. If null a new matrix is created. Modified.- Returns:
- The transposed matrix.
-
trace
public static double trace(RowD1Matrix64F a)
This computes the trace of the matrix:
trace = ∑i=1:n { aii }
where n = min(numRows,numCols)- Parameters:
a- A square matrix. Not modified.
-
det
public static double det(DenseMatrix64F mat)
Returns the determinant of the matrix. If the inverse of the matrix is also needed, then usingLUDecompositionAlt_D64directly (or any similar algorithm) can be more efficient.- Parameters:
mat- The matrix whose determinant is to be computed. Not modified.- Returns:
- The determinant.
-
invert
public static boolean invert(DenseMatrix64F mat)
Performs a matrix inversion operation on the specified matrix and stores the results in the same matrix.
a = a-1If the algorithm could not invert the matrix then false is returned. If it returns true that just means the algorithm finished. The results could still be bad because the matrix is singular or nearly singular.
- Parameters:
mat- The matrix that is to be inverted. Results are stored here. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
invert
public static boolean invert(DenseMatrix64F mat, DenseMatrix64F result)
Performs a matrix inversion operation that does not modify the original and stores the results in another matrix. The two matrices must have the same dimension.
b = a-1If the algorithm could not invert the matrix then false is returned. If it returns true that just means the algorithm finished. The results could still be bad because the matrix is singular or nearly singular.
For medium to large matrices there might be a slight performance boost to using
LinearSolverFactoryinstead.- Parameters:
mat- The matrix that is to be inverted. Not modified.result- Where the inverse matrix is stored. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
pinv
public static void pinv(DenseMatrix64F A, DenseMatrix64F invA)
Computes the Moore-Penrose pseudo-inverse:
pinv(A) = (ATA)-1 AT
or
pinv(A) = AT(AAT)-1
Internally it uses
SolvePseudoInverseSvdto compute the inverse. For performance reasons, this should only be used when a matrix is singular or nearly singular.- Parameters:
A- A m by n Matrix. Not modified.invA- Where the computed pseudo inverse is stored. n by m. Modified.
-
columnsToVector
public static DenseMatrix64F[] columnsToVector(DenseMatrix64F A, DenseMatrix64F[] v)
Converts the columns in a matrix into a set of vectors.- Parameters:
A- Matrix. Not modified.v-- Returns:
- An array of vectors.
-
rowsToVector
public static DenseMatrix64F[] rowsToVector(DenseMatrix64F A, DenseMatrix64F[] v)
Converts the rows in a matrix into a set of vectors.- Parameters:
A- Matrix. Not modified.v-- Returns:
- An array of vectors.
-
setIdentity
public static void setIdentity(RowD1Matrix64F mat)
Sets all the diagonal elements equal to one and everything else equal to zero. If this is a square matrix then it will be an identity matrix.- Parameters:
mat- A square matrix.- See Also:
identity(int)
-
identity
public static DenseMatrix64F identity(int width)
Creates an identity matrix of the specified size.
aij = 0 if i ≠ j
aij = 1 if i = j
- Parameters:
width- The width and height of the identity matrix.- Returns:
- A new instance of an identity matrix.
-
identity
public static DenseMatrix64F identity(int numRows, int numCols)
Creates a rectangular matrix which is zero except along the diagonals.- Parameters:
numRows- Number of rows in the matrix.numCols- NUmber of columns in the matrix.- Returns:
- A matrix with diagonal elements equal to one.
-
diag
public static DenseMatrix64F diag(double... diagEl)
Creates a new square matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = j
- Parameters:
diagEl- Contains the values of the diagonal elements of the resulting matrix.- Returns:
- A new matrix.
- See Also:
diagR(int, int, double...)
-
diag
public static DenseMatrix64F diag(DenseMatrix64F ret, int width, double... diagEl)
- See Also:
diag(double...)
-
diagR
public static DenseMatrix64F diagR(int numRows, int numCols, double... diagEl)
Creates a new rectangular matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = j
- Parameters:
numRows- Number of rows in the matrix.numCols- Number of columns in the matrix.diagEl- Contains the values of the diagonal elements of the resulting matrix.- Returns:
- A new matrix.
- See Also:
diag(double...)
-
kron
public static void kron(DenseMatrix64F A, DenseMatrix64F B, DenseMatrix64F C)
The Kronecker product of two matrices is defined as:
Cij = aijB
where Cij is a sub matrix inside of C ∈ ℜ m*k × n*l, A ∈ ℜ m × n, and B ∈ ℜ k × l.- Parameters:
A- The left matrix in the operation. Not modified.B- The right matrix in the operation. Not modified.C- Where the results of the operation are stored. Modified.
-
extract
public static void extract(RealMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1, RealMatrix64F dst, int dstY0, int dstX0)
Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'.
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.- Parameters:
src- The original matrix which is to be copied. Not modified.srcX0- Start column.srcX1- Stop column+1.srcY0- Start row.srcY1- Stop row+1.dst- Where the submatrix are stored. Modified.dstY0- Start row in dst.dstX0- start column in dst.
-
extract
public static DenseMatrix64F extract(DenseMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1)
Creates a new matrix which is the specified submatrix of 'src'
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.- Parameters:
src- The original matrix which is to be copied. Not modified.srcX0- Start column.srcX1- Stop column+1.srcY0- Start row.srcY1- Stop row+1.- Returns:
- Extracted submatrix.
-
extractDiag
public static void extractDiag(DenseMatrix64F src, DenseMatrix64F dst)
Extracts the diagonal elements 'src' write it to the 'dst' vector. 'dst' can either be a row or column vector.
- Parameters:
src- Matrix whose diagonal elements are being extracted. Not modified.dst- A vector the results will be written into. Modified.
-
extractRow
public static DenseMatrix64F extractRow(DenseMatrix64F a, int row, DenseMatrix64F out)
Extracts the row from a matrix.- Parameters:
a- Input matrixrow- Which row is to be extractedout- output. Storage for the extracted row. If null then a new vector will be returned.- Returns:
- The extracted row.
-
extractColumn
public static DenseMatrix64F extractColumn(DenseMatrix64F a, int column, DenseMatrix64F out)
Extracts the column from a matrix.- Parameters:
a- Input matrixcolumn- Which column is to be extractedout- output. Storage for the extracted column. If null then a new vector will be returned.- Returns:
- The extracted column.
-
insert
public static void insert(RealMatrix64F src, RealMatrix64F dest, int destY0, int destX0)
Inserts matrix 'src' into matrix 'dest' with the (0,0) of src at (row,col) in dest. This is equivalent to calling extract(src,0,src.numRows,0,src.numCols,dest,destY0,destX0).- Parameters:
src- matrix that is being copied into dest. Not modified.dest- Where src is being copied into. Modified.destY0- Start row for the copy into dest.destX0- Start column for the copy into dest.
-
elementMax
public static double elementMax(D1Matrix64F a)
Returns the value of the element in the matrix that has the largest value.
Max{ aij } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The max element value of the matrix.
-
elementMaxAbs
public static double elementMaxAbs(D1Matrix64F a)
Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The max abs element value of the matrix.
-
elementMin
public static double elementMin(D1Matrix64F a)
Returns the value of the element in the matrix that has the minimum value.
Min{ aij } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The value of element in the matrix with the minimum value.
-
elementMinAbs
public static double elementMinAbs(D1Matrix64F a)
Returns the absolute value of the element in the matrix that has the smallest absolute value.
Min{ |aij| } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The max element value of the matrix.
-
elementMult
public static void elementMult(D1Matrix64F a, D1Matrix64F b)
Performs the an element by element multiplication operation:
aij = aij * bij
- Parameters:
a- The left matrix in the multiplication operation. Modified.b- The right matrix in the multiplication operation. Not modified.
-
elementMult
public static void elementMult(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)
Performs the an element by element multiplication operation:
cij = aij * bij
- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
elementDiv
public static void elementDiv(D1Matrix64F a, D1Matrix64F b)
Performs the an element by element division operation:
aij = aij / bij
- Parameters:
a- The left matrix in the division operation. Modified.b- The right matrix in the division operation. Not modified.
-
elementDiv
public static void elementDiv(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)
Performs the an element by element division operation:
cij = aij / bij
- Parameters:
a- The left matrix in the division operation. Not modified.b- The right matrix in the division operation. Not modified.c- Where the results of the operation are stored. Modified.
-
elementSum
public static double elementSum(D1Matrix64F mat)
Computes the sum of all the elements in the matrix:
sum(i=1:m , j=1:n ; aij)- Parameters:
mat- An m by n matrix. Not modified.- Returns:
- The sum of the elements.
-
elementSumAbs
public static double elementSumAbs(D1Matrix64F mat)
Computes the sum of the absolute value all the elements in the matrix:
sum(i=1:m , j=1:n ; |aij|)- Parameters:
mat- An m by n matrix. Not modified.- Returns:
- The sum of the absolute value of each element.
-
elementPower
public static void elementPower(D1Matrix64F A, D1Matrix64F B, D1Matrix64F C)
Element-wise power operation
cij = aij ^ bij- Parameters:
A- left sideB- right sideC- output (modified)
-
elementPower
public static void elementPower(double a, D1Matrix64F B, D1Matrix64F C)Element-wise power operation
cij = a ^ bij- Parameters:
a- left scalarB- right sideC- output (modified)
-
elementPower
public static void elementPower(D1Matrix64F A, double b, D1Matrix64F C)
Element-wise power operation
cij = aij ^ b- Parameters:
A- left sideb- right scalarC- output (modified)
-
elementLog
public static void elementLog(D1Matrix64F A, D1Matrix64F C)
Element-wise log operation
cij = Math.log(aij)- Parameters:
A- inputC- output (modified)
-
elementExp
public static void elementExp(D1Matrix64F A, D1Matrix64F C)
Element-wise exp operation
cij = Math.log(aij)- Parameters:
A- inputC- output (modified)
-
sumRows
public static DenseMatrix64F sumRows(DenseMatrix64F input, DenseMatrix64F output)
Computes the sum of each row in the input matrix and returns the results in a vector:
bj = sum(i=1:n ; |aji|)- Parameters:
input- INput matrix whose rows are summed.output- Optional storage for output. Must be a vector. If null a row vector is returned. Modified.- Returns:
- Vector containing the sum of each row in the input.
-
sumCols
public static DenseMatrix64F sumCols(DenseMatrix64F input, DenseMatrix64F output)
Computes the sum of each column in the input matrix and returns the results in a vector:
bj = sum(i=1:m ; |aij|)- Parameters:
input- INput matrix whose rows are summed.output- Optional storage for output. Must be a vector. If null a column vector is returned. Modified.- Returns:
- Vector containing the sum of each row in the input.
-
addEquals
public static void addEquals(D1Matrix64F a, D1Matrix64F b)
Performs the following operation:
a = a + b
aij = aij + bij
- Parameters:
a- A Matrix. Modified.b- A Matrix. Not modified.
-
addEquals
public static void addEquals(D1Matrix64F a, double beta, D1Matrix64F b)
Performs the following operation:
a = a + β * b
aij = aij + β * bij- Parameters:
beta- The number that matrix 'b' is multiplied by.a- A Matrix. Modified.b- A Matrix. Not modified.
-
add
public static void add(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)
Performs the following operation:
c = a + b
cij = aij + bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
a- A Matrix. Not modified.b- A Matrix. Not modified.c- A Matrix where the results are stored. Modified.
-
add
public static void add(D1Matrix64F a, double beta, D1Matrix64F b, D1Matrix64F c)
Performs the following operation:
c = a + β * b
cij = aij + β * bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
a- A Matrix. Not modified.beta- Scaling factor for matrix b.b- A Matrix. Not modified.c- A Matrix where the results are stored. Modified.
-
add
public static void add(double alpha, D1Matrix64F a, double beta, D1Matrix64F b, D1Matrix64F c)Performs the following operation:
c = α * a + β * b
cij = α * aij + β * bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
alpha- A scaling factor for matrix a.a- A Matrix. Not modified.beta- A scaling factor for matrix b.b- A Matrix. Not modified.c- A Matrix where the results are stored. Modified.
-
add
public static void add(double alpha, D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)Performs the following operation:
c = α * a + b
cij = α * aij + bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
alpha- A scaling factor for matrix a.a- A Matrix. Not modified.b- A Matrix. Not modified.c- A Matrix where the results are stored. Modified.
-
add
public static void add(D1Matrix64F a, double val)
Performs an in-place scalar addition:
a = a + val
aij = aij + val
- Parameters:
a- A matrix. Modified.val- The value that's added to each element.
-
add
public static void add(D1Matrix64F a, double val, D1Matrix64F c)
Performs scalar addition:
c = a + val
cij = aij + val
- Parameters:
a- A matrix. Not modified.c- A matrix. Modified.val- The value that's added to each element.
-
subtract
public static void subtract(D1Matrix64F a, double val, D1Matrix64F c)
Performs matrix scalar subtraction:
c = a - val
cij = aij - val
- Parameters:
a- (input) A matrix. Not modified.val- (input) The value that's subtracted to each element.c- (Output) A matrix. Modified.
-
subtract
public static void subtract(double val, D1Matrix64F a, D1Matrix64F c)Performs matrix scalar subtraction:
c = val - a
cij = val - aij
- Parameters:
val- (input) The value that's subtracted to each element.a- (input) A matrix. Not modified.c- (Output) A matrix. Modified.
-
subtractEquals
public static void subtractEquals(D1Matrix64F a, D1Matrix64F b)
Performs the following subtraction operation:
a = a - b
aij = aij - bij- Parameters:
a- A Matrix. Modified.b- A Matrix. Not modified.
-
subtract
public static void subtract(D1Matrix64F a, D1Matrix64F b, D1Matrix64F c)
Performs the following subtraction operation:
c = a - b
cij = aij - bijMatrix C can be the same instance as Matrix A and/or B.
- Parameters:
a- A Matrix. Not modified.b- A Matrix. Not modified.c- A Matrix. Modified.
-
scale
public static void scale(double alpha, D1Matrix64F a)Performs an in-place element by element scalar multiplication.
aij = α*aij- Parameters:
a- The matrix that is to be scaled. Modified.alpha- the amount each element is multiplied by.
-
scale
public static void scale(double alpha, D1Matrix64F a, D1Matrix64F b)Performs an element by element scalar multiplication.
bij = α*aij- Parameters:
alpha- the amount each element is multiplied by.a- The matrix that is to be scaled. Not modified.b- Where the scaled matrix is stored. Modified.
-
divide
public static void divide(double alpha, D1Matrix64F a)Performs an in-place element by element scalar division with the scalar on top.
aij = &alpha/aij;- Parameters:
a- The matrix whose elements are divide the scalar. Modified.alpha- top value in division
-
divide
public static void divide(D1Matrix64F a, double alpha)
Performs an in-place element by element scalar division with the scalar on bottom.
aij = aij/α- Parameters:
a- The matrix whose elements are to be divided. Modified.alpha- the amount each element is divided by.
-
divide
public static void divide(double alpha, D1Matrix64F a, D1Matrix64F b)Performs an element by element scalar division with the scalar on top.
bij = &alpha/aij;- Parameters:
alpha- The numerator.a- The matrix whose elements are the divisor. Not modified.b- Where the results are stored. Modified.
-
divide
public static void divide(D1Matrix64F a, double alpha, D1Matrix64F b)
Performs an element by element scalar division with the scalar on botton.
bij = aij /α- Parameters:
a- The matrix whose elements are to be divided. Not modified.alpha- the amount each element is divided by.b- Where the results are stored. Modified.
-
changeSign
public static void changeSign(D1Matrix64F a)
Changes the sign of every element in the matrix.
aij = -aij- Parameters:
a- A matrix. Modified.
-
changeSign
public static void changeSign(D1Matrix64F input, D1Matrix64F output)
Changes the sign of every element in the matrix.
outputij = -inputij- Parameters:
input- A matrix. Modified.
-
fill
public static void fill(D1Matrix64F a, double value)
Sets every element in the matrix to the specified value.
aij = value- Parameters:
a- A matrix whose elements are about to be set. Modified.value- The value each element will have.
-
rref
public static DenseMatrix64F rref(DenseMatrix64F A, int numUnknowns, DenseMatrix64F reduced)
Puts the augmented system matrix into reduced row echelon form (RREF) using Gauss-Jordan elimination with row (partial) pivots. A matrix is said to be in RREF is the following conditions are true:
- If a row has non-zero entries, then the first non-zero entry is 1. This is known as the leading one.
- If a column contains a leading one then all other entries in that column are zero.
- If a row contains a leading 1, then each row above contains a leading 1 further to the left.
[1] Page 19 in, Otter Bretscherm "Linear Algebra with Applications" Prentice-Hall Inc, 1997
- Parameters:
A- Input matrix. Unmodified.numUnknowns- Number of unknowns/columns that are reduced. Set to -1 to default to Math.min(A.numRows,A.numCols), which works for most systems.reduced- Storage for reduced echelon matrix. If null then a new matrix is returned. Modified.- Returns:
- Reduced echelon form of A
- See Also:
RrefGaussJordanRowPivot
-
-
DMelt 3.0 © DataMelt by jWork.ORG