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.
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
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungAdds the given matrix to the currentMatrix.appendAtBottom(double rowValue, double... rowValues) Appends a new row with the given row values on the bottom of the currentMatrix.appendAtRight(Matrix matrix) Appends the given matrix at the right of the currentMatrix.static MatrixcreateIdendityMatrixWithLength(int length) static MatrixcreateQuadraticMatrixWithOnesAndLength(int length) The values of the createdMatrixwill be all 1.0static MatrixcreateRandomQuadraticMatrixWithLength(int length) The values of the createdMatrixwill be all a whole random number in [0, 99].static MatrixcreateRandomQuadraticMatrixWithRowCountAndColumnCount(int rowCount, int columnCount) The values of the createdMatrixwill be all a whole random number in [0, 99].booleangetClone()intVector[]getMatrixWithFirstColumns(int columnCount) getMatrixWithLastColumns(int columnCount) getMinimalFactorMatrix(Matrix solutionMatrix) This method implements the least squares algorithm.getProduct(Matrix matrix) intgetRank()intVector[]intgetSize()double[]doublegetTrace()doublegetValue(int rowIndex, int columnIndex) inthashCode()booleanhasSameSize(Matrix matrix) booleanbooleanbooleanmultiply(double factor) Multiplies the currentMatrixwith 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 currentMatrixusing an epsilonsetAllValuesTo(double value) Sets the values of the currentMatrixto the given value.setDiagonalValuesTo(double value) Sets the diagonal values of the currentMatrixto 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 currentMatrixto an identity matrix.Transforms the currentMatrixto an equivalent upper left matrix.Transposes the currentMatrix.static MatrixwithOnesAndRowCountAndColumnCount(int rowCount, int columnCount) The values of the createdMatrixwill be all 1.0static MatrixwithRowCountAndColumnCount(int rowCount, int columnCount)
-
Konstruktordetails
-
Matrix
public Matrix(int rowCount, int columnCount, double value) Creates a newMatrixwith 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
-
createIdendityMatrixWithLength
- Parameter:
length-- Gibt zurück:
- a new identity
Matrixwith the given length. - Löst aus:
NonPositiveArgumentException- if the given length is not positive.
-
createQuadraticMatrixWithOnesAndLength
The values of the createdMatrixwill be all 1.0- Parameter:
length-- Gibt zurück:
- a new
Matrixwith the given length. - Löst aus:
NonPositiveArgumentException- if the given length is not positive.
-
createRandomQuadraticMatrixWithLength
The values of the createdMatrixwill be all a whole random number in [0, 99].- Parameter:
length-- Gibt zurück:
- a new
Matrixwith the given length.
-
createRandomQuadraticMatrixWithRowCountAndColumnCount
public static Matrix createRandomQuadraticMatrixWithRowCountAndColumnCount(int rowCount, int columnCount) The values of the createdMatrixwill be all a whole random number in [0, 99].- Parameter:
rowCount-columnCount-- Gibt zurück:
- a new
Matrixwith 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.
-
withOnesAndRowCountAndColumnCount
The values of the createdMatrixwill be all 1.0- Parameter:
rowCount-columnCount-- Gibt zurück:
- a new
Matrixwith 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.
-
withRowCountAndColumnCount
- Parameter:
rowCount-columnCount-- Gibt zurück:
- a new
Matrixwith the given rowCount and columnCount. - 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.
-
appendAtBottom
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
-
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 currentMatrixis 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
Matrixand the given matrix. - Löst aus:
UnequalArgumentException- if the given matrix has not as many rows as the currentMatrixcolumns has.
-
getPseudoInverse
- Gibt zurück:
- a pseudo inverse matrix of the current
Matrix. - Löst aus:
InvalidArgumentException- if the currentMatrixis not quadratic.
-
getRank
public int getRank()- Gibt zurück:
- the rank of the current
Matrix. - Löst aus:
InvalidArgumentException- if the currentMatrixis 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
Matrixis an extended matrix of a linear equation system
-
getSum
- Parameter:
matrix-- Gibt zurück:
- the matrix that is the sum of the current
Matrixand 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 currentMatrixis 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 currentMatrixdoes not contain a row with the given row index.ArgumentIsOutOfRangeException- if the currentMatrixdoes not contain a column with the given column index.
-
hashCode
public int hashCode() -
hasSameSize
- Parameter:
matrix-- Gibt zurück:
- true if the current
Matrixhas the same size as the given matrix
-
isIdentityMatrix
public boolean isIdentityMatrix()- Gibt zurück:
- true if the current
Matrixis an identity matrix
-
isQuadratic
public boolean isQuadratic()- Gibt zurück:
- true if the current
Matrixis a quadratic matrix
-
isRegular
public boolean isRegular()- Gibt zurück:
- true if the current
Matrixis regular
-
multiply
Multiplies the currentMatrixwith 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 currentMatrixdoes not contain a row with the given row index.
-
removeZeroRows
Removes the zero rows of the currentMatrixusing an epsilon- Gibt zurück:
- the current
Matrix
-
setAllValuesTo
Sets the values of the currentMatrixto 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 currentMatrixdoes not contain a row with the given row index.ArgumentIsOutOfRangeException- if the currentMatrixdoes 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 currentMatrixcontains.
-
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 currentMatrixcontains.
-
setDiagonalValuesTo
Sets the diagonal values of the currentMatrixto the given value.- Parameter:
value-- Gibt zurück:
- the current
Matrix - Löst aus:
InvalidArgumentException- if the currentMatrixis 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 currentMatrixdoes not have a row with the given row1 index.ArgumentIsOutOfRangeException- if the currentMatrixdoes 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 currentMatrixdoes not represent aPolynom.
-
toVector
- Gibt zurück:
- a vector representation of the current
Matrix - Löst aus:
UnrepresentingArgumentException- if the currentMatrixdoes not represent aVector.
-
tranformFirstPartToIdentityMatrix
Transforms the first part of the currentMatrixto an identity matrix.- Gibt zurück:
- the current
Matrix - Löst aus:
InvalidArgumentException- if the currentMatrixhas more rows than columns.InvalidArgumentException- if the currentMatrixhas linear depending rows.
-
transformToEquivalentUpperLeftMatrix
Transforms the currentMatrixto an equivalent upper left matrix.- Gibt zurück:
- the current
Matrix
-
toString
-
transpose
Transposes the currentMatrix.- Gibt zurück:
- the current
Matrix
-