Matrix
math.utils

Class Matrix



  • public class Matrixextends Object
    class Matrix
    • Field Summary

      Fields 
      Modifier and TypeField and Description
      static doubletolerance
      The 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

      Methods 
      Modifier and TypeMethod 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.
      StringtoString()
      Returns a String representation of the elements of the Matrix
      voidtranspose()
      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:
        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:
        NullPointerException - if input array is null
        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:
        NullPointerException - if input vector is null
        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.
      • setToIdentity

        public void setToIdentity()
        Fills the matrix with zeros everywhere, except on the main diagonal, filled with ones.
      • toString

        public String toString()
        Returns a String representation of the elements of the Matrix
        Overrides:
        toString in class Object

SCaVis 2.0 © jWork.ORG