Package civitas.celestis.math.matrix
Class Matrix
java.lang.Object
civitas.celestis.util.grid.DoubleArrayGrid
civitas.celestis.math.matrix.Matrix
- All Implemented Interfaces:
BaseGrid<Double>,DoubleGrid,Serializable,Iterable<Double>
A specialized
DoubleArrayGrid used in a mathematical context.
Matrices provide various mathematical operations such as matrix-scalar,
matrix-vector, and matrix-matrix arithmetic.- See Also:
-
Field Summary
Fields inherited from class civitas.celestis.util.grid.DoubleArrayGrid
columns, rows, values -
Constructor Summary
ConstructorsConstructorDescriptionMatrix(int rows, int columns) Creates a new matrix.Matrix(DoubleGrid g) Creates a new matrix. -
Method Summary
Modifier and TypeMethodDescriptionadd(double s) Adds a scalar to this matrix, then returns the resulting matrix.Adds another matrix to this matrix, then returns the resulting matrix.doubledet()Calculates and returns the determinant of this matrix.divide(double s) Divides this matrix by a scalar, then returns the resulting matrix.static Matrixidentity(int n) Returns a newn*nidentity matrix.multiply(double s) Multiplies this matrix by a scalar, then returns the resulting matrix.Multiplies this matrix by another matrix, then returns the resulting matrix.Multiplies a vector by this matrix, then returns the resulting vector.Multiplies a vector by this matrix, then returns the resulting vector.Multiplies a vector by this matrix, then returns the resulting vector.<V extends Vector<V>>
Vmultiply(V v) Multiplies a vector by this matrix, then returns the resulting vector.static Matrixof(double[][] values) Creates a new matrix from a 2D array of values.subtract(double s) Subtracts this matrix by a scalar, then returns the resulting matrix.Subtracts another matrix from this matrix, then returns the resulting matrix.Methods inherited from class civitas.celestis.util.grid.DoubleArrayGrid
array, boxed, collect, columns, contains, containsAll, equals, fill, fillRange, forEach, forEach, get, hashCode, iterator, map, mapToObj, merge, replaceAll, resize, rows, set, set, setRange, size, stream, subGrid, toString, transpose, update, updateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
spliterator
-
Constructor Details
-
Matrix
public Matrix(int rows, int columns) Creates a new matrix.- Parameters:
rows- The number of rows to initializecolumns- The number of columns to initialize
-
Matrix
Creates a new matrix.- Parameters:
g- The numeric grid of which to copy values from
-
-
Method Details
-
of
Creates a new matrix from a 2D array of values.- Parameters:
values- The values of which to contain in the grid- Returns:
- The constructed matrix
-
identity
Returns a newn*nidentity matrix.- Parameters:
n- The number of dimensions to create the identity matrix of- Returns:
- A new
n*nidentity matrix
-
add
Adds a scalar to this matrix, then returns the resulting matrix.- Parameters:
s- The scalar of which to add to this matrix- Returns:
- The resulting matrix
-
subtract
Subtracts this matrix by a scalar, then returns the resulting matrix.- Parameters:
s- The scalar of which to subtract from this matrix- Returns:
- The resulting matrix
-
multiply
Multiplies this matrix by a scalar, then returns the resulting matrix.- Parameters:
s- The scalar of this to multiply this matrix by- Returns:
- The resulting matrix
-
divide
Divides this matrix by a scalar, then returns the resulting matrix.- Parameters:
s- The scalar of which to divide this matrix by- Returns:
- THe resulting matrix
- Throws:
ArithmeticException- When the denominatorsis zero
-
multiply
Multiplies a vector by this matrix, then returns the resulting vector.- Type Parameters:
V- The type of vector to multiply by this matrix- Parameters:
v- The vector of which to multiply to this matrix- Returns:
- The resulting vector-matrix product
- Throws:
ArithmeticException- When the number of columns is not equal to the vector's component count
-
multiply
Multiplies a vector by this matrix, then returns the resulting vector.- Parameters:
v- The vector of which to multiply to this matrix- Returns:
- The resulting vector-matrix product
- Throws:
ArithmeticException- When the number of columns is not equal to the vector's component count
-
multiply
Multiplies a vector by this matrix, then returns the resulting vector.- Parameters:
v- The vector of which to multiply to this matrix- Returns:
- The resulting vector-matrix product
- Throws:
ArithmeticException- When the number of columns is not equal to the vector's component count
-
multiply
Multiplies a vector by this matrix, then returns the resulting vector.- Parameters:
v- The vector of which to multiply to this matrix- Returns:
- The resulting vector-matrix product
- Throws:
ArithmeticException- When the number of columns is not equal to the vector's component count
-
add
Adds another matrix to this matrix, then returns the resulting matrix.- Parameters:
m- The matrix of which to add to this matrix- Returns:
- The resulting matrix
- Throws:
ArithmeticException- When the matrices' dimensions are different
-
subtract
Subtracts another matrix from this matrix, then returns the resulting matrix.- Parameters:
m- The matrix of which to subtract from this matrix- Returns:
- The resulting matrix
- Throws:
ArithmeticException- When the matrices' dimensions are different
-
multiply
Multiplies this matrix by another matrix, then returns the resulting matrix.- Parameters:
m- The matrix of which to multiply this matrix by- Returns:
- The resulting matrix
- Throws:
ArithmeticException- When the matrices' dimensions are incompatible for multiplication
-
det
Calculates and returns the determinant of this matrix.- Returns:
- The determinant of this matrix
- Throws:
IllegalStateException- When this matrix is not a square matrix (the row count and column count are different)
-