Package ch.nolix.core.math.algebra
Klasse Matrix
java.lang.Object
ch.nolix.core.math.algebra.Matrix
A
Matrix
represents a mathematical matrix of doubles. A
Matrix
has at least 1 row and 1 column.
All comparisons a Matrix
does are approximative. For example: -The
second row of the matrix [4, 5; 0.000000001, 0] is interpreted as a zero row.
-The matrix [0.9999999999, 0; 0, 1] is interpreted as a identity matrix.- Version:
- 2016-02-01
- Autor:
- Silvan Wyss
-
Konstruktorübersicht
KonstruktorBeschreibungMatrix
(int size) Creates a newMatrix
with the given size.Matrix
(int rowCount, int columnCount) Creates a newMatrix
with the given number of rows and the given number of columns.Matrix
(int rowCount, int columnCount, double value) Creates a newMatrix
with the given number of rows and columns. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungAdds the given matrix to the currentMatrix
.appendAtRight
(Matrix matrix) Appends the given matrix at the right of the currentMatrix
.appendRowAtBottom
(double rowValue, double... rowValues) Appends a new row with the given row values on the bottom of the currentMatrix
.static Matrix
createIdendityMatrix
(int size) static Matrix
createMatrixOfOnes
(int size) The values of the createdMatrix
will be all 1.0static Matrix
createMatrixOfOnes
(int rowCount, int columnCount) The values of the createdMatrix
will be all 1.0static Matrix
createRandomMatrix
(int size) The values of the createdMatrix
will be all a whole random number in [0, 99].static Matrix
createRandomMatrix
(int rowCount, int columnCount) The values of the createdMatrix
will be all a whole random number in [0, 99].boolean
boolean
equalsApproximatively
(Matrix matrix, double epsilon) getClone()
int
Vector[]
getMatrixWithFirstColumns
(int columnCount) getMatrixWithLastColumns
(int columnCount) getMinimalFactorMatrix
(Matrix solutionMatrix) This method implements the least squares algorithm.getProduct
(Matrix matrix) int
getRank()
int
Vector[]
int
getSize()
double[]
double
getTrace()
double
getValue
(int rowIndex, int columnIndex) int
hashCode()
boolean
hasSameSize
(Matrix matrix) boolean
boolean
boolean
multiply
(double factor) Multiplies the currentMatrix
with the given factor.multiplyRow
(int rowIndex, double factor) Multiplies the row with the given row index with the given factor.Removes the zero rows of the currentMatrix
using an epsilonsetAllValuesTo
(double value) Sets the values of the currentMatrix
to the given value.setDiagonalValuesTo
(double value) Sets the diagonal values of the currentMatrix
to the given value.setValue
(int rowIndex, int columnIndex, double value) Sets the value in the row with the given row index and the column with the given column index.setValues
(double[] values) Sets the values of the currentMatrix
.setValues
(double value, double... values) Sets the values of the currentMatrix
.swapRows
(int row1Index, int row2Index) Swaps the rows with the given indexes.toString()
toVector()
Transforms the first part of the currentMatrix
to an identity matrix.Transforms the currentMatrix
to an equivalent upper left matrix.Transposes the currentMatrix
.
-
Konstruktordetails
-
Matrix
public Matrix(int size) - Parameter:
size
-- Löst aus:
NonPositiveArgumentException
- if the given size is not positive.
-
Matrix
public Matrix(int rowCount, int columnCount) Creates a newMatrix
with the given number of rows and the given number of columns.- Parameter:
rowCount
-columnCount
-- Löst aus:
NonPositiveArgumentException
- if the given row count is not positive.NonPositiveArgumentException
- if the given column count is not positive.
-
Matrix
public Matrix(int rowCount, int columnCount, double value) Creates a newMatrix
with the given number of rows and columns. The values of the matrix will be all set to the given value.- Parameter:
rowCount
-columnCount
-value
-- Löst aus:
NonPositiveArgumentException
- if the given rowCount is not positive.NonPositiveArgumentException
- if the given columnCount is not positive.
-
-
Methodendetails
-
createIdendityMatrix
- Parameter:
size
-- Gibt zurück:
- a new identity
Matrix
with the given size. - Löst aus:
NonPositiveArgumentException
- if the given size is not positive.
-
createMatrixOfOnes
The values of the createdMatrix
will be all 1.0- Parameter:
size
-- Gibt zurück:
- a new
Matrix
with the given size. - Löst aus:
NonPositiveArgumentException
- if the given size is not positive.
-
createMatrixOfOnes
The values of the createdMatrix
will be all 1.0- Parameter:
rowCount
-columnCount
-- Gibt zurück:
- a new
Matrix
with the given number of rows and the given number of columns. - Löst aus:
NonPositiveArgumentException
- if the given rowCount is not positive.NonPositiveArgumentException
- if the given columnCount is not positive.
-
createRandomMatrix
The values of the createdMatrix
will be all a whole random number in [0, 99].- Parameter:
size
-- Gibt zurück:
- a new
Matrix
with the given size.
-
createRandomMatrix
The values of the createdMatrix
will be all a whole random number in [0, 99].- Parameter:
rowCount
-columnCount
-- Gibt zurück:
- a new
Matrix
with the given number of rows and the given number of columns. - Löst aus:
NonPositiveArgumentException
- if the given rowCount is not positive.NonPositiveArgumentException
- if the given columnCount is not positive.
-
add
Adds the given matrix to the currentMatrix
.- Parameter:
matrix
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
UnequalArgumentException
- if the given matrix has not as many rows as the currentMatrix
.UnequalArgumentException
- if the given matrix has not as many columns as the currentMatrix
.
-
appendAtRight
Appends the given matrix at the right of the currentMatrix
.- Parameter:
matrix
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
UnequalArgumentException
- if the given matrix has not as many rows as the currentMatrix
.
-
appendRowAtBottom
Appends a new row with the given row values on the bottom of the currentMatrix
.- Parameter:
rowValue
-rowValues
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
InvalidArgumentException
- if not as many row values are given than the number of columns of the currentMatrix
.
-
equals
-
equalsApproximatively
- Parameter:
matrix
-epsilon
-- Gibt zurück:
- true if the current
Matrix
equals the given matrix with a deviation, that is smaller than the given epsilon.
-
getColumnCount
public int getColumnCount()- Gibt zurück:
- the number of columns of the current
Matrix
-
getClone
- Gibt zurück:
- a clone of the current
Matrix
-
getColumnVectors
- Gibt zurück:
- the column vectors of the current
Matrix
-
getInverse
- Gibt zurück:
- the inverse matrix of the current
Matrix
. - Löst aus:
InvalidArgumentException
- if the currentMatrix
is not regular.
-
getMatrixWithFirstColumns
- Parameter:
columnCount
-- Gibt zurück:
- a matrix with the first columns of the current
Matrix
. - Löst aus:
ArgumentIsOutOfRangeException
- if the given column count is not valid.
-
getMatrixWithLastColumns
- Parameter:
columnCount
-- Gibt zurück:
- a matrix with the last columns of the current
Matrix
. - Löst aus:
ArgumentIsOutOfRangeException
- if the given column count is not valid.
-
getMinimalFactorMatrix
This method implements the least squares algorithm.- Parameter:
solutionMatrix
-- Gibt zurück:
- a matrix A so that the matrix X*A-Y is minimal. -X is the current
Matrix
. -Y is the given solution matrix. The following formula is used: A = (X_t*X)^-1*X_t*Y. - Löst aus:
UnequalArgumentException
- if the given solution matrix has not 1 column.UnequalArgumentException
- if the given solution matrix has not as many rows as the currentMatrix
.
-
getProduct
- Parameter:
matrix
-- Gibt zurück:
- the product of the current
Matrix
and the given matrix. - Löst aus:
UnequalArgumentException
- if the given matrix has not as many rows as the currentMatrix
columns has.
-
getPseudoInverse
- Gibt zurück:
- a pseudo inverse matrix of the current
Matrix
. - Löst aus:
InvalidArgumentException
- if the currentMatrix
is not quadratic.
-
getRank
public int getRank()- Gibt zurück:
- the rank of the current
Matrix
. - Löst aus:
InvalidArgumentException
- if the currentMatrix
is not quadratic.
-
getRowCount
public int getRowCount()- Gibt zurück:
- the number of rows of the current
Matrix
-
getRowVectors
- Gibt zurück:
- the row vectors of the current
Matrix
-
getSize
public int getSize()- Gibt zurück:
- the size of the current
Matrix
-
getSolutionAsExtendedMatrix
public double[] getSolutionAsExtendedMatrix()- Gibt zurück:
- the solution when the current
Matrix
is an extended matrix of a linear equation system
-
getSum
- Parameter:
matrix
-- Gibt zurück:
- the matrix that is the sum of the current
Matrix
and the given matrix - Löst aus:
UnequalArgumentException
- if the given matrix has not the same size as the currentMatrix
-
getTransposed
- Gibt zurück:
- the transposed matrix of the current
Matrix
.
-
getTrace
public double getTrace()- Gibt zurück:
- the trace of the current
Matrix
. - Löst aus:
InvalidArgumentException
- if the currentMatrix
is not quadratic.
-
getValue
public double getValue(int rowIndex, int columnIndex) - Parameter:
rowIndex
-columnIndex
-- Gibt zurück:
- the value in the row with the given row index and the column with the given column index.
- Löst aus:
ArgumentIsOutOfRangeException
- if the currentMatrix
does not contain a row with the given row index.ArgumentIsOutOfRangeException
- if the currentMatrix
does not contain a column with the given column index.
-
hashCode
public int hashCode() -
hasSameSize
- Parameter:
matrix
-- Gibt zurück:
- true if the current
Matrix
has the same size as the given matrix
-
isIdentityMatrix
public boolean isIdentityMatrix()- Gibt zurück:
- true if the current
Matrix
is an identity matrix
-
isQuadratic
public boolean isQuadratic()- Gibt zurück:
- true if the current
Matrix
is a quadratic matrix
-
isRegular
public boolean isRegular()- Gibt zurück:
- true if the current
Matrix
is regular
-
multiply
Multiplies the currentMatrix
with the given factor.- Parameter:
factor
-- Gibt zurück:
- the current
Matrix
-
multiplyRow
Multiplies the row with the given row index with the given factor.- Parameter:
rowIndex
-factor
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
ArgumentIsOutOfRangeException
- if the currentMatrix
does not contain a row with the given row index.
-
removeZeroRows
Removes the zero rows of the currentMatrix
using an epsilon- Gibt zurück:
- the current
Matrix
-
setAllValuesTo
Sets the values of the currentMatrix
to the given value.- Parameter:
value
-- Gibt zurück:
- the current
Matrix
-
setValue
Sets the value in the row with the given row index and the column with the given column index.- Parameter:
rowIndex
-columnIndex
-value
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
ArgumentIsOutOfRangeException
- if the currentMatrix
does not contain a row with the given row index.ArgumentIsOutOfRangeException
- if the currentMatrix
does not contain a column with the given column index.
-
setValues
Sets the values of the currentMatrix
.- Parameter:
value
-values
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
InvalidArgumentException
- if not as many values are given as the currentMatrix
contains.
-
setValues
Sets the values of the currentMatrix
.- Parameter:
values
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
InvalidArgumentException
- if not as many values are given as the currentMatrix
contains.
-
setDiagonalValuesTo
Sets the diagonal values of the currentMatrix
to the given value.- Parameter:
value
-- Gibt zurück:
- the current
Matrix
- Löst aus:
InvalidArgumentException
- if the currentMatrix
is not quadratic
-
swapRows
Swaps the rows with the given indexes.- Parameter:
row1Index
-row2Index
-- Gibt zurück:
- the current
Matrix
. - Löst aus:
ArgumentIsOutOfRangeException
- if the currentMatrix
does not have a row with the given row1 index.ArgumentIsOutOfRangeException
- if the currentMatrix
does not have a row with the given row1 index.
-
toPolynom
- Gibt zurück:
- a polynom representation of the current
Matrix
- Löst aus:
UnrepresentingArgumentException
- if the currentMatrix
does not represent aPolynom
.
-
toVector
- Gibt zurück:
- a vector representation of the current
Matrix
- Löst aus:
UnrepresentingArgumentException
- if the currentMatrix
does not represent aVector
.
-
tranformFirstPartToIdentityMatrix
Transforms the first part of the currentMatrix
to an identity matrix.- Gibt zurück:
- the current
Matrix
- Löst aus:
InvalidArgumentException
- if the currentMatrix
has more rows than columns.InvalidArgumentException
- if the currentMatrix
has linear depending rows.
-
transformToEquivalentUpperLeftMatrix
Transforms the currentMatrix
to an equivalent upper left matrix.- Gibt zurück:
- the current
Matrix
-
toString
-
transpose
Transposes the currentMatrix
.- Gibt zurück:
- the current
Matrix
-