Class Matrix
- java.lang.Object
-
- Matrix
-
public class Matrix extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Matrix(double[][] mat)Creates a matrix from a bidimensional arrayMatrix(java.io.InputStream is)Creates a matrix from an InputStream in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns.Matrix(java.io.Reader r)Creates a matrix from a Reader in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns.Matrix(Matrix toCopy)Creates a matrix from another Matrix
-
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object mi)Tells if an Object is equal to this MatrixintgetColumnsNumber()Returns the number of columns of this Matrixdouble[][]getMatrix()Gets the bidimensional array representing this MatrixintgetRowsNumber()Returns the number of rows of this Matrixstatic double[][]identity(int n)Returns a bidimensional array containing an identity matrixstatic booleanisRect(double[][] m)Tells if a bidimensional array is a rectanglevoidload(java.io.InputStream is)Loads a matrix from an InputStream in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns.voidload(java.io.Reader r)Loads a matrix from an InputStream in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns.static voidmain(java.lang.String[] ar)static double[][]nullMatrix(int n)Returns a bidimensional array containing a zero matrixstatic Matrixone(int n)Returns the identity Matrixintorder()Returns the order of this Matrix if it is a square matrixstatic double[][]pow(double[][] m, int n)Returns the n-th power of a bidimensional array.Matrixpow(int n)Returns the Matrix that n-th power of this Matrixstatic double[][]prod(double[][] m1, double[][] m2)Returns the cartesian product of two bidimensional arrays.Matrixprod(Matrix mat)Returns the Matrix that is the cartesian product of this Matrix with another Matrixstatic double[][]sum(double[][] m1, double[][] m2)Returns the sum of two bidimensional arrays.Matrixsum(Matrix mat)Returns the Matrix that is the sum of this Matrix with another Matrixjava.lang.StringtoString()Returns a String representing this Matrixdoublevalue(int i, int j)Gets the value of this Matrix at the given coordinatesstatic Matrixzero(int n)Returns the zero Matrix
-
-
-
Constructor Detail
-
Matrix
public Matrix(Matrix toCopy)
Creates a matrix from another Matrix- Parameters:
toCopy- the Matrix to copy
-
Matrix
public Matrix(double[][] mat)
Creates a matrix from a bidimensional array- Parameters:
mat- the bidimensional array
-
Matrix
public Matrix(java.io.InputStream is)
Creates a matrix from an InputStream in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns. The following rows*columnes double values are the values of the Matrix- Parameters:
is- the InputStream
-
Matrix
public Matrix(java.io.Reader r)
Creates a matrix from a Reader in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns. The following rows*columnes double values are the values of the Matrix- Parameters:
r- the Reader
-
-
Method Detail
-
load
public void load(java.io.InputStream is)
Loads a matrix from an InputStream in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns. The following rows*columnes double values are the values of the Matrix- Parameters:
is- the InputStream
-
load
public void load(java.io.Reader r)
Loads a matrix from an InputStream in which the first integer value is the number of rows of the Matrix and the second integer value is the number of columns. The following rows*columnes double values are the values of the Matrix- Parameters:
r- the Reader
-
sum
public Matrix sum(Matrix mat)
Returns the Matrix that is the sum of this Matrix with another Matrix- Parameters:
mat- the Matrix to sum- Returns:
- the resulting sum Matrix
-
sum
public static double[][] sum(double[][] m1, double[][] m2)Returns the sum of two bidimensional arrays.- Parameters:
m1- the first bidimensional arraym2- the second bidimensional array- Returns:
- the bidimensional array that is the sum of m1 and m2
-
isRect
public static boolean isRect(double[][] m)
Tells if a bidimensional array is a rectangle- Parameters:
m- the bidimensional array- Returns:
- true if the array is a rectangle, false otherwise
-
prod
public Matrix prod(Matrix mat)
Returns the Matrix that is the cartesian product of this Matrix with another Matrix- Parameters:
mat- the Matrix to make the product with- Returns:
- the resulting cartesian product Matrix
-
prod
public static double[][] prod(double[][] m1, double[][] m2)Returns the cartesian product of two bidimensional arrays.- Parameters:
m1- the first bidimensional arraym2- the second bidimensional array- Returns:
- the bidimensional array that is the cartesian product of m1 and m2
-
pow
public Matrix pow(int n)
Returns the Matrix that n-th power of this Matrix- Parameters:
n- the esponent of the power- Returns:
- the resulting power Matrix
-
pow
public static double[][] pow(double[][] m, int n)Returns the n-th power of a bidimensional array.- Parameters:
m- the first bidimensional arrayn- the esponent of the power- Returns:
- the bidimensional array that is the elevation of m to the n-th power
-
getRowsNumber
public int getRowsNumber()
Returns the number of rows of this Matrix- Returns:
- the number of rows
-
getColumnsNumber
public int getColumnsNumber()
Returns the number of columns of this Matrix- Returns:
- the number of columns
-
order
public int order()
Returns the order of this Matrix if it is a square matrix- Returns:
- the order of this Matrix if it is a square matrix, -1 otherwise
-
value
public double value(int i, int j)Gets the value of this Matrix at the given coordinates- Parameters:
i- the row indexj- the column index- Returns:
- the value at the given coordinates if they are correct, NaN otherwise
-
getMatrix
public double[][] getMatrix()
Gets the bidimensional array representing this Matrix- Returns:
- the bidimensional array
-
one
public static Matrix one(int n)
Returns the identity Matrix- Parameters:
n- the order of the identity Matrix- Returns:
- the identity Matrix
-
identity
public static double[][] identity(int n)
Returns a bidimensional array containing an identity matrix- Parameters:
n- the order of the identity matrix- Returns:
- the identity matrix bidimensional array
-
zero
public static Matrix zero(int n)
Returns the zero Matrix- Parameters:
n- the order of the zero Matrix- Returns:
- the zero Matrix
-
nullMatrix
public static double[][] nullMatrix(int n)
Returns a bidimensional array containing a zero matrix- Parameters:
n- the order of the zero matrix- Returns:
- the zero matrix bidimensional array
-
toString
public java.lang.String toString()
Returns a String representing this Matrix- Overrides:
toStringin classjava.lang.Object- Returns:
- the String to represent this Matrix
-
equals
public boolean equals(java.lang.Object mi)
Tells if an Object is equal to this Matrix- Overrides:
equalsin classjava.lang.Object- Parameters:
mi- the Object to compare- Returns:
- true if mi is a Matrix with the same elements, false otherwise
-
main
public static void main(java.lang.String[] ar)
-
-