Class Matrix


  • public class Matrix
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Matrix​(double[][] mat)
      Creates a matrix from a bidimensional array
      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.
      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
      boolean equals​(java.lang.Object mi)
      Tells if an Object is equal to this Matrix
      int getColumnsNumber()
      Returns the number of columns of this Matrix
      double[][] getMatrix()
      Gets the bidimensional array representing this Matrix
      int getRowsNumber()
      Returns the number of rows of this Matrix
      static double[][] identity​(int n)
      Returns a bidimensional array containing an identity matrix
      static boolean isRect​(double[][] m)
      Tells if a bidimensional array is a rectangle
      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.
      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.
      static void main​(java.lang.String[] ar)  
      static double[][] nullMatrix​(int n)
      Returns a bidimensional array containing a zero matrix
      static Matrix one​(int n)
      Returns the identity Matrix
      int order()
      Returns the order of this Matrix if it is a square matrix
      static double[][] pow​(double[][] m, int n)
      Returns the n-th power of a bidimensional array.
      Matrix pow​(int n)
      Returns the Matrix that n-th power of this Matrix
      static double[][] prod​(double[][] m1, double[][] m2)
      Returns the cartesian product of two bidimensional arrays.
      Matrix prod​(Matrix mat)
      Returns the Matrix that is the cartesian product of this Matrix with another Matrix
      static double[][] sum​(double[][] m1, double[][] m2)
      Returns the sum of two bidimensional arrays.
      Matrix sum​(Matrix mat)
      Returns the Matrix that is the sum of this Matrix with another Matrix
      java.lang.String toString()
      Returns a String representing this Matrix
      double value​(int i, int j)
      Gets the value of this Matrix at the given coordinates
      static Matrix zero​(int n)
      Returns the zero Matrix
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 array
        m2 - 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 array
        m2 - 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 array
        n - 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 index
        j - 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:
        toString in class java.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:
        equals in class java.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)