math.utils
Class Matrix
- java.lang.Object
-
- math.utils.Matrix
-
public class Matrix extends java.lang.Objectclass Matrix
-
-
Field Summary
Fields Modifier and Type Field and Description static doubletoleranceThe tolerance used for solving linear equations.
-
Constructor Summary
Constructors Constructor and Description Matrix()Constructs a new Matrix, with 1 row and 1 column, initialized to 1.Matrix(double[][] coef)Constructs a new Matrix, initialized with the given coefficients.Matrix(int nbRows, int nbCols)Initializes a new Matrix with the given number of rows and columns.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublegetCoef(int row, int col)Returns the coef.intgetColumns()Returns the number of columns.intgetRows()Returns the number of rows.MatrixgetTranspose()Returns the transposed matrix, without changing the inner coefficients of the original matrix.booleanisSquare()Returns true if the matrix is square, i.e.double[]multiplyWith(double[] coefs)Returns the result of the multiplication of the matrix with the given vector.double[]multiplyWith(double[] src, double[] res)Returns the result of the multiplication of the matrix with the given vector.MatrixmultiplyWith(Matrix matrix)Returns the result of the multiplication of the matrix with another one.voidsetCoef(int row, int col, double coef)Sets the coef to the given value.voidsetToIdentity()Fills the matrix with zeros everywhere, except on the main diagonal, filled with ones.double[]solve(double[] vector)Computes the solution of a linear system, using the Gauss-Jordan algorithm.java.lang.StringtoString()Returns a String representation of the elements of the Matrixvoidtranspose()Transposes the matrix, changing the inner coefficients.
-
-
-
Field Detail
-
tolerance
public static double tolerance
The tolerance used for solving linear equations. Equal to 1e-14 by default.
-
-
Constructor Detail
-
Matrix
public Matrix()
Constructs a new Matrix, with 1 row and 1 column, initialized to 1.
-
Matrix
public Matrix(int nbRows, int nbCols)Initializes a new Matrix with the given number of rows and columns.
-
Matrix
public Matrix(double[][] coef)
Constructs a new Matrix, initialized with the given coefficients.
-
-
Method Detail
-
getCoef
public double getCoef(int row, int col)Returns the coef. row and col are between 1 and the number of rows and columns.
-
getRows
public int getRows()
Returns the number of rows.
-
getColumns
public int getColumns()
Returns the number of columns.
-
isSquare
public boolean isSquare()
Returns true if the matrix is square, i.e. the number of rows equals the number of columns.
-
setCoef
public void setCoef(int row, int col, double coef)Sets the coef to the given value. row and col are between 1 and the number of rows and columns.
-
multiplyWith
public Matrix multiplyWith(Matrix matrix)
Returns the result of the multiplication of the matrix with another one. The content of the matrix is not modified.- Throws:
java.lang.IllegalArgumentException- if the size of matrices do not match
-
multiplyWith
public double[] multiplyWith(double[] coefs)
Returns the result of the multiplication of the matrix with the given vector. The content of the matrix is not modified.- Throws:
java.lang.NullPointerException- if input array is nulljava.lang.IllegalArgumentException- if size of vector and of matrix do not match
-
multiplyWith
public double[] multiplyWith(double[] src, double[] res)Returns the result of the multiplication of the matrix with the given vector. The content of the matrix is not modified.- Throws:
java.lang.NullPointerException- if input vector is nulljava.lang.IllegalArgumentException- if size of vector and of matrix do not match
-
transpose
public void transpose()
Transposes the matrix, changing the inner coefficients.
-
getTranspose
public Matrix getTranspose()
Returns the transposed matrix, without changing the inner coefficients of the original matrix.
-
solve
public double[] solve(double[] vector)
Computes the solution of a linear system, using the Gauss-Jordan algorithm. The inner coefficients of the matrix are not modified.- Throws:
java.lang.NullPointerException- if input vector is nulljava.lang.IllegalArgumentException- if size of vector and of matrix do not matchjava.lang.UnsupportedOperationException- if the matrix is not squarejava.lang.ArithmeticException- if the algorithm could not find pivot greater than tolerance
-
setToIdentity
public void setToIdentity()
Fills the matrix with zeros everywhere, except on the main diagonal, filled with ones.
-
toString
public java.lang.String toString()
Returns a String representation of the elements of the Matrix- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG