Package linalg
Class Matrix
java.lang.Object
linalg.Matrix
- Direct Known Subclasses:
Vector
Provides several methods for construction, manipulations, operations, and comparisons of complex or real matrices.
All matrices, even those constructed with int[][] or double[][] will have entries of the type
CNumber
-
Constructor Summary
ConstructorDescriptionMatrix()
Creates an empty matrix with zero rows and zero columnsMatrix(double[][] entries)
Creates matrix and copies contents of entries into matrix.Matrix(int size)
Creates a square matrix of specified size, filled with zeros.Matrix(int[][] entries)
Creates matrix and copies contents of entries into matrix.Matrix(int m, int n)
Creates a matrix with given number of rows and columns filled with zerosMatrix(int m, int n, double s)
Creates a matrix where all entries are same value.Creates a matrix where all entries are same value.Creates a square matrix of specified size, filled with specified number.Creates a matrix with given shape filled with zeros.Creates matrix and fills it with the contents of entries.Creates a matrix with given shape where all entries are same value.Creates a matrix with given shape where all entries are same value.Creates matrix and copies contents of entries into matrix.Creates a matrix that is a copy of matrix A. -
Method Summary
Modifier and TypeMethodDescriptiondefault Matrix
abs()
Computes absolute value, element-wise, of a matrix.default Matrix
add(double a)
Adds the value of a to all entries of matrix.default Matrix
Performs matrix addition on two matrices of the same dimensions.default Matrix
Augments two matrices.default Matrix
colSpace()
Finds an orthonormal basis for the column space of this matrix.default Matrix
conjT()
Computes the conjugate transpose of this matrix.default Matrix
Conjugates a matrix element-wise.copy()
Constructs a copy of the matrix.default CNumber
det()
Computes determinant of matrix.default Matrix
diag()
Extracts diagonal elements from matrix.default Vector
Extracts diagonal elements form matrix and stores in vector.default Matrix
Computes the matrix direct sum.default Matrix
divRow(int rowIndex, double divisor)
Divides a specified row by a constant value.default Matrix
Divides a specified row by a constant value.default Matrix[]
eig()
Computes the eigenvalues and associated eigenvectors for a square matrix.default Matrix
eigVals()
Computes the eigenvalues of a matrix.default Matrix
eigVecs()
Computes the right eigenvectors of a matrix.default Matrix
Performs element-wise division on two matrices of the same dimensions.default Matrix
Performs element-wise multiplication of two matrices.default boolean
Checks if two matrices are element-wise equivalent.default Matrix
erref()
Computes reduced extended row-echelon form of matrix.default Matrix
extend(int n)
Extends a row or column vector to form a matrix.default CNumber
Computes the Frobenius inner product of two matrices A and B,<A, B>
F.default Matrix
flatten()
Flattens anMxN
matrix to a 1x(m*n) matrix.default Matrix
flatten(int axis)
Flattens anMxN
matrix to a 1x(m*n) or (m*n)x1 matrix depending on axis.get(int row, int col)
Gets value from specified location from this matrix.double
getAsDouble(int row, int col)
Gets value at specified location from this matrix converted to a double.CNumber[]
getCol(int colIndex)
Extracts column from matrix.getColAsVector(int colIndex)
Extracts column vector from matrix.CNumber[]
getRow(int rowIndex)
Extracts row from matrix.getRowAsVector(int rowIndex)
Extracts column vector from matrix.getSlice(int rowStart, int rowEnd, int colStart, int colEnd)
Gets a slice of a matrix.CNumber[][]
Gets values from matrix.double[][]
Gets values from matrix converted to doubles.default Matrix
H()
Computes the Hermation adjoint of a matrix.default Matrix
Computes the Hermation adjoint of a matrix.default Matrix
hessu()
Converts a matrix similar to this matrix that is in upper Hessenburg form.default Matrix[]
hessuV()
Converts a matrix similar to this matrix that is in upper Hessenburg form.static Matrix
I(int size)
Generates the identity matrix of a specified size.static Matrix
I(int m, int n)
Creates an identity like matrix rectangular.static Matrix
identity(int size)
Generates the identity matrix of a specified size.default CNumber
infNorm()
default Matrix
inv()
Computes the matrix inverse if it exists.default Matrix
inverse()
Computes the matrix inverse if it exists.default boolean
Checks if matrix has at least one complex entry.default boolean
Checks if this matrix is diagonal.default boolean
Checks if a matrix is diagonalizable.default boolean
isEmpty()
Checks if the matrix is empty.default boolean
Checks to see if a matrices rank is the same as its number of rows.default boolean
Checks if matrix is hermation.default boolean
isI()
Checks if a matrix is an identity matrix.default boolean
Checks if B is the inverse of this matrix.default boolean
isNeg()
default boolean
Checks if this matrix is orthogonal.default boolean
isPos()
default boolean
isPosDef()
Checks if matrix is positive-definite.default boolean
Checks if matrix is positive-semidefinite.default boolean
isReal()
Checks if matrix is real.default boolean
Checks if matrix is self-adjoint.default boolean
default boolean
Checks if a matrix is skew-symmetric.default boolean
isSquare()
Checks if the matrix is square.default boolean
Checks if a matrix is symmetric.default boolean
isSymmetric(String skewOption)
Checks if a matrix is symmetric or skew-symmetric depending on the skewOption.default int
isTri()
Checks if a matrix is Triangular.
A triangular matrix has all zeros above and/or below the principle diagonal.
- Diagonal: A square matrix is diagonal if every element above and below the principle diagonal is zero.
- Lower Triangular: A square matrix is lower triangular if every element above the principle diagonal is zero.
- Upper Triangular: A square matrix is upper triangular if every element below the principle diagonal is zero
See
-isTriU()
-isTriL()
-isDiagonal()
default boolean
isTriL()
Checks if matrix is lower triangular.default boolean
isTriU()
Checks if matrix is upper triangular.default boolean
Checks if this matrix is unitary.default boolean
isVector()
Checks if a given matrix is a column or row vector.default boolean
isZero()
Checks if this matrix has only zero entries.default Matrix
Computes an orthonormal basis of the left null space of this matrix.default CNumber
max()
Finds the maximum value in the matrix.default CNumber
Finds value with maximum magnitude.default double
maxReal()
Finds the maximum real value in the matrix.default CNumber
min()
Finds the minimum value in the matrix.default CNumber
Finds value with minimum magnitude.default double
minReal()
Finds the minimum real value in the matrix.default Matrix
Performs matrix multiplication on two matrices.default Matrix
multRow(int rowIndex, double factor)
Multiplies a specified row by a constant value.default Matrix
Multiplies a specified row by a constant value.default CNumber
norm()
Computes the 2-norm of a Matrix denoted L2, 2 or AF for a matrix A.default CNumber
norm(double p)
Computes the Lp norm.default CNumber
norm(double p, double q)
Computes the Lp, q norm of this matrix.default int
nullity()
The rank of a matrix A is the dimension of the vector space spanned by the nullspace of this matrix.default Matrix
Computes a orthonormal basis for the null space of this matrix.default int
numCols()
Number of columns in this matrixdefault int
numRows()
Number of rows in this matrix.static Matrix
ones(int size)
Constructs a square matrix such that all elements in the matrix are one.static Matrix
ones(int numRows, int numCols)
Constructs a matrix with given number of rows and columns such that all elements in the matrix are one.static Matrix
Constructs a matrix with given number of rows and columns such that all elements in the matrix are one.static void
Prints a list of objects to the standard output using that objects toString() method.static void
Prints a list of objects to the standard output using that objects toString() method and a new-line character.static void
Prints a list of objects to the standard output using that objects toString() method and Separating each Object with a specified String.static Matrix
randn(int rows, int cols, boolean complex)
Generates a matrix of given size where all entries are normally distributed random values with mean of zero and a standard deviation of one.static Matrix
random(int rows, int cols, boolean... magnitude_flag)
Constructs matrix of given size with random numbers between zero and one.static Matrix
random(int rows, int cols, double mag)
Constructs matrix of given size with random complex numbers with given magnitude.static Matrix
random(int rows, int cols, double min, double max, boolean... magnitude_flag)
Constructs matrix of given size with random numbers between min and max.static Matrix
Constructs matrix of given size with random numbers between zero and one.static Matrix
Constructs matrix of given size with random complex numbers with given magnitude.static Matrix
Constructs matrix of given size with random numbers between min and max.static Matrix
randomComplex(int rows, int cols)
Generates a random complex matrix with given shape.static Matrix
randomOrthogonal(int n)
Generates a random orthogonal matrix distributed with Haar measure.static Matrix
randomUnitary(int n)
Generates a random orthogonal matrix distributed with Haar measure.default int
rank()
The rank of a matrix A is the dimension of the vector space generated (or spanned) by its columns.default Matrix
recep()
Creates a new matrix that contains the reciprocals of this matrixdefault Matrix
ref()
Computes row-echelon form of matrix.default Matrix
removeCol(int colIndex)
Removes specified single column from matrix.default Matrix
removeCols(int... colIndices)
Removes specified columns from matrix.default Matrix
removeRow(int rowIndex)
Removes specified single row from matrix.default Matrix
removeRows(int... rowIndices)
Removes specified rows from matrix.default Matrix
reshape(int newM, int newN)
default Matrix
default Matrix
round(int decimals)
Rounds all entries of a matrix.default void
roundToZero(int decimals)
Rounds values in this matrix within a specified number of decimals of zero to zero.default Matrix
rowSpace()
Finds an orthonormal basis for the row space of this matrix.default Matrix
rref()
Computes reduced row-echelon form of matrix.default Matrix
rref(boolean partialPivoting)
Computes reduced row-echelon form of matrix.default Matrix
Computes reduced row-echelon form of matrix.default boolean
Compares the dimensions, rows and columns, of two matrices.default boolean
Compares the dimensions of two matrices.default Matrix
scalDiv(double divisor)
Performs scalar division of this matrix.default Matrix
Performs scalar division of this matrix.default Matrix
scalMult(double factor)
Performs scalar multiplication of a matrix.default Matrix
Performs scalar multiplication of a matrix.default void
set(double value, int row, int col)
Sets specified element in matrix to value.default void
Sets specified element in matrix to value.default void
setCol(double[] col, int colIndex)
Sets specified column of this matrix to the values stored within the passed array.default void
Sets specified column of this matrix to the values stored within the passed array.default void
Sets specified column of this matrix to the values stored within the passed column vector.default void
setRow(double[] row, int rowIndex)
Sets specified row of this matrix to the values stored within the passed array.default void
Sets specified row of this matrix to the values stored within the passed array.default void
Sets specified row of this matrix to the values stored within the passed row vector.default void
Sets a specified slice of this matrix to the values stored in thevalues
matrix.default Matrix
setSliceCopy(int rowStart, int colStart, Matrix values)
Creates a copy of this matrix and sets a specified slice of the copy to the values stored in thevalues
matrix.default void
setValues(double[][] values)
Copies values from array into matrix.default void
Copies values from array into matrix.default String
shape()
Shape of this matrix i.e.default Matrix
sqrt()
Computes element wise square root of the matrix.default Matrix
Stacks matrices along rows.default Matrix
Stacks matrices along specified axis.default Matrix
sub(double a)
Subtracts the value of a from all entries of matrix.default Matrix
Performs matrix subtraction on two matrices of the same dimensions.default Matrix
swapCols(int colIndex1, int colIndex2)
Swaps two columns in a matrix.default Matrix
swapRows(int rowIndex1, int rowIndex2)
Swaps two rows in a matrix.default Matrix
T()
Transposes Matrix.toString()
Formats matrix contents as a string.default Vector
toVector()
If possible, converts matrix to a Vector object.
A matrix will be converted to a row vector if it contains only a single row.default CNumber
tr()
Computes the trace of a square matrix.default CNumber
trace()
Computes the trace of square matrix.default Matrix
Transposes Matrix.default Matrix
tril()
Generates lower triangle of Matrix.default Matrix
tril(int k)
Generates lower triangle of Matrix.default Matrix
triu()
Generates upper triangle of Matrix.default Matrix
triu(int k)
Generates upper triangle of Matrix.static Matrix
Constructs a Vandermonde matrix from a vector x.default int
Checks if a matrix is a vector and if so, what kind of vector (i.e row or column vectors).static Matrix
zeros(int size)
Constructs a square matrix such that all elements in the matrix are zero.static Matrix
zeros(int numRows, int numCols)
Constructs a matrix with given number of rows and columns such that all elements in the matrix are zero.static Matrix
Constructs a matrix with given number of rows and columns such that all elements in the matrix are zero.
-
Constructor Details
-
Matrix
public Matrix()Creates an empty matrix with zero rows and zero columns -
Matrix
public Matrix(int size)Creates a square matrix of specified size, filled with zeros.- Parameters:
size
- - size of the square matrix
-
Matrix
Creates a square matrix of specified size, filled with specified number.- Parameters:
size
- - size of the square matrixs
- - complex value of matrix entries.
-
Matrix
public Matrix(int m, int n)Creates a matrix with given number of rows and columns filled with zeros- Parameters:
m
- - number of rows in matrixn
- - number of columns in matrix
-
Matrix
Creates a matrix where all entries are same value.- Parameters:
m
- - number of rows in matrixn
- - number of columns in matrixs
- - complex value of matrix entries.
-
Matrix
public Matrix(int m, int n, double s)Creates a matrix where all entries are same value.- Parameters:
m
- - number of rows in matrixn
- - number of columns in matrixs
- - double value of matrix entries.
-
Matrix
Creates a matrix that is a copy of matrix A.- Parameters:
A
- - A matrix
-
Matrix
Creates matrix and fills it with the contents of entries.- Parameters:
entries
- - 2d array of Strings representing real or complex numbers.
-
Matrix
Creates matrix and copies contents of entries into matrix.- Parameters:
entries
- - 2d array of Number objects.
-
Matrix
public Matrix(double[][] entries)Creates matrix and copies contents of entries into matrix.- Parameters:
entries
- - 2d array of double.
-
Matrix
public Matrix(int[][] entries)Creates matrix and copies contents of entries into matrix.- Parameters:
entries
- - 2d array of double.
-
Matrix
Creates a matrix with given shape filled with zeros.- Parameters:
shape
- - shape of matrix.
-
Matrix
Creates a matrix with given shape where all entries are same value.- Parameters:
shape
- - shape of matrix.s
- - complex value of matrix entries.
-
Matrix
Creates a matrix with given shape where all entries are same value.- Parameters:
shape
- - shape of matrix.s
- - double value of matrix entries.
-
-
Method Details
-
zeros
Constructs a square matrix such that all elements in the matrix are zero.- Parameters:
size
- - Size of square matrix.- Returns:
- A square zero matrix of given size.
-
zeros
Constructs a matrix with given number of rows and columns such that all elements in the matrix are zero.- Parameters:
numRows
- - number of rows to be in zero matrix.numCols
- - number of columns to be in zero matrix.- Returns:
- A zero matrix with given number of rows and columns.
-
zeros
Constructs a matrix with given number of rows and columns such that all elements in the matrix are zero.- Parameters:
shape
- - Shape of zero matrix.- Returns:
- A zero matrix with given number of rows and columns.
-
ones
Constructs a square matrix such that all elements in the matrix are one.- Parameters:
size
- - Size of square matrix.- Returns:
- A square zero matrix of given size.
-
ones
Constructs a matrix with given number of rows and columns such that all elements in the matrix are one.- Parameters:
numRows
- - number of rows to be in zero matrix.numCols
- - number of columns to be in zero matrix.- Returns:
- A zero matrix with given number of rows and columns.
-
ones
Constructs a matrix with given number of rows and columns such that all elements in the matrix are one.- Parameters:
shape
- - Shape of zero matrix.- Returns:
- A zero matrix with given number of rows and columns.
-
identity
Generates the identity matrix of a specified size. Same asI(int size)
The identity matrix is a square matrix with ones on the main diagonal. All other entries are zero. The Identity matrix is the multiplicative identity for matrices. That is, given a matrix B and the appropriately sized identity matrix, B*I=B.- Parameters:
size
- - size of identity matrix. For example, if size = 3, then the 3x3 identity matrix will be returned.- Returns:
- Identity matrix of specified size.
-
I
Generates the identity matrix of a specified size. Same asidentity(int size)
The identity matrix is a square matrix with ones on the main diagonal. All other entries are zero. The Identity matrix is the multiplicative identity for matrices. That is, given a matrix B and the appropriately sized identity matrix, B*I=B.- Parameters:
size
- - size of identity matrix. For example, if size = 3, then the 3x3 identity matrix will be returned.- Returns:
- Identity matrix of specified size.
-
I
Creates an identity like matrix rectangular. That is, a matrix of zeros with ones along the principle diagonal.- Parameters:
m
- - Number of rows in matrix.n
- - Number of columns in matrix.- Returns:
- - Identity-like matrix of specified size.
-
van
Constructs a Vandermonde matrix from a vector x.- Parameters:
x
- - Column vector to construct Vandermonde matrix with.n
- - Number of columns in the Vandermonde matrix.- Returns:
- A Vandermonde matrix of shape kxn where k is the length of the vector x.
-
random
Constructs matrix of given size with random numbers between min and max. If the boolean flag is true, then min and max are used as min and max of complex magnitude. Otherwise, min and max are used as min and max values of real numbers.- Parameters:
shape
- - Shape of the resulting matrix.min
- - Lower bound for random numbermax
- - Upper bound for random numbermagnitude_flag
- - Optional flag to use min and max as bounds for magnitude of complex number.- Returns:
- Matrix with random entries of specified size
-
random
Constructs matrix of given size with random numbers between min and max. If the boolean flag is true, then min and max are used as min and max of complex magnitude. Otherwise, min and max are used as min and max values of real numbers.- Parameters:
rows
- - Number of rows in resulting matrixcols
- - Number of columns in resulting matrixmin
- - Lower bound for random numbermax
- - Upper bound for random numbermagnitude_flag
- - Optional flag to use min and max as bounds for magnitude of complex number.- Returns:
- Matrix with random entries of specified size
-
random
Constructs matrix of given size with random numbers between zero and one. If the boolean flag is true, then min and max are used as min and max of complex magnitude. Otherwise, min and max are used as min and max values of real numbers.- Parameters:
shape
- - Shape of the resulting matrix.magnitude_flag
- - Optional flag to generate complex number with magnitude between zero and one.- Returns:
- Matrix of specified size with random entries.
-
random
Constructs matrix of given size with random numbers between zero and one. If the boolean flag is true, then min and max are used as min and max of complex magnitude. Otherwise, min and max are used as min and max values of real numbers.- Parameters:
rows
- - Number of rows in resulting matrix.cols
- - Number of columns in resulting matrix.magnitude_flag
- - Optional flag to generate complex number with magnitude between zero and one.- Returns:
- Matrix of specified size with random entries.
-
random
Constructs matrix of given size with random complex numbers with given magnitude.- Parameters:
shape
- - Shape of the resulting matrixmag
- - Optional flag to generate complex number with magnitude between zero and one.- Returns:
- Matrix of specified size with random entries.
-
random
Constructs matrix of given size with random complex numbers with given magnitude.- Parameters:
rows
- - Number of rows in resulting matrix.cols
- - Number of columns in resulting matrix.mag
- - Optional flag to generate complex number with magnitude between zero and one.- Returns:
- Matrix of specified size with random entries.
-
randn
Generates a matrix of given size where all entries are normally distributed random values with mean of zero and a standard deviation of one.- Parameters:
rows
- - Number of rows in resulting matrix.cols
- - Number of columns in resulting matrix.- Returns:
- Matrix of specified size with random entries.
-
randomComplex
Generates a random complex matrix with given shape.- Parameters:
rows
- - Number of rows in random matrix.cols
- - Number of columns in random matrix.- Returns:
- Complex matrix of specified size with random entries.
-
randomOrthogonal
Generates a random orthogonal matrix distributed with Haar measure. A matrix B is orthogonal if and only if BTB = I.- Parameters:
n
- - Size of the random orthogonal matrix.- Returns:
- A random orthogonal matrix.
-
randomUnitary
Generates a random orthogonal matrix distributed with Haar measure. A matrix B is orthogonal if and only if B*B = I.- Parameters:
n
- - Size of the random orthogonal matrix.- Returns:
- A random orthogonal matrix.
-
copy
Constructs a copy of the matrix.- Returns:
- - Copy of matrix.
-
getValues
Gets values from matrix.- Returns:
- Returns entries of this matrix as 2d array of Numbers.
-
getValuesAsDouble
public double[][] getValuesAsDouble()Gets values from matrix converted to doubles.
Note: using this method will result in the loss the imaginary portion of any cells in the matrix.- Returns:
- Returns entries of this matrix as 2d array of doubles.
-
getRow
Extracts row from matrix.- Parameters:
rowIndex
- - Index of row to be returned.- Returns:
- extracted row from the matrix.
-
getRowAsVector
Extracts column vector from matrix.- Parameters:
rowIndex
- - Index of column to be returned.- Returns:
- extracted column from the matrix as vector.
-
getCol
Extracts column from matrix.- Parameters:
colIndex
- - Index of column to be returned.- Returns:
- extracted column from the matrix.
-
getColAsVector
Extracts column vector from matrix.- Parameters:
colIndex
- - Index of column to be returned.- Returns:
- extracted column from the matrix as vector.
-
getSlice
Gets a slice of a matrix. All start values inclusive, all end values exclusive.- Parameters:
rowStart
- - Beginning row of slice (inclusive).rowEnd
- - Ending row of slice (exclusive).colStart
- - Beginning column of slice (inclusive).colEnd
- - Ending column of the slice (exclusive).- Returns:
- - Returns the specified slice (or subsection) of the matrix as a new Matrix.
-
get
Gets value from specified location from this matrix.- Returns:
- Returns data in matrix at given position
-
getAsDouble
public double getAsDouble(int row, int col)Gets value at specified location from this matrix converted to a double.
Note: using this method will result in the loss of the imaginary portion of the matrix cell.- Returns:
- - data in matrix at given position as double
-
print
Prints a list of objects to the standard output using that objects toString() method.- Parameters:
printList
- - List of objects to print. Can be Matrix, Vector, String, etc.
-
println
Prints a list of objects to the standard output using that objects toString() method and a new-line character.- Parameters:
printList
- - List of objects to print. Can be Matrix, Vector, String, etc.
-
printSep
Prints a list of objects to the standard output using that objects toString() method and Separating each Object with a specified String.- Parameters:
separator
- - String to print between each Object inprintList
printList
- - List of objects to print. Can be Matrix, Vector, String, etc.
-
toString
Formats matrix contents as a string. -
add
Performs matrix addition on two matrices of the same dimensions.- Parameters:
B
- - matrix to add to the instance matrix- Returns:
- result of matrix addition
-
add
Adds the value of a to all entries of matrix.- Parameters:
a
- Value to add to matrix.- Returns:
- A new matrix with the value of a added to this matrix.
-
sub
Performs matrix subtraction on two matrices of the same dimensions.- Parameters:
B
- - matrix to subtract to the instance matrix- Returns:
- result of matrix subtraction
-
sub
Subtracts the value of a from all entries of matrix.- Parameters:
a
- Value to subtract from matrix.- Returns:
- A new matrix with the value of a added to this matrix.
-
mult
Performs matrix multiplication on two matrices. The instance matrix must have the same number of columns as the rows of B. If the instance matrix is a kxm matrix and B is a m x n matrix then the result will be a k x n matrix.- Parameters:
B
- - matrix to multiply to the instance matrix- Returns:
- result of matrix multiplication
-
elemMult
Performs element-wise multiplication of two matrices.- Parameters:
B
- - matrix to multiply element-wise to this matrix.- Returns:
- result of element-wise matrix multiplication.
- Throws:
IllegalArgumentException
- If matrices do not have the same dimension.
-
scalMult
Performs scalar multiplication of a matrix.- Parameters:
factor
- - value to multiply this matrix by.- Returns:
- The scalar multiplication of the matrix and the factor.
-
scalMult
Performs scalar multiplication of a matrix.- Parameters:
factor
- - value to multiply matrix by.- Returns:
- The scalar multiplication of the matrix and the factor.
-
elemDiv
Performs element-wise division on two matrices of the same dimensions.- Parameters:
B
- - matrix to divide element-wise the instance matrix with.- Returns:
- result of element-wise matrix multiplication.
-
scalDiv
Performs scalar division of this matrix.- Parameters:
divisor
- - value to divide matrix by.- Returns:
- The scalar division of the matrix and the divisor.
-
scalDiv
Performs scalar division of this matrix.- Parameters:
divisor
- - value to divide matrix by.- Returns:
- The scalar division of the matrix and the divisor.
-
fip
Computes the Frobenius inner product of two matrices A and B,<A, B>
F.- Parameters:
B
- - Second matrix for the Frobenius inner product.- Returns:
- the Frobenius inner product.
-
directSum
Computes the matrix direct sum. That is, a block diagonal matrix containing all matrices from a set of matrices.- Parameters:
matrixList
- - List of matrices from which to compute the matrix direct sum.- Returns:
- The result of direct summing the matrices in matrixList to this matrix.
-
sqrt
Computes element wise square root of the matrix. All square roots are the positive root or, in the case of complex entries, the root with positive real part.- Returns:
- The element-wise square root of this matrix.
-
abs
Computes absolute value, element-wise, of a matrix. If any of the matrix cells are complex, this will result in the magnitude of that value.- Returns:
- - element-wise absolute value of matrix.
-
transpose
Transposes Matrix. Same asMatrix.T()
- Returns:
- transpose of matrix
-
T
Transposes Matrix. Same asMatrix.transpose()
- Returns:
- transpose of matrix
-
conjugate
Conjugates a matrix element-wise.- Returns:
- Conjugate of matrix
-
conjT
- Returns:
- The conjugate transpose of this matrix.
-
hermAdjoint
Computes the Hermation adjoint of a matrix. This is the transpose of the conjugate matrix.
This method is the same asconjT()
andH()
.- Returns:
- adjoint of matrix.
-
H
Computes the Hermation adjoint of a matrix. This is the transpose of the conjugate matrix.
This method is the same asconjT()
andhermAdjpint()
.- Returns:
- adjoint of matrix.
-
det
Computes determinant of matrix. If the matrix has any complex entries, this may be a complex value. Note: Currently this method only works for real matirces.- Returns:
- determinant of matrix.
-
stack
Stacks matrices along rows. Both matrices must have the same number of columns Also seestack(Matrix B, int axis)
- Parameters:
B
-- Returns:
-
stack
Stacks matrices along specified axis. Axis 0 will stack matrices along the rows. Axis 1 will stack matrices along columns. Note: To stack matrices along axis 0 they must have the same number of columns. To stack matrices along axis 1 they must have the same number of rows.- Parameters:
B
- - Matrix to stackaxis
- - Axis along which to stack matrices.- Returns:
- Returns A and B stacked along specified axis.
-
augment
Augments two matrices. This is the same asstack(B, 1)
- Parameters:
B
- - Matrix to augment to this matrix.- Returns:
- The matrix B augmented to this matrix.
-
ref
Computes row-echelon form of matrix. This will be an upper-triangular matrix.
A matrix is in row-echelon form if: - The first non-zero element in each row, called the leading entry (also called the pivot), is 1. - The pivot of a nonzero row is always strictly to the right of the leading coefficient of the row above it. - Rows with all zero elements, if any, are below rows having a non-zero element.
A matrix can be transformed into a row equivalent matrix in row-echelon form using row operations. This is done using Gaussian (Gauss-Jordan) elimination.
Also see
for reduced row-echelon form.rref()
- Returns:
- Row-echelon form of matrix
-
rref
Computes reduced row-echelon form of matrix.
A matrix is in reduced row-echelon form if:
A matrix can be transformed into a row eqivalent matrix in reduced row-echelon form using row operations. This is done using Gaussian (Gauss-Jordan) elimination.
- It is in row-echelon form. This is, ~ The first non-zero element in each row, called the leading entry (also called the pivot), is 1. ~ The pivot of a nonzero row is always strictly to the right of the leading coefficient of the row above it. ~ Rows with all zero elements, if any, are below rows having a non-zero element.
- The pivot in each row is the only non-zero entry in its column.- Parameters:
partialPivoting
- - Falg for use of partial pivoting.- If true then the rref will be computed using partial pivoting. ~ This is equivalent to the method
rref()
. - If false then the rref will be computed WITHOUT using partial pivoting.- Returns:
-
rref
Computes reduced row-echelon form of matrix. This is done using partial pivoting.
A matrix is in reduced row-echelon form if:
A matrix can be transformed into a row eqivalent matrix in reduced row-echelon form using row operations. This is done using Gaussian (Gauss-Jordan) elimination.
- It is in row-echelon form. This is, ~ The first non-zero element in each row, called the leading entry (also called the pivot), is 1. ~ The pivot of a nonzero row is always strictly to the right of the leading coefficient of the row above it. ~ Rows with all zero elements, if any, are below rows having a non-zero element.
- The pivot in each row is the only non-zero entry in its column.
Also see
for row-echelon form.ref()
- Returns:
- Row-echelon form of matrix.
-
rrefNoPivot
Computes reduced row-echelon form of matrix. This is done WITHOUT using partial pivoting.
A matrix is in reduced row-echelon form if:
A matrix can be transformed into a row eqivalent matrix in reduced row-echelon form using row operations. This is done using Gaussian (Gauss-Jordan) elimination.
- It is in row-echelon form. This is, ~ The first non-zero element in each row, called the leading entry (also called the pivot), is 1. ~ The pivot of a nonzero row is always strictly to the right of the leading coefficient of the row above it. ~ Rows with all zero elements, if any, are below rows having a non-zero element.
- The pivot in each row is the only non-zero entry in its column.
Also see
for row-echelon form.ref()
- Returns:
- Row-echelon form of matrix.
-
erref
Computes reduced extended row-echelon form of matrix. That is, a Matrix with the same number of rows isaugmented
with this matrix and then this augmented matrix is put intoreduced row-echelon form
.- Returns:
- Returns extended row-echelon form of this matrix.
-
trace
Computes the trace of square matrix. That is, the sum of the entries along the principle diagonal.
This method is the same astr()
.- Returns:
- trace of this matrix.
-
tr
Computes the trace of a square matrix. That is, the sum of the entries along the principle diagonal.
This method is the same astrace()
.- Returns:
- trace of this matrix.
-
rank
default int rank()The rank of a matrix A is the dimension of the vector space generated (or spanned) by its columns. This is always an integer. This corresponds to the maximal number of linearly independent columns of A. This, in turn, is identical to the dimension of the vector space spanned by its rows- Returns:
- Returns the rank of this matrix.
-
nullity
default int nullity()The rank of a matrix A is the dimension of the vector space spanned by the nullspace of this matrix. The nullify is always an integer.- Returns:
- Returns the rank of this matrix.
-
inverse
Computes the matrix inverse if it exists. This is done by first computing theQR decomposition
The inverse of a Matrix A is A-1 satisfying AA-1=I where I is the appropriately sized Identity matrix.- Returns:
- The inverse of this matrix.
-
inv
Computes the matrix inverse if it exists. This is done by first computing theQR decomposition
The inverse of a Matrix A is A-1 satisfying AA-1=I where I is the appropriately sized Identity matrix.- Returns:
- The inverse of this matrix.
-
recep
Creates a new matrix that contains the reciprocals of this matrix- Returns:
- new matrix that contains the reciprocals of this matrix
-
reshape
-
reshape
-
flatten
Flattens anMxN
matrix to a 1x(m*n) matrix. Each row of the Matrix is appended to the end of the first row of the Matrix in order.- Returns:
-
flatten
Flattens anMxN
matrix to a 1x(m*n) or (m*n)x1 matrix depending on axis.- Parameters:
axis
- - axis along which to flatten- Returns:
-
extend
Extends a row or column vector to form a matrix. That is, for a row vector,- Parameters:
n
- Number of times to make the extension. That is, for a row vector with m entries, a matrix of shape n-by-m will be formed. For a column vector with m entries, a matrix of shape m-by-n will be formed.- Returns:
- The extended matrix formed from the vector.
- Throws:
IllegalCallerException
- if the caller is not aVector
-
setValues
Copies values from array into matrix. The given array must have the same dimensions as the matrix object. This will replace any current values in the matrix.- Parameters:
values
- - Values to copy into array
-
setValues
default void setValues(double[][] values)Copies values from array into matrix. The given array must have the same dimensions as the matrix object. A will replace any current values in the matrix.- Parameters:
values
- - Values to copy into array
-
set
Sets specified element in matrix to value. A will replace the current value at that index.- Parameters:
value
- - value to insert into matrixrow
- - row to insert valuecol
- - column to insert value
-
set
default void set(double value, int row, int col)Sets specified element in matrix to value. A will replace the current value at that index.- Parameters:
value
- - value to insert into matrixrow
- - row index to insert valuecol
- - column index to insert value
-
setCol
Sets specified column of this matrix to the values stored within the passed column vector.
Also see
setCol(CNumber[] col, int colIndex)
setCol(double[] col, int colIndex)
- Parameters:
col
- - Column vector containing the new entries for the specified column.colIndex
- - Index of new column to set.- Throws:
IllegalArgumentException
- if the vector is not a column vector or if the vector and matrix do not have the same number of rows.
-
setCol
Sets specified column of this matrix to the values stored within the passed array.
Also see
setCol(Vector col, int colIndex)
setCol(double[] col, int colIndex)
- Parameters:
col
- - array containing the new entries for the specified column.colIndex
- - Index of new column to set.- Throws:
IllegalArgumentException
- if the array of values has a different length then the number of rows in the matrix.
-
setCol
default void setCol(double[] col, int colIndex)Sets specified column of this matrix to the values stored within the passed array. Also see
setCol(Vector col, int colIndex)
setCol(CNumber[] col, int colIndex)
- Parameters:
col
- - array containing the new entries for the specified column.colIndex
- - Index of new column to set.- Throws:
IllegalArgumentException
- if the array of values has a different length then the number of rows in the matrix.
-
setRow
Sets specified row of this matrix to the values stored within the passed row vector.
Also see
setRow(CNumber[] col, int colIndex)
setRow(double[] col, int colIndex)
- Parameters:
row
- - row vector containing the new entries for the specified column.rowIndex
- - Index of new row to set.- Throws:
IllegalArgumentException
- if the vector is not a row vector or if the vector and matrix do not have the same number of columns.
-
setRow
Sets specified row of this matrix to the values stored within the passed array.
Also see
setRow(Vector col, int colIndex)
setRow(double[] col, int colIndex)
- Parameters:
row
- - array containing the new entries for the specified column.rowIndex
- - Index of new column to set.- Throws:
IllegalArgumentException
- if the array of values has a different length then the number of columns in the matrix.
-
setRow
default void setRow(double[] row, int rowIndex)Sets specified row of this matrix to the values stored within the passed array.
Also see
setRow(Vector col, int colIndex)
setRow(CNumber[] col, int colIndex)
- Parameters:
row
- - array containing the new entries for the specified column.rowIndex
- - Index of new column to set.- Throws:
IllegalArgumentException
- if the array of values has a different length then the number of columns in the matrix.
-
setSliceCopy
Creates a copy of this matrix and sets a specified slice of the copy to the values stored in thevalues
matrix. Together the parametersrowStart
andcolStart
define the upper left corner of the slice to set.
If the values matrix does not fit within this matrix, an error will be thrown.
If want to adjust this matrix instance directly seesetSlice(Matrix values, int rowStart, int colStart)
- Returns:
-
setSlice
Sets a specified slice of this matrix to the values stored in thevalues
matrix. Together the parametersrowStart
andcolStart
define the upper left corner of the slice to set.
If the values matrix does not fit within this matrix, an error will be thrown.
If you do not want to adjust this matrix instance seesetSliceCopy(Matrix values, int rowStart, int colStart)
- Parameters:
rowStart
- - Row on original matrix to place top row of values matrixcolStart
- - Column on original matrix to place left-most column of values matrixvalues
- - New values to set within specified slice.
-
removeRow
Removes specified single row from matrix. To remove more than one row at a time seeremoveRows(int... rowIndices)
.- Parameters:
rowIndex
- - Index of row to remove.- Returns:
- Matrix with the specified row removed.
-
removeRows
Removes specified rows from matrix. If k row indices are specified for a mxn matrix, the resulting matrix will have shape (m-k)xn. Also seeremoveRow(int rowIndex)
.- Parameters:
rowIndices
- - list of row indices to remove from matrix.- Returns:
- Matrix with specified rows removed
-
removeCol
Removes specified single column from matrix. To remove more than one column at a time seeremoveCols(int... colIndices)
.- Parameters:
colIndex
- - Index of column to remove.- Returns:
- Matrix with the specified column removed.
-
removeCols
Removes specified columns from matrix. If k column indices are specified for a mxn matrix, the resulting matrix will have shape m-by-(n-k). Also seeremoveCol(int colIndex)
- Parameters:
colIndices
- - list of column indices to remove from matrix.- Returns:
- Matrix with specified columns removed
-
tril
Generates lower triangle of Matrix. That is, all values above the middle diagonal will be zeroed. Also seetril(int k)
- Returns:
- Lower triangle of Matrix.
-
tril
Generates lower triangle of Matrix. That is, all values above the kth diagonal will be zeroed. Also seetril()
- Parameters:
k
- - diagonal above which to zero. k=0 whould be middile diagonal, k=-1 would be the diagonal to the left of the middle diagonal, and k=1 would be the diagonal to the right of the middle diagonal.- Returns:
- Lower triangle of Matrix.
-
triu
Generates upper triangle of Matrix. That is, all values above the middle diagonal will be zeroed. Also seetriu(int k)
- Returns:
- upper triangle of Matrix.
-
triu
Generates upper triangle of Matrix. That is, all values below the kth diagonal will be zeroed. Also seetriu()
- Parameters:
k
- - diagonal above which to zero. k=0 would be middle diagonal, k=-1 would be the diagonal to the left of the middle diagonal, and k=1 would be the diagonal to the right of the middle diagonal.- Returns:
- upper triangle of Matrix.
-
diag
Extracts diagonal elements from matrix.- Returns:
- Returns an equivalently sized matrix containing only the diagonal elements of this matrix.
-
diagAsVector
Extracts diagonal elements form matrix and stores in vector.- Returns:
- Column vector containing diagonal elements of this matrix.
-
hessu
Converts a matrix similar to this matrix that is in upper Hessenburg form. A matrix is in upper Hessenburg form if all entries below the first subdiagonal are zero. Two n-by-n matrices A and B are similar if there exists an invertible n-by-n matrix P, such that B=P-1AP. Similar matrices share many properties including the same eigenvalues.- Returns:
- A matrix similar to this matrix which is in upper Hessenburg form.
-
hessuV
Converts a matrix similar to this matrix that is in upper Hessenburg form. A matrix is in upper Hessenburg form if all entries below the first subdiagonal are zero. Two n-by-n matrices A and B are similar if there exists an invertible n-by-n matrix P, such that B=P-1AP. Similar matrices share many properties including the same eigenvalues.- Returns:
- A matrix similar to this matrix which is in upper Hessenburg form.
-
swapRows
Swaps two rows in a matrix.- Parameters:
rowIndex1
- - Index of first row to be swapped.rowIndex2
- - Index of second row to be swapped.- Returns:
- Matrix with specified rows swapped.
-
swapCols
Swaps two columns in a matrix.- Parameters:
colIndex1
- - Index of first column to be swapped.colIndex2
- - Index of second column to be swapped.- Returns:
- Matrix with specified columns swapped.
-
multRow
Multiplies a specified row by a constant value.- Parameters:
factor
- - number to multiply row by.- Returns:
- Matrix with specified row multiplied by the factor.
-
multRow
Multiplies a specified row by a constant value.- Parameters:
factor
- - number to multiply row by.- Returns:
- Matrix with specified row multiplied by the factor
-
divRow
Divides a specified row by a constant value.- Parameters:
divisor
- - number to divide row by.- Returns:
- Matrix with specified row divided by the divisor.
-
divRow
Divides a specified row by a constant value.- Parameters:
divisor
- - number to divide row by.- Returns:
- Matrix with specified row divided by the divisor.
-
toVector
If possible, converts matrix to a Vector object.
A matrix will be converted to a row vector if it contains only a single row.
A matrix will be converted to a column vector if it contains only a single column.
If a matrix contains only one row and one column or is empty, then it will be converted to a column vector by default.- Returns:
- Vector equivalent of matrix.
-
round
Rounds all entries of a matrix. If entry is complex, both the real and imaginary part will be rounded.- Parameters:
decimals
- - Number of decimals to round number to.- Returns:
- Returns copy of Matrix
A
with entries rounded to Specified number of decimal places.
-
roundToZero
default void roundToZero(int decimals)Rounds values in this matrix within a specified number of decimals of zero to zero.- Parameters:
decimals
- - Number of decimals
-
numCols
default int numCols()Number of columns in this matrix- Returns:
- Number of rows in matrix.
-
numRows
default int numRows()Number of rows in this matrix.- Returns:
- Number of columns in matrix.
-
shape
Shape of this matrix i.e. number of rows and columns.- Returns:
- Returns shape of this matrix shape as String e.g. "m x n".
-
isSquare
default boolean isSquare()Checks if the matrix is square. That is, does the matrix have the same number of rows and columns?- Returns:
- True if the matrix is square, false otherwise.
-
isEmpty
default boolean isEmpty()Checks if the matrix is empty. That is, does the matrix have exactly zero entries?- Returns:
- True if the matrix is empty, false otherwise.
-
min
Finds the minimum value in the matrix. If the matrix is complex, the value with the smallest magnitude will be returned. If the matrix is real, the smallest real number will be returned.
Also seeminReal()
andminComplex()
- Returns:
- minimum value of this matrix
-
minReal
default double minReal()Finds the minimum real value in the matrix. If the matrix contains non-real values, the imaginary component will be ignored.
Also seemin()
andminComplex()
- Returns:
- Returns minimum real value of this matrix.
-
max
Finds the maximum value in the matrix. If the matrix is complex, the value with the largest magnitude will be returned. If the matrix is real, the largest real number will be returned.
Also seemaxReal()
andmaxComplex()
- Returns:
- Returns maximum value of this matrix.
-
maxReal
default double maxReal()Finds the maximum real value in the matrix. If the matrix contains any non-real entries, the imaginary component will be ignored.
Also seemax()
andmaxComplex()
- Returns:
- Returns maximum real value of this matrix.
-
minComplex
- Returns:
- Returns value with minimum magnitude in this matrix.
-
maxComplex
- Returns:
- Returns value with maximum magnitude in this matrix.
-
isReal
default boolean isReal()Checks if matrix is real. That is, the matrix only has real entries.- Returns:
- True if matrix has no complex entries. Otherwise, false.
-
isComplex
default boolean isComplex()Checks if matrix has at least one complex entry.- Returns:
- True if matrix has at least one non-real entry. Otherwise, false.
-
isVector
default boolean isVector()Checks if a given matrix is a column or row vector. A column vector will be a a matrix of shapemx1
and a row vector will be a matrix of shape1xn
- Returns:
- True if matrix is a column or row vector, otherwise returns false.
-
vectorType
default int vectorType()Checks if a matrix is a vector and if so, what kind of vector (i.e row or column vectors).- Returns:
- 0 if the matrix is NOT a vector, 1 if the matrix is a row vector, 2 if the matrix is a column vector, and 3 if the matrix is of shape 1x1
-
isSelfAdjoint
default boolean isSelfAdjoint()Checks if matrix is self-adjoint. That is, if the matrix is equal to its own conjugate transpose.
Same asisHermation()
.- Returns:
- True if the matrix is self-adjoint. Otherwise, returns false.
-
isHermation
default boolean isHermation()Checks if matrix is hermation. That is, if the matrix is equal to its own conjugate transpose.
Same asisSelfAdjoint()
.- Returns:
- True if the matrix is hermation. Otherwise, returns false.
-
isSymmetric
default boolean isSymmetric()Checks if a matrix is symmetric.
For an square matrix A, A is symmetric if and only ifA[i][j] = A[j][i]
for all i, j. That is, if A is equal its own transpose, then it is symmetric.
Also seeisSkewSymmetric()
andisSymmetric(String skewOption)
- Returns:
- True if this matrix is symmetric, false otherwise.
-
isSkewSymmetric
default boolean isSkewSymmetric()Checks if a matrix is skew-symmetric.
For an square matrix A, A is skew-symmetric if and only ifA[i][j] = -A[j][i]
for all i, j. That is, if A is equal to the negative of its own transpose, then it is skew-symmetric.
Also seeisSymmetric()
andisSymmetric(String skewOption)
- Returns:
- True if this matrix is symmetric, false otherwise.
-
isSymmetric
Checks if a matrix is symmetric or skew-symmetric depending on the skewOption.
- If skewOption is passed "skew", this method is identical toisSkewSymmetric()
.
- If skewOption is passed "no-skew", this method is identical toisSymmetric()
.
For an square matrix A, A is symmetric if and only ifA[i][j] = A[j][i]
for all i, j. That is, if A is equal to A transpose.
A is skew-symmetric if and only ifA[i][j] = -A[j][i]
for all i, j. That is, if A is equal to -A transpose.- Parameters:
skewOption
- - String to indicate whether to check for symmetry or skew-symmetry. Specify skewOption as "skew" to check for skew-symmetry or "no-skew" to check for regular symmetry.- Returns:
- True if the matrix is symmetric/skew-symmetric. Otherwise, returns false.
-
isOrthogonal
default boolean isOrthogonal()Checks if this matrix is orthogonal. A square matrixQ
is orthogonal if and only ifQQ^T = I
where I is the appropriately sized identity matrix.
Please note, this method only checks ifQQ^T = I
. If the matrix is complex you may be looking forisUnitary()
which checks if a matrix is unitary orQQ^* = I
whereQ^*
is the conjugate transpose ofQ
. TheisUnitary()
method will behave the same as this method for real matrices.- Returns:
- True if the matrix is orthogonal. Otherwise, returns false.
-
isUnitary
default boolean isUnitary()Checks if this matrix is unitary. A square matrixQ
is unitary if and only ifQQ^* = I
whereI
is the appropriately sized identity matrix andQ^*
is the conjugate transpose.
For real matrices, this method is the same asisOrthogonal()
.- Returns:
- True if the matrix is unitary. Otherwise, returns false.
-
isTri
default int isTri()Checks if a matrix is Triangular.
A triangular matrix has all zeros above and/or below the principle diagonal.
- Diagonal: A square matrix is diagonal if every element above and below the principle diagonal is zero.
- Lower Triangular: A square matrix is lower triangular if every element above the principle diagonal is zero.
- Upper Triangular: A square matrix is upper triangular if every element below the principle diagonal is zero
See
-isTriU()
-isTriL()
-isDiagonal()
- Returns:
- - 1 if matrix is not triangular.
- 0 if Matrix is diagonal.
- 1 if Matrix is lower triangular.
- 2 if Matrix is upper triangular.
-
isTriU
default boolean isTriU()Checks if matrix is upper triangular. A square matrix is upper triangular if every element below the principle diagonal is zero.- Returns:
- True if this matrix is upper triangular. Otherwise, returns false.
-
isTriL
default boolean isTriL()Checks if matrix is lower triangular. A square matrix is lower triangular if every element above the principle diagonal is zero.- Returns:
- True if this matrix is lower triangular. Otherwise, returns false.
-
isDiagonal
default boolean isDiagonal()Checks if this matrix is diagonal. A matrix is diagonal if every element above and below the principle diagonal is zero.- Returns:
- True if this matrix is diagonal. Otherwise, returns false.
-
isFullRank
default boolean isFullRank()Checks to see if a matrices rank is the same as its number of rows.- Returns:
- Returns true if matrix is full rank. Otherwise, returns false.
-
isSingular
default boolean isSingular() -
norm
Computes the 2-norm of a Matrix denoted L2, 2 or AF for a matrix A. This is known as the Frobenius norm or the Hilbert�Schmidt norm. -
norm
Computes the Lp norm. This is equivalent to Lp, q where p = q.
p can beDouble.POSITIVE_INFINITY
. which will result in the infinity / max norm being computed.- Parameters:
p
- - norm parameter- Returns:
-
norm
Computes the Lp, q norm of this matrix.- Parameters:
p
- - norm parameter 1q
- - norm parameter 2- Returns:
- Returns Lp, q norm of this matrix
-
infNorm
-
rowSpace
Finds an orthonormal basis for the row space of this matrix.
The row space of a matrix is the span of all column vectors. A orthonormal row space basis is a linearly independent set of unit vectors which also spans the row space.- Returns:
- A matrix whose rows are row vectors forming an orthonormal basis for the row space of this matrix.
-
colSpace
Finds an orthonormal basis for the column space of this matrix.
The column space of a matrix is the span of all column vectors. A orthonormal column space basis is a linearly independent set of unit vectors which also spans the column space.- Returns:
- A matrix whose columns are column vectors forming an orthonormal basis for the columns space of this matrix.
-
nullSpace
Computes a orthonormal basis for the null space of this matrix. The null space of a matrix A is all vectors x that satisfy Ax =0 .- Returns:
- A matrix whose column vectors from an orthonormal basis for the null space of this matrix.
-
leftNullSpace
Computes an orthonormal basis of the left null space of this matrix. The left null space of a matrix A is all column vectors x which satisfy xTA=0T. This is equivalent to the thenull space
of AT.- Returns:
-
isPos
default boolean isPos()- Returns:
- True if matrix only contains positive real entries.
-
isNeg
default boolean isNeg()- Returns:
- True if matrix only contains negative entries.
-
isPosDef
default boolean isPosDef()Checks if matrix is positive-definite. An m-by-m hermation (or symmetric if real) matrix M is positive-definite if for all non-zero column vectors z, zHMz is positive where zH is the conjugate transpose of z.
Also seepositive-semidefinite
.- Returns:
- True if the matrix is positive-definite. Otherwise, returns false.
-
isPosSemidef
default boolean isPosSemidef()Checks if matrix is positive-semidefinite. An m-by-m hermation (or symmetric if real) matrix M is positive-definite if for all non-zero \ column vector z, z*Mz is non-negative where z* is the conjugate transpose of z.
Also seepositive-definite
.- Returns:
- True if the matrix is positive-semidefinite. Otherwise, returns false.
-
eig
Computes the eigenvalues and associated eigenvectors for a square matrix.
Also see
-eigVecs()
to compute just the eigenvectors.
-eigVals()
to compute just the eigenvalues. This is recommended if the eigenvectors are not needed as it will be faster.- Returns:
- Returns an array of two matrices. The first matrix is a row vector which contains the eigenvalues of A (no necessarily ordered but grouped by equality), repeated per there multiplicity. The columns of the second matrix are the eigenvectors of A associated with each eigenvalue in the first matrix. For repeated eigenvalues, each associated eigenvector in the second matrix is an associated eigenvector.
-
eigVecs
Computes the right eigenvectors of a matrix. This is done by first computing the Schur decomposition.
Also see
-eig()
to compute both eigenvalues and eigenvectors.
-eigVals()
to compute just the eigenvalues.- Returns:
- Returns a matrix containing the eigenvectors of this matrix as its column vectors.
-
eigVals
Computes the eigenvalues of a matrix. This is done by first computing the Schur decomposition.
Also see
-eig()
to compute both eigenvalues and eigenvectors.
-eigVecs()
to compute just the eigenvectors.- Returns:
- Returns a column vector containing the eigenvalues of this matrix.
-
isDiagonalizable
default boolean isDiagonalizable()Checks if a matrix is diagonalizable. A matrix B is diagonalizable if and only if the multiplicity for each eigenvalue is equivalent to the eigenspace for that eigenvalue.- Returns:
- True if the matrix is diagonalizable. Otherwise, returns false.
-
equals
Checks if two matrices are element-wise equivalent. If the two matrices are different shapes, this method will return false.- Parameters:
B
- - Matrix to compare equality with- Returns:
- True if both matrices are element-wise equivalent. Otherwise, false.
-
sameShape
Compares the dimensions of two matrices. Ifcode
is passed zero then this method will check if both matrices have the same number of rows and columns. Ifcode
is passed one then this method will check if both matrices have the same number of rows only. Ifcode
is passed two then this method will check if both matrices have the same number of columns only. To check rows against columns usematMultCheck(Matrix A, Matrix B)
- Parameters:
B
- - Another matrixcode
- - Choice for dimension(s) along which to check equivalence- Returns:
- - true if the dimensions specified by
code
are equvalent. Otherwise. returns false
-
sameShape
Compares the dimensions, rows and columns, of two matrices.- Parameters:
B
- - Another matrix- Returns:
- - True if the number of rows and number of column of the two matrices are both equal. Otherwise, returns false.
-
isZero
default boolean isZero()Checks if this matrix has only zero entries. If so, then the matrix is the so called zero matrix and is the additive identity for matrices of the same size.- Returns:
- Returns true if matrix has all zero elements. Otherwise, returns false.
-
isI
default boolean isI()Checks if a matrix is an identity matrix.- Returns:
- Returns true if the matrix in question is an identity matrix. Otherwise, returns false.
-
isInv
Checks if B is the inverse of this matrix.
Seematrix inverse
- Returns:
- True if B is the inverse of this matrix. Otherwise, returns false.
-