This class defines a set of static methods for calculations with vectors and matrices using native Java arrays
without any enclosing object structures. Matrices are simple two-dimensional arrays A[r][c]
, where r
is the (vertical) row index and c
is the (horizontal) column index (as
common in linear algebra). This means that matrices are really vectors of row vectors. Only arrays of type
float
and double
are supported. All matrices are assumed to be rectangular (i.e., all rows are of
equal length).
Note: Methods named with a trailing 'D
' (e.g., multiplyD(double, double[])
) operate destructively,
i.e., modify one of the supplied arguments.
- Version:
- 2022/08/29
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Thrown when the dimensions of matrix/vector arguments do not match.static class
Thrown when a non-square matrix is encountered where a square matrix is assumed.static class
Thrown when source and target objects are identical but shouldn't.static class
Thrown when the length of some vector is zero. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Default matrix symmetry tolerance.static char
Leading delimiter used for lists of vector and matrix elements bytoString()
methods.static Locale
Locale used for printing decimal numbers bytoString()
methods.static char
Trailing delimiter used for lists of vector and matrix elements bytoString()
methods.static char
Character used to separate successive vector and matrix elements bytoString()
methods. -
Method Summary
Modifier and TypeMethodDescriptionstatic double[][]
add
(double[][] A, double[][] B) Calculates and returns the sum of the specifieddouble
matrix (non-destructively).static double[]
add
(double[] a, double[] b) Calculates and returns the sum of the specifieddouble
vectors (non-destructively).static float[][]
add
(float[][] A, float[][] B) Calculates and returns the sum of the specifiedfloat
matrix (non-destructively).static float[]
add
(float[] a, float[] b) Calculates and returns the sum of the specifiedfloat
vectors (non-destructively).static void
addD
(double[][] A, double[][] B) Adds the elements of the firstdouble
matrix to the second vector (destructively).static void
addD
(double[] a, double[] b) Adds the elements of the firstdouble
vector to the second vector (destructively).static void
addD
(float[][] A, float[][] B) Adds the elements of the firstfloat
matrix to the second vector (destructively).static void
addD
(float[] a, float[] b) Adds the elements of the firstfloat
vector to the second vector (destructively).static void
copyD
(double[] source, double[] target) Copy data from onedouble[]
vector to another.static void
copyD
(float[] source, float[] target) Copy data from onefloat[]
vector to another.static double
determinant
(double[][] A) Calculates and returns the determinant of the givendouble[][]
matrix.static double
Calculates and returns the determinant of the givenRealMatrix
.static double
determinant2x2
(double[][] A) Calculates and returns the determinant of the given 2x2double[][]
matrix.static float
determinant2x2
(float[][] A) Calculates and returns the determinant of the given 2x2float[][]
matrix.static double
determinant3x3
(double[][] A) Calculates and returns the determinant of the given 3x3double[][]
matrix.static float
determinant3x3
(float[][] A) Calculates and returns the determinant of the given 3x3float[][]
matrix.double[][]
diagMatrix
(double[] d) Creates and returns a diagonal matrix from the specified vector.static double
distL2
(double[] a, double[] b) Calculates the L2 distance between two vectors (points) in n-dimensional space.static float
distL2
(float[] a, float[] b) Calculates the L2 distance between two vectors (points) in n-dimensional space.static double
distL2squared
(double[] a, double[] b) Calculates the squared L2 distance between two vectors (points) in n-dimensional space.static float
distL2squared
(float[] a, float[] b) Calculates the squared L2 distance between two vectors (points) in n-dimensional space.static double
dotProduct
(double[] a, double[] b) Calculates and returns the dot (inner or scalar) product of two vectors, which must have the same length.static double[]
duplicate
(double[] a) Returns a copy of the givendouble[]
vector.static double[][]
duplicate
(double[][] A) Returns a copy of the givendouble[][]
matrix.static float[]
duplicate
(float[] a) Returns a copy of the givenfloat[]
vector.static float[][]
duplicate
(float[][] A) Returns a copy of the givenfloat[][]
matrix.static void
fillD
(double[][] A, double val) Fills the givendouble
matrix with the specified value (destructively).static void
fillD
(double[] x, double val) Fills the givendouble
vector with the specified value (destructively).static void
fillD
(float[][] A, float val) Fills the givenfloat
matrix with the specified value (destructively).static void
fillD
(float[] x, float val) Fills the givenfloat
vector with the specified value (destructively).static double[]
flatten
(double[][] A) Returns the values of the specified matrix as adouble[]
with elements arranged in row-major order.static float[]
flatten
(float[][] A) Returns the values of the specified matrix as afloat[]
with elements arranged in row-major order.static double[]
Returns the values of the specified matrix as adouble[]
with elements arranged in row-major order.static double[][]
fromLongBits
(long[][] A) Converts along[][]
with 64-bitdouble
representations to the equivalentdouble[][]
.static double[]
getColumn
(double[][] A, int c) Returns a particular column of the specifieddouble
matrix as adouble
vector.static float[]
getColumn
(float[][] A, int c) Returns a particular column of the specifiedfloat
matrix as afloat
vector.static double[]
getDiagonal
(double[][] A) Returns a vector with the diagonal elements of the specified matrix.static float[]
getDiagonal
(float[][] A) Returns a vector with the diagonal elements of the specified matrix.static RealVector
Returns a vector with the diagonal elements of the specified matrix.static int
getNumberOfColumns
(double[][] A) Returns the number of columns of the specifieddouble
matrix.static int
getNumberOfColumns
(float[][] A) Returns the number of columns of the specifiedfloat
matrix.static int
Returns the number of columns of the specifiedRealMatrix
.static int
getNumberOfRows
(double[][] A) Returns the number of rows of the specifieddouble
matrix.static int
getNumberOfRows
(float[][] A) Returns the number of rows of the specifiedfloat
matrix.static int
Returns the number of rows of the specifiedRealMatrix
.static double[]
getRow
(double[][] A, int r) Returns a particular row of the specifieddouble
matrix as adouble
vector.static float[]
getRow
(float[][] A, int r) Returns a particular row of the specifiedfloat
matrix as afloat
vector.static double[][]
idMatrix
(int size) Creates and returns a new identity matrix of the specified size.static int
idxMax
(double[] a) Returns the index of the largest element in the specified vector.static int
idxMax
(float[] a) Returns the index of the largest element in the specified vector.static int
idxMin
(double[] a) Returns the index of the smallest element in the specified vector.static int
idxMin
(float[] a) Returns the index of the smallest element in the specified vector.static double[][]
inverse
(double[][] A) Calculates and returns the inverse of the given matrix, which must be square.static float[][]
inverse
(float[][] A) Calculates and returns the inverse of the given matrix, which must be square.static boolean
Checks is the given square matrix is positive definite.static boolean
isPositiveDefinite
(RealMatrix A, double tolerance) Checks is the given square matrix is positive definite, using the specified symmetry tolerance value.static boolean
isRectangular
(double[][] A) Checks if all rows of the given matrix have the same length.static boolean
isRectangular
(float[][] A) Checks if all rows of the given matrix have the same length.static boolean
isSingular
(double[][] A) Checks is the given squaredouble[][]
matrix is non-singular.static boolean
Checks is the given square matrix is non-singular.static boolean
isSquare
(double[][] A) Checks it the given matrix has the same number of rows and columns.static boolean
isSquare
(float[][] A) Checks it the given matrix has the same number of rows and columns.static boolean
isSymmetric
(double[][] A) Checks is the given square matrix is symmetric, using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).static boolean
isSymmetric
(double[][] A, double relTolerance) Checks is the given square matrix is symmetric using the specified relative tolerance.static boolean
Checks is the given square matrix is symmetric, using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).static boolean
isSymmetric
(RealMatrix A, double relTolerance) Checks is the given square matrix is symmetric using the specified relative tolerance.static boolean
isZero
(double[] a) Checks if all elements of the specifieddouble[]
vector are zero using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).static boolean
isZero
(double[][] A) Checks if all elements of the specifieddouble[][]
matrix are zero using default tolerance value (Arithmetic.EPSILON_DOUBLE
).static boolean
isZero
(double[][] A, double tolerance) Checks if all elements of the specifieddouble[][]
matrix are zero using the specified tolerance value.static boolean
isZero
(double[] a, double tolerance) Checks if all elements of the specifieddouble[]
vector are zero using the specified tolerance value.static boolean
isZero
(float[] a) Checks if all elements of the specifiedfloat[]
vector are zero using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).static boolean
isZero
(float[] a, float tolerance) Checks if all elements of the specifiedfloat[]
vector are zero using the specified tolerance value.static double[]
join
(double[]... as) Joins (concatenates) a sequence of vectors into a single vector.static float[]
join
(float[]... as) Joins (concatenates) a sequence of vectors into a single vector.static double[]
lerp
(double[] a, double[] b, double t) Performs linear interpolation between two vectorsa
andb
, which must have the same length.static float[]
lerp
(float[] a, float[] b, float t) Performs linear interpolation between two vectorsa
andb
, which must have the same length.static double[][]
makeDoubleMatrix
(int rows, int cols, double... values) Creates and returns adouble[][]
matrix containing the specified values.static double[]
makeDoubleVector
(double... values) Creates and returns adouble[]
vector from the specified values.static float[][]
makeFloatMatrix
(int rows, int cols, float... values) Creates and returns afloat[][]
matrix containing the specified values.static float[]
makeFloatVector
(float... values) Creates and returns afloat[]
vector from the specified values.static RealMatrix
makeRealMatrix
(int rows, int cols, double... values) Creates and returns aRealMatrix
containing the specifieddouble
values.static RealVector
makeRealVector
(double... values) Creates and returns aRealVector
from the specifieddouble
values.static double
max
(double[] a) Returns the largest value in the specifieddouble[]
vector.static double
max
(double[][] A) Returns the largest value in the specifieddouble[][]
matrix.static float
max
(float[] a) Returns the largest value in the specifiedfloat[]
vector.static float
max
(float[][] A) Returns the largest value in the specifiedfloat[][]
matrix.static double
min
(double[] a) Returns the smallest value in the specified vector.static float
min
(float[] a) Returns the smallest value in the specified vector.static double[]
multiply
(double[][] A, double[] x) Multiplies a matrix A with a vector x "from the right", i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector.static double[][]
multiply
(double[][] A, double[][] B) Returns the product of twodouble[][]
matrices A, B as a newdouble[][]
matrix.static double[]
multiply
(double[] x, double[][] A) Multiplies a vector x with a matrix A "from the left", i.e., y = x * A, where x is treated as a row vector and the result y is also a row vector.static double[]
multiply
(double s, double[] x) Multiplies adouble[]
vector by a scalar and returns a newdouble[]
vector (non-destructive).static double[][]
multiply
(double s, double[][] A) Multiplies adouble[][]
matrix by a scalar and returns a newdouble[][]
matrix (non-destructive).static float[]
multiply
(float[][] A, float[] x) Multiplies a matrix A with a vector x from the right, i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector.static float[][]
multiply
(float[][] A, float[][] B) Returns the product of twofloat[][]
matrices A, B as a newfloat[][]
matrix.static float[]
multiply
(float s, float[] x) Multiplies afloat[]
vector by a scalar and returns a newfloat[]
vector (non-destructive).static float[][]
multiply
(float s, float[][] A) Multiplies afloat[][]
matrix by a scalar and returns a newfloat[][]
matrix (non-destructive).static void
multiplyD
(double[][] A, double[][] B, double[][] C) Calculates the product of twodouble[][]
matrices A, B and places the results in the thirddouble[][]
matrix C, which is modified (destructively).static void
multiplyD
(double[][] A, double[] x, double[] y) Multiplies a matrix A with a vector x "from the right", i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector.static void
multiplyD
(double[] x, double[][] A, double[] y) Destructive version ofmultiply(double[], double[][])
.static void
multiplyD
(double s, double[] x) Multiplies adouble[]
vector by a scalar.static void
multiplyD
(double s, double[][] A) Multiplies adouble[][]
matrix by a scalar.static void
multiplyD
(float[][] A, float[][] B, float[][] C) Calculates the product of twofloat[][]
matrices A, B and places the results in the thirdfloat[][]
matrix C, which is modified (destructively).static void
multiplyD
(float[][] A, float[] x, float[] y) Multiplies a matrix A with a vector x "from the right", i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector.static void
multiplyD
(float s, float[] x) Multiplies afloat[]
vector by a scalar.static void
multiplyD
(float s, float[][] A) Multiplies afloat[][]
matrix by a scalar.static double
norm
(double[][] A) Calculates and returns the Froebenius norm of the given matrix.static double[]
normalize
(double[] a) Normalizes the specifieddouble[]
vector to unit (L2) norm and returns the result as a newdouble[]
vector.static float[]
normalize
(float[] a) Normalizes the specifiedfloat[]
vector to unit (L2) norm and returns the result as a newfloat[]
vector.static void
normalizeD
(double[] a) Normalizes the specifieddouble[]
vector to unit (L2) norm.static void
normalizeD
(float[] a) Normalizes the specifiedfloat[]
vector to unit (L2) norm.static double
normL1
(double[] a) Calculates and returns the L1 norm of the given vector.static float
normL1
(float[] a) Calculates and returns the L1 norm of the given vector.static double
normL2
(double[] a) Calculates and returns the L2 norm of the given vector.static float
normL2
(float[] x) Calculates and returns the L2 norm of the given vector.static double
normL2squared
(double[] a) Calculates and returns the squared L2 norm of the given vector.static double
normL2squared
(float[] a) Calculates and returns the squared L2 norm of the given vector.static double[][]
outerProduct
(double[] a, double[] b) Calculates and returns the outer product of two vectors, which is a matrix of size (m,n), where m is the length of the first vector and m is the length of the second vector.static void
printToStream
(double[][] A, PrintStream strm) Outputs a string representation of the given matrix to the specified output stream.static void
printToStream
(double[] a, PrintStream strm) Outputs a string representation of the given vector to the specified output stream.static void
printToStream
(float[][] A, PrintStream strm) Outputs a string representation of the given matrix to the specified output stream.static void
printToStream
(float[] a, PrintStream strm) Outputs a string representation of the given vector to the specified output stream.static void
printToStream
(long[][] A, PrintStream strm) static boolean
sameSize
(double[][] A, double[][] B) Checks if the given matrices have the same size.static boolean
sameSize
(double[] a, double[] b) Checks if the given vectors have the same length.static boolean
sameSize
(float[][] A, float[][] B) Checks if the given matrices have the same size.static boolean
sameSize
(float[] a, float[] b) Checks if the given vectors have the same length.static double[]
solve
(double[][] A, double[] b) Finds the exact solution x for the linear system of equations A * x = b.static RealVector
solve
(RealMatrix A, RealVector b) Finds the exact solution x for the linear system of equations A * x = b.static double[]
sort
(double[] a) Returns a sorted copy of the givendouble[]
vector.static float[]
sort
(float[] a) Returns a sorted copy of the givenfloat[]
vector.static double[]
subtract
(double[] a, double[] b) Calculates and returns the difference (a - b) of the specifieddouble
vectors (non-destructively).static float[]
subtract
(float[] a, float[] b) Calculates and returns the difference (a - b) of the specifiedfloat
vectors (non-destructively).static double
sum
(double[] a) Calculates and returns the sum of the elements in the specifieddouble[]
vector.static double
sum
(double[][] A) Calculates and returns the sum of the elements in the specifieddouble[][]
matrix.static double
sum
(float[] a) Calculates and returns the sum of the elements in the specifiedfloat[]
vector.static double
sum
(float[][] A) Calculates and returns the sum of the elements in the specifiedfloat[][]
matrix.static double
sumColumn
(double[][] A, int col) Calculates the sum of the elements in the specified matrix column.static double
sumColumn
(float[][] A, int col) Calculates the sum of the elements in the specified matrix column.static double[]
sumColumns
(double[][] A) Calculates the sums of all matrix columns and returns them as a vector with one element per column.static float[]
sumColumns
(float[][] A) Calculates the sums of all matrix columns and returns them as a vector with one element per column.static double
sumRow
(double[][] A, int row) Calculates the sum of the elements in the specified matrix row.static double
sumRow
(float[][] A, int row) Calculates the sum of the elements in the specified matrix row.static double[]
sumRows
(double[][] A) Calculates the sums of all matrix rows and returns them as a vector with one element per row.static float[]
sumRows
(float[][] A) Calculates the sums of all matrix rows and returns them as a vector with one element per row.static double[]
toCartesian
(double[] ah) Converts a homogeneous vector to its equivalent Cartesian vector, which is one element shorter.static double[]
toDouble
(float[] a) Converts afloat[]
to adouble[]
.static double[][]
toDouble
(float[][] A) Converts afloat[][]
to adouble[][]
.static float[]
toFloat
(double[] a) Converts adouble[]
to afloat[]
.static float[][]
toFloat
(double[][] A) Converts adouble[][]
to afloat[][]
.static double[]
toHomogeneous
(double[] ac) Converts a Cartesian vector to an equivalent homogeneous vector by attaching an additional 1-element.static long[][]
toLongBits
(double[][] A) Converts adouble[][]
to along[][]
whose elements contain the 64-bit representation of the originaldouble
values.static String
toString
(double[] a) Returns a string representation of the specified vector.static String
toString
(double[][] A) Returns a string representation of the specified matrix.static String
toString
(float[] a) Returns a string representation of the specified vector.static String
toString
(float[][] A) Returns a string representation of the specified matrix.static String
toString
(long[][] A) Returns a string representation of the specified matrix withlong
elements.static String
Returns a string representation of the specified matrix.static String
Returns a string representation of the specified vector.static double
trace
(double[][] A) Calculates and returns the trace of the givendouble[][]
matrix.static float
trace
(float[][] A) Calculates and returns the trace of the givenfloat[][]
matrix.static double[][]
transpose
(double[][] A) Returns the transpose of the givendouble[][]
matrix.static float[][]
transpose
(float[][] A) Returns the transpose of the givenfloat[][]
matrix.static double[]
zeroVector
(int length) Creates and returns a new zero-valueddouble[]
vector of the specified length.
-
Field Details
-
PrintLocale
Locale used for printing decimal numbers bytoString()
methods. -
SeparationChar
Character used to separate successive vector and matrix elements bytoString()
methods. -
LeftDelimitChar
Leading delimiter used for lists of vector and matrix elements bytoString()
methods. -
RightDelimitChar
Trailing delimiter used for lists of vector and matrix elements bytoString()
methods. -
DefaultSymmetryTolerance
Default matrix symmetry tolerance.- See Also:
-
-
Method Details
-
makeDoubleMatrix
Creates and returns a
double[][]
matrix containing the specified values. Throws aIllegalArgumentException
if the number of supplied values does not exactly match the matrix size. Example for creating a 2x3 matrix:double[][] A = makeDoubleMatrix(2, 3, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 );
See also
flatten(double[][])
.- Parameters:
rows
- the number of matrix rowscols
- the number of matrix columnsvalues
- a sequence of matrix values in row-major order (may also be passed as adouble[]
)- Returns:
- a
double[][]
matrix
-
makeFloatMatrix
Creates and returns a
float[][]
matrix containing the specified values. Throws aIllegalArgumentException
if the number of supplied values does not exactly match the matrix size. Example for creating a 2x3 matrix:float[][] A = makeFloatMatrix(2, 3, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f );
See also
flatten(float[][])
.- Parameters:
rows
- the number of matrix rowscols
- the number of matrix columnsvalues
- a sequence of matrix values in row-major order (may also be passed as afloat[]
)- Returns:
- a
float[][]
matrix
-
makeRealMatrix
Creates and returns a
RealMatrix
containing the specifieddouble
values. CallsmakeDoubleMatrix(int, int, double...)
. Example for creating a 2x3 matrix:RealMatrix A = makeRealMatrix(2, 3, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 );
See also
flatten(RealMatrix)
.- Parameters:
rows
- the number of matrix rowscols
- the number of matrix columnsvalues
- a sequence of matrix values in row-major order (may also be passed as adouble[]
)- Returns:
- a
RealMatrix
-
flatten
Returns the values of the specified matrix as adouble[]
with elements arranged in row-major order. The matrix must be fully rectangular (all rows of same length). See alsomakeDoubleMatrix(int, int, double...)
.- Parameters:
A
- a matrix- Returns:
- a
double[]
with the matrix elements
-
flatten
Returns the values of the specified matrix as afloat[]
with elements arranged in row-major order. The matrix must be fully rectangular (all rows of same length). See alsomakeFloatMatrix(int, int, float...)
.- Parameters:
A
- a matrix- Returns:
- a
float[]
with the matrix elements
-
flatten
Returns the values of the specified matrix as adouble[]
with elements arranged in row-major order. See alsomakeRealMatrix(int, int, double...)
.- Parameters:
A
- a matrix- Returns:
- a
double[]
with the matrix elements
-
makeDoubleVector
Creates and returns adouble[]
vector from the specified values.- Parameters:
values
- a sequence of vector values (may also be passed as a singledouble[]
)- Returns:
- a
double[]
-
makeFloatVector
Creates and returns afloat[]
vector from the specified values.- Parameters:
values
- a sequence of vector values (may also be passed as a singlefloat[]
)- Returns:
- a
float[]
-
makeRealVector
Creates and returns aRealVector
from the specifieddouble
values.- Parameters:
values
- a sequence of vector values (may also be passed as a singledouble[]
)- Returns:
- a
RealVector
-
zeroVector
Creates and returns a new zero-valueddouble[]
vector of the specified length. Throws an exception if the length is less than 1.- Parameters:
length
- the length of the vector- Returns:
- a
double[]
with zero values
-
idMatrix
Creates and returns a new identity matrix of the specified size. Throws an exception if the size is less than 1.- Parameters:
size
- the size of the matrix- Returns:
- an identity matrix
-
getNumberOfRows
Returns the number of rows of the specifieddouble
matrix.- Parameters:
A
- adouble[][]
matrix- Returns:
- the number of rows
-
getNumberOfColumns
Returns the number of columns of the specifieddouble
matrix.- Parameters:
A
- adouble[][]
matrix- Returns:
- the number of columns
-
getNumberOfRows
Returns the number of rows of the specifiedfloat
matrix.- Parameters:
A
- afloat[][]
matrix- Returns:
- the number of rows
-
getNumberOfColumns
Returns the number of columns of the specifiedfloat
matrix.- Parameters:
A
- afloat[][]
matrix- Returns:
- the number of columns
-
getNumberOfRows
Returns the number of rows of the specifiedRealMatrix
.- Parameters:
A
- aRealMatrix
- Returns:
- the number of rows
-
getNumberOfColumns
Returns the number of columns of the specifiedRealMatrix
.- Parameters:
A
- aRealMatrix
- Returns:
- the number of columns
-
getRow
Returns a particular row of the specifieddouble
matrix as adouble
vector.- Parameters:
A
- adouble[][]
matrixr
- the row index (starting with 0)- Returns:
- a
double
vector
-
getRow
Returns a particular row of the specifiedfloat
matrix as afloat
vector.- Parameters:
A
- afloat[][]
matrixr
- the row index (starting with 0)- Returns:
- a
float
vector
-
getColumn
Returns a particular column of the specifieddouble
matrix as adouble
vector.- Parameters:
A
- adouble[][]
matrixc
- the column index (starting with 0)- Returns:
- a
double
vector
-
getColumn
Returns a particular column of the specifiedfloat
matrix as afloat
vector.- Parameters:
A
- afloat[][]
matrixc
- the column index (starting with 0)- Returns:
- a
float
vector
-
isRectangular
Checks if all rows of the given matrix have the same length.- Parameters:
A
- afloat[][]
matrix- Returns:
- true iff the matrix is rectangular
-
isRectangular
Checks if all rows of the given matrix have the same length.- Parameters:
A
- adouble[][]
matrix- Returns:
- true iff the matrix is rectangular
-
isSquare
Checks it the given matrix has the same number of rows and columns.- Parameters:
A
- adouble[][]
matrix- Returns:
- true iff the matrix is square
-
isSquare
Checks it the given matrix has the same number of rows and columns.- Parameters:
A
- afloat[][]
matrix- Returns:
- true iff the matrix is square
-
getDiagonal
Returns a vector with the diagonal elements of the specified matrix.- Parameters:
A
- a squaredouble[][]
matrix- Returns:
- the vector of diagonal elements
-
getDiagonal
Returns a vector with the diagonal elements of the specified matrix.- Parameters:
A
- a squarefloat[][]
matrix- Returns:
- the vector of diagonal elements
-
getDiagonal
Returns a vector with the diagonal elements of the specified matrix.- Parameters:
A
- a squareRealMatrix
- Returns:
- the
RealVector
of diagonal elements
-
diagMatrix
Creates and returns a diagonal matrix from the specified vector. See alsogetDiagonal(double[][])
.- Parameters:
d
- vector of diagonal matrix elements- Returns:
- a diagonal matrix
-
isSingular
Checks is the given squaredouble[][]
matrix is non-singular.- Parameters:
A
- a squaredouble[][]
matrix- Returns:
- true if the matrix is singular
- Throws:
Matrix.NonsquareMatrixException
- if the matrix is not square
-
isSingular
Checks is the given square matrix is non-singular.- Parameters:
A
- a squareRealMatrix
- Returns:
- true if the matrix is singular
- Throws:
Matrix.NonsquareMatrixException
- if the matrix is not square
-
isSymmetric
Checks is the given square matrix is symmetric using the specified relative tolerance.- Parameters:
A
- a square matrixrelTolerance
- relative symmetry tolerance- Returns:
- true if the matrix is symmetric
-
isSymmetric
Checks is the given square matrix is symmetric, using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).- Parameters:
A
- a square matrix- Returns:
- true if the matrix is symmetric
-
isSymmetric
Checks is the given square matrix is symmetric using the specified relative tolerance.- Parameters:
A
- a square matrixrelTolerance
- relative symmetry tolerance- Returns:
- true if the matrix is symmetric
-
isSymmetric
Checks is the given square matrix is symmetric, using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).- Parameters:
A
- a square matrix- Returns:
- true if the matrix is symmetric
-
isPositiveDefinite
Checks is the given square matrix is positive definite, using the specified symmetry tolerance value.- Parameters:
A
- a square matrixtolerance
- the absolute positivity and relative symmetry tolerance- Returns:
- true if the matrix is positive definite
-
isPositiveDefinite
Checks is the given square matrix is positive definite.- Parameters:
A
- a square matrix- Returns:
- true if the matrix is positive definite
-
sameSize
Checks if the given vectors have the same length.- Parameters:
a
- first vectorb
- second vector- Returns:
- true iff both vectors have the same length
-
sameSize
Checks if the given vectors have the same length.- Parameters:
a
- first vectorb
- second vector- Returns:
- true iff both vectors have the same length
-
sameSize
Checks if the given matrices have the same size.- Parameters:
A
- first matrixB
- second matrix- Returns:
- true iff both matrices have the same size
-
sameSize
Checks if the given matrices have the same size.- Parameters:
A
- first matrixB
- second matrix- Returns:
- true iff both matrices have the same size
-
duplicate
Returns a copy of the givendouble[]
vector.- Parameters:
a
- adouble[]
vector- Returns:
- a copy of the vector
-
duplicate
Returns a copy of the givenfloat[]
vector.- Parameters:
a
- afloat[]
vector- Returns:
- a copy of the vector
-
duplicate
Returns a copy of the givendouble[][]
matrix.- Parameters:
A
- adouble[][]
matrix- Returns:
- a copy of the matrix
-
duplicate
Returns a copy of the givenfloat[][]
matrix.- Parameters:
A
- afloat[][]
matrix- Returns:
- a copy of the matrix
-
copyD
Copy data from onefloat[]
vector to another. The two vectors must have the same length (not checked).- Parameters:
source
- the source vector (unmodified)target
- the target vector (modified)
-
copyD
Copy data from onedouble[]
vector to another. The two vectors must have the same length (not checked).- Parameters:
source
- the source vector (unmodified)target
- the target vector (modified)
-
toFloat
Converts adouble[]
to afloat[]
.- Parameters:
a
- the originaldouble[]
array- Returns:
- a copy of the array of type
float[]
-
toFloat
Converts adouble[][]
to afloat[][]
.- Parameters:
A
- the originaldouble[][]
array- Returns:
- a copy of the array of type
float[][]
-
toLongBits
Converts adouble[][]
to along[][]
whose elements contain the 64-bit representation of the originaldouble
values. Its printed representation is comparatively compact (seetoString(long[][])
). This is useful for defining literaldouble
arrays without losing any precision (by avoiding conversion to decimal representation). Note that thelong
are bit representations and cannot be used to perform any arithmetic calculations.- Parameters:
A
- the originaldouble
array- Returns:
- a copy of the array of type
float[][]
- See Also:
-
fromLongBits
Converts along[][]
with 64-bitdouble
representations to the equivalentdouble[][]
. This is useful for defining literaldouble
arrays without losing any precision (by avoiding conversion to decimal representation).- Parameters:
A
- along
array- Returns:
- the equivalent
double
array - See Also:
-
toDouble
Converts afloat[]
to adouble[]
.- Parameters:
a
- the originalfloat[]
array- Returns:
- a copy of the array of type
double[]
-
toDouble
Converts afloat[][]
to adouble[][]
.- Parameters:
A
- the originalfloat[][]
array- Returns:
- a copy of the array of type
double[][]
-
fillD
Fills the givendouble
vector with the specified value (destructively).- Parameters:
x
- a vector (which is modified)val
- the fill value
-
fillD
Fills the givenfloat
vector with the specified value (destructively).- Parameters:
x
- a vector (which is modified)val
- the fill value
-
fillD
Fills the givendouble
matrix with the specified value (destructively).- Parameters:
A
- a matrix (which is modified)val
- the fill value
-
fillD
Fills the givenfloat
matrix with the specified value (destructively).- Parameters:
A
- a matrix (which is modified)val
- the fill value
-
add
Calculates and returns the sum of the specifieddouble
vectors (non-destructively). An exception is thrown if the vectors are of different lengths. None of the arguments is modified.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- a new
double
vector
-
addD
Adds the elements of the firstdouble
vector to the second vector (destructively). An exception is thrown if the vectors are of different lengths. The second vector is modified.- Parameters:
a
- the first vectorb
- the second vector
-
add
Calculates and returns the sum of the specifiedfloat
vectors (non-destructively). An exception is thrown if the vectors are of different lengths. None of the arguments is modified.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- a new
float
vector
-
addD
Adds the elements of the firstfloat
vector to the second vector (destructively). An exception is thrown if the vectors are of different lengths. The second vector is modified.- Parameters:
a
- the first vectorb
- the second vector
-
add
Calculates and returns the sum of the specifieddouble
matrix (non-destructively). An exception is thrown if the matrices are of different size. None of the arguments is modified.- Parameters:
A
- the first matrixB
- the second matrix- Returns:
- a new
double
matrix
-
addD
Adds the elements of the firstdouble
matrix to the second vector (destructively). An exception is thrown if the matrices are of different size. The second matrix is modified.- Parameters:
A
- the first matrixB
- the second matrix
-
add
Calculates and returns the sum of the specifiedfloat
matrix (non-destructively). An exception is thrown if the matrices are of different size. None of the arguments is modified.- Parameters:
A
- the first matrixB
- the second matrix- Returns:
- a new
float
matrix
-
addD
Adds the elements of the firstfloat
matrix to the second vector (destructively). An exception is thrown if the matrices are of different size. The second matrix is modified.- Parameters:
A
- the first matrixB
- the second matrix
-
subtract
Calculates and returns the difference (a - b) of the specifieddouble
vectors (non-destructively). An exception is thrown if the vectors are of different lengths. None of the arguments is modified.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- a new
double
vector
-
subtract
Calculates and returns the difference (a - b) of the specifiedfloat
vectors (non-destructively). An exception is thrown if the vectors are of different lengths. None of the arguments is modified.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- a new
float
vector
-
multiply
Multiplies adouble[]
vector by a scalar and returns a newdouble[]
vector (non-destructive).- Parameters:
s
- a scalarx
- a vector- Returns:
- a new vector
-
multiplyD
Multiplies adouble[]
vector by a scalar. Destructive, i.e., the specified vector is modified.- Parameters:
s
- a scalarx
- a vector
-
multiply
Multiplies adouble[][]
matrix by a scalar and returns a newdouble[][]
matrix (non-destructive).- Parameters:
s
- a scalarA
- a matrix- Returns:
- a new matrix
-
multiplyD
Multiplies adouble[][]
matrix by a scalar. Destructive, i.e., the specified matrix is modified.- Parameters:
s
- a scalarA
- a matrix
-
multiply
Multiplies afloat[]
vector by a scalar and returns a newfloat[]
vector (non-destructive).- Parameters:
s
- a scalarx
- a vector- Returns:
- a new vector
-
multiplyD
Multiplies afloat[]
vector by a scalar. Destructive, i.e., the specified vector is modified.- Parameters:
s
- a scalarx
- a matrix
-
multiply
Multiplies afloat[][]
matrix by a scalar and returns a newfloat[][]
matrix (non-destructive).- Parameters:
s
- a scalarA
- a matrix- Returns:
- a new matrix
-
multiplyD
Multiplies afloat[][]
matrix by a scalar. Destructive, i.e., the specified matrix is modified.- Parameters:
s
- a scalarA
- a matrix
-
multiply
Multiplies a vector x with a matrix A "from the left", i.e., y = x * A, where x is treated as a row vector and the result y is also a row vector.- Parameters:
x
- a (row) vector of length mA
- a matrix of size (m,n)- Returns:
- a (row) vector of length n
-
multiplyD
Destructive version ofmultiply(double[], double[][])
.- Parameters:
x
- a (row) vector of length mA
- matrix of size (m,n)y
- a (row) vector of length n
-
multiply
Multiplies a matrix A with a vector x "from the right", i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector.- Parameters:
x
- a (column) vector of length nA
- a matrix of size (m,n)- Returns:
- a (column) vector of length m
-
multiplyD
Multiplies a matrix A with a vector x "from the right", i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector. The result is placed in the vector passed as the last argument, which is modified. Destructive version ofmultiply(double[][], double[])
. An exception is thrown if any matrix or vector dimensions do not match or if the two vectors are the same.- Parameters:
A
- matrix of size (m,n)x
- a (column) vector of length ny
- a (column) vector of length m
-
multiply
Multiplies a matrix A with a vector x from the right, i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector.- Parameters:
x
- a (column) vector of length nA
- a matrix of size (m,n)- Returns:
- a (column) vector of length m
-
multiplyD
Multiplies a matrix A with a vector x "from the right", i.e., y = A * x, where x is treated as a column vector and the result y is also a column vector. The result is placed in the vector passed as the last argument, which is modified. Destructive version ofmultiply(float[][], float[])
. An exception is thrown if any matrix or vector dimensions do not match or if the two vectors are the same.- Parameters:
A
- matrix of size (m,n)x
- a (column) vector of length ny
- a (column) vector of length m
-
multiply
Returns the product of twodouble[][]
matrices A, B as a newdouble[][]
matrix. Non-destructive, i.e., none of the arguments is modified.- Parameters:
A
- first matrixB
- second matrix- Returns:
- the matrix product A * B
-
multiplyD
public static void multiplyD(double[][] A, double[][] B, double[][] C) throws Matrix.SameSourceTargetException, Matrix.IncompatibleDimensionsException Calculates the product of twodouble[][]
matrices A, B and places the results in the thirddouble[][]
matrix C, which is modified (destructively). An exception is thrown if any matrix dimensions do not match or if the target matrix is the same as one of the source matrices.- Parameters:
A
- first matrixB
- second matrixC
- the result matrix- Throws:
Matrix.SameSourceTargetException
- if the target matrix is the same as one of the source matricesMatrix.IncompatibleDimensionsException
- if any matrix dimensions do not match
-
multiply
Returns the product of twofloat[][]
matrices A, B as a newfloat[][]
matrix. Non-destructive, i.e., none of the arguments is modified.- Parameters:
A
- first matrixB
- second matrix- Returns:
- the matrix product A * B
-
multiplyD
Calculates the product of twofloat[][]
matrices A, B and places the results in the thirdfloat[][]
matrix C, which is modified (destructively). An exception is thrown if any matrix dimensions do not match or if the target matrix is the same as one of the source matrices.- Parameters:
A
- first matrixB
- second matrixC
- the result matrix
-
dotProduct
Calculates and returns the dot (inner or scalar) product of two vectors, which must have the same length. Throws an exceptions if vector dimensions do not match.- Parameters:
a
- first vectorb
- second vector- Returns:
- the dot product
-
outerProduct
Calculates and returns the outer product of two vectors, which is a matrix of size (m,n), where m is the length of the first vector and m is the length of the second vector.- Parameters:
a
- first (column) vector (of length m)b
- second (row) vector (of length n)- Returns:
- the outer product (matrix)
-
normL1
Calculates and returns the L1 norm of the given vector.- Parameters:
a
- a vector- Returns:
- the L1 norm of the vector
-
normL1
Calculates and returns the L1 norm of the given vector.- Parameters:
a
- a vector- Returns:
- the L1 norm of the vector
-
normL2
Calculates and returns the L2 norm of the given vector.- Parameters:
a
- a vector- Returns:
- the L2 norm of the vector
-
normL2squared
Calculates and returns the squared L2 norm of the given vector. The squared norm is less costly to calculate (no square root needed) than the L2 norm and is thus often used for efficiency.- Parameters:
a
- a vector- Returns:
- the squared L2 norm of the vector
-
normL2
Calculates and returns the L2 norm of the given vector.- Parameters:
x
- a vector- Returns:
- the L2 norm of the vector
-
normL2squared
Calculates and returns the squared L2 norm of the given vector. The squared norm is less costly to calculate (no square root needed) than the L2 norm and is thus often used for efficiency.- Parameters:
a
- a vector- Returns:
- the squared L2 norm of the vector
-
normalize
Normalizes the specifieddouble[]
vector to unit (L2) norm and returns the result as a newdouble[]
vector.- Parameters:
a
- a vector- Returns:
- the normalized vector
-
normalizeD
Normalizes the specifieddouble[]
vector to unit (L2) norm. The vector is modified (destructively).- Parameters:
a
- a vector
-
normalize
Normalizes the specifiedfloat[]
vector to unit (L2) norm and returns the result as a newfloat[]
vector.- Parameters:
a
- a vector- Returns:
- the normalized vector
-
normalizeD
Normalizes the specifiedfloat[]
vector to unit (L2) norm. The vector is modified (destructively).- Parameters:
a
- a vector
-
distL2
Calculates the L2 distance between two vectors (points) in n-dimensional space. Both vectors must have the same number of elements.- Parameters:
a
- first vectorb
- second vector- Returns:
- the distance
-
distL2squared
Calculates the squared L2 distance between two vectors (points) in n-dimensional space. Both vectors must have the same number of elements.- Parameters:
a
- first vectorb
- second vector- Returns:
- the squared distance
-
distL2
Calculates the L2 distance between two vectors (points) in n-dimensional space. Both vectors must have the same number of elements.- Parameters:
a
- first vectorb
- second vector- Returns:
- the distance
-
distL2squared
Calculates the squared L2 distance between two vectors (points) in n-dimensional space. Both vectors must have the same number of elements.- Parameters:
a
- first vectorb
- second vector- Returns:
- the squared distance
-
norm
Calculates and returns the Froebenius norm of the given matrix.- Parameters:
A
- a matrix- Returns:
- the norm of the matrix
-
sum
Calculates and returns the sum of the elements in the specifieddouble[]
vector.- Parameters:
a
- a vector- Returns:
- the sum of vector elements
-
sum
Calculates and returns the sum of the elements in the specifieddouble[][]
matrix.- Parameters:
A
- a matrix- Returns:
- the sum of matrix elements
-
sum
Calculates and returns the sum of the elements in the specifiedfloat[]
vector.- Parameters:
a
- a vector- Returns:
- the sum of vector elements
-
sum
Calculates and returns the sum of the elements in the specifiedfloat[][]
matrix.- Parameters:
A
- a matrix- Returns:
- the sum of matrix elements
-
sumRow
Calculates the sum of the elements in the specified matrix row.- Parameters:
A
- a matrixrow
- the row index- Returns:
- the sum of the row's elements
-
sumRow
Calculates the sum of the elements in the specified matrix row.- Parameters:
A
- a matrixrow
- the row index- Returns:
- the sum of the row's elements
-
sumColumn
Calculates the sum of the elements in the specified matrix column.- Parameters:
A
- a matrixcol
- the column index- Returns:
- the sum of the column's elements
-
sumColumn
Calculates the sum of the elements in the specified matrix column.- Parameters:
A
- a matrixcol
- the column index- Returns:
- the sum of the column's elements
-
sumRows
Calculates the sums of all matrix rows and returns them as a vector with one element per row.- Parameters:
A
- a matrix of size (M,N)- Returns:
- a vector of length M containing the sums of all matrix columns
-
sumRows
Calculates the sums of all matrix rows and returns them as a vector with one element per row.- Parameters:
A
- a matrix of size (M,N)- Returns:
- a vector of length M containing the sums of all matrix columns
-
sumColumns
Calculates the sums of all matrix columns and returns them as a vector with one element per column.- Parameters:
A
- a matrix of size (M,N)- Returns:
- a vector of length N containing the sums of all matrix rows
-
sumColumns
Calculates the sums of all matrix columns and returns them as a vector with one element per column.- Parameters:
A
- a matrix of size (M,N)- Returns:
- a vector of length N containing the sums of all matrix rows
-
idxMin
Returns the index of the smallest element in the specified vector. If the smallest value is not unique, the lowest index is returned. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the index of the smallest value
-
idxMin
Returns the index of the smallest element in the specified vector. If the smallest value is not unique, the lowest index is returned. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the index of the smallest value
-
idxMax
Returns the index of the largest element in the specified vector. If the largest value is not unique, the lowest index is returned. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the index of the largest value
-
idxMax
Returns the index of the largest element in the specified vector. If the largest value is not unique, the lowest index is returned. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the index of the largest value
-
min
Returns the smallest value in the specified vector. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the largest value
-
min
Returns the smallest value in the specified vector. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the largest value
-
max
Returns the largest value in the specifieddouble[]
vector. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the largest value
-
max
Returns the largest value in the specifiedfloat[]
vector. An exception is thrown if the vector has zero length.- Parameters:
a
- a vector- Returns:
- the largest value
-
max
Returns the largest value in the specifieddouble[][]
matrix.- Parameters:
A
- a matrix- Returns:
- the largest matrix value
-
max
Returns the largest value in the specifiedfloat[][]
matrix.- Parameters:
A
- a matrix- Returns:
- the largest matrix value
-
join
Joins (concatenates) a sequence of vectors into a single vector.- Parameters:
as
- a sequence of vectors (at least one vector)- Returns:
- a vector containing all elements of the input vectors
-
join
Joins (concatenates) a sequence of vectors into a single vector.- Parameters:
as
- a sequence of vectors (at least one vector)- Returns:
- a vector containing all elements of the input vectors
-
lerp
Performs linear interpolation between two vectorsa
andb
, which must have the same length. Returns a new vectorc = a + t * (b - a)
.- Parameters:
a
- first vector (to be interpolated from)b
- second vector (to be interpolated to)t
- interpolation coefficient, expected to be in [0,1]- Returns:
- the interpolated vector
-
lerp
Performs linear interpolation between two vectorsa
andb
, which must have the same length. Returns a new vectorc = a + t * (b - a)
.- Parameters:
a
- first vector (to be interpolated from)b
- second vector (to be interpolated to)t
- interpolation coefficient, expected to be in [0,1]- Returns:
- the interpolated vector
-
toHomogeneous
Converts a Cartesian vector to an equivalent homogeneous vector by attaching an additional 1-element. The resulting homogeneous vector is one element longer than the specified Cartesian vector. See alsotoCartesian(double[])
.- Parameters:
ac
- a Cartesian vector- Returns:
- an equivalent homogeneous vector
-
toCartesian
Converts a homogeneous vector to its equivalent Cartesian vector, which is one element shorter. See alsotoHomogeneous(double[])
.- Parameters:
ah
- a homogeneous vector- Returns:
- the equivalent Cartesian vector
- Throws:
DivideByZeroException
- if the last vector element is zero
-
determinant
Calculates and returns the determinant of the givenRealMatrix
. Throws an exception if the matrix is non-square.- Parameters:
A
- a square matrix- Returns:
- the determinant
-
determinant
Calculates and returns the determinant of the givendouble[][]
matrix. Throws an exception if the matrix is non-square.- Parameters:
A
- a square matrix- Returns:
- the determinant
-
determinant2x2
Calculates and returns the determinant of the given 2x2double[][]
matrix. This method is hard-coded for the specific matrix size for better performance than the general method (determinant(double[][])
). Throws an exception if the matrix is not 2x2.- Parameters:
A
- a 2x2 matrix- Returns:
- the determinant
-
determinant2x2
Calculates and returns the determinant of the given 2x2float[][]
matrix. Throws an exception if the matrix is not 2x2.- Parameters:
A
- a 2x2 matrix- Returns:
- the determinant
-
determinant3x3
Calculates and returns the determinant of the given 3x3double[][]
matrix. This method is hard-coded for the specific matrix size for better performance than the general method (determinant(double[][])
). Throws an exception if the matrix is not 3x3.- Parameters:
A
- a 3x3 matrix- Returns:
- the determinant
-
determinant3x3
Calculates and returns the determinant of the given 3x3float[][]
matrix. Throws an exception if the matrix is not 3x3.- Parameters:
A
- a 3x3 matrix- Returns:
- the determinant
-
trace
Calculates and returns the trace of the givendouble[][]
matrix. Throws an exception if the matrix is non-square.- Parameters:
A
- a square matrix- Returns:
- the trace
-
trace
Calculates and returns the trace of the givenfloat[][]
matrix. Throws an exception if the matrix is non-square.- Parameters:
A
- a square matrix- Returns:
- the trace
-
transpose
Returns the transpose of the givendouble[][]
matrix. The original matrix is not modified.- Parameters:
A
- a matrix- Returns:
- the transpose of the matrix
-
transpose
Returns the transpose of the givenfloat[][]
matrix. The original matrix is not modified.- Parameters:
A
- a matrix- Returns:
- the transpose of the matrix
-
isZero
Checks if all elements of the specifieddouble[]
vector are zero using the specified tolerance value.- Parameters:
a
- a vectortolerance
- the tolerance value- Returns:
- true if all vector elements are smaller than the tolerance
-
isZero
Checks if all elements of the specifieddouble[]
vector are zero using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).- Parameters:
a
- a vector- Returns:
- true if all vector elements are smaller than the tolerance
-
isZero
Checks if all elements of the specifiedfloat[]
vector are zero using the specified tolerance value.- Parameters:
a
- a vectortolerance
- the tolerance value- Returns:
- true if all vector elements are smaller than the tolerance
-
isZero
Checks if all elements of the specifiedfloat[]
vector are zero using the default tolerance value (Arithmetic.EPSILON_DOUBLE
).- Parameters:
a
- a vector- Returns:
- true if all vector elements are smaller than the tolerance
-
isZero
Checks if all elements of the specifieddouble[][]
matrix are zero using the specified tolerance value.- Parameters:
A
- a matrixtolerance
- the tolerance value- Returns:
- true if all matrix elements are smaller than the tolerance
-
isZero
Checks if all elements of the specifieddouble[][]
matrix are zero using default tolerance value (Arithmetic.EPSILON_DOUBLE
).- Parameters:
A
- a matrix- Returns:
- true if all matrix elements are smaller than the tolerance
-
sort
Returns a sorted copy of the givendouble[]
vector. Elements are sorted by increasing value (smallest first).- Parameters:
a
- adouble[]
vector- Returns:
- a sorted copy of the vector
-
sort
Returns a sorted copy of the givenfloat[]
vector. Elements are sorted by increasing value (smallest first).- Parameters:
a
- afloat[]
vector- Returns:
- a sorted copy of the vector
-
inverse
Calculates and returns the inverse of the given matrix, which must be square. Exceptions are thrown if the supplied matrix is not square or ill-conditioned (singular).- Parameters:
A
- a square matrix- Returns:
- the inverse matrix
- Throws:
Matrix.NonsquareMatrixException
- if the supplied matrix is not square
-
inverse
Calculates and returns the inverse of the given matrix, which must be square. Exceptions are thrown if the supplied matrix is not square or ill-conditioned (singular).- Parameters:
A
- a square matrix- Returns:
- the inverse matrix
- Throws:
Matrix.NonsquareMatrixException
- if the supplied matrix is not square
-
solve
Finds the exact solution x for the linear system of equations A * x = b. Returns the solution vector x ornull
if the supplied matrix is ill-conditioned (i.e., singular). Exceptions are thrown if A is not square or dimensions are incompatible. Callssolve(RealMatrix, RealVector)
.- Parameters:
A
- a square matrix of size n x nb
- a vector of length n- Returns:
- the solution vector (x) of length n or
null
if no solution possible
-
solve
Finds the exact solution x for the linear system of equations A * x = b. Returns the solution vector x ornull
if the supplied matrix is ill-conditioned (i.e., singular). Exceptions are thrown if A is not square or dimensions are incompatible. UsesLUDecomposition
from the Apache Commons Math library.- Parameters:
A
- a square matrix of size n x nb
- a vector of length n- Returns:
- the solution vector (x) of length n or
null
if no solution possible
-
toString
Returns a string representation of the specified vector.- Parameters:
a
- a vector- Returns:
- the string representation
-
toString
Returns a string representation of the specified vector.- Parameters:
a
- a vector- Returns:
- the string representation
-
toString
Returns a string representation of the specified vector.- Parameters:
a
- a vector- Returns:
- the string representation
-
toString
Returns a string representation of the specified matrix.- Parameters:
A
- a matrix- Returns:
- the string representation
-
toString
Returns a string representation of the specified matrix.- Parameters:
A
- a matrix- Returns:
- the string representation
-
toString
Returns a string representation of the specified matrix withlong
elements.- Parameters:
A
- a matrix- Returns:
- the string representation
-
toString
Returns a string representation of the specified matrix.- Parameters:
A
- a matrix- Returns:
- the string representation
-
printToStream
Outputs a string representation of the given vector to the specified output stream.- Parameters:
a
- the vectorstrm
- the output stream- See Also:
-
printToStream
Outputs a string representation of the given matrix to the specified output stream.- Parameters:
A
- the matrixstrm
- the output stream- See Also:
-
printToStream
Outputs a string representation of the given vector to the specified output stream.- Parameters:
a
- the vectorstrm
- the output stream- See Also:
-
printToStream
Outputs a string representation of the given matrix to the specified output stream.- Parameters:
A
- the matrixstrm
- the output stream- See Also:
-
printToStream
-