Class BigDecimalMatrix

java.lang.Object
com.mvohm.quadmatrix.Matrix
com.mvohm.quadmatrix.BigDecimalMatrix

public class BigDecimalMatrix extends Matrix
An implementation of the abstract class Matrix that uses an array of BigDecimal values to store the internal data and arithmetic provided by BigDecimal to perform calculations.
The precision of the calculations to be performed by a new instance of BigDecimalMatrix can be controlled via the precision parameter of a constructor, or by setting defaultPrecision wti setDefaultPrecision(int) method. The default precision value is used to set the precision for all new instances which are created by constructors that don't have precision parameter. If the default value of defaultPrecision is 40, this value will be used if no special actions to control the precision was done.
All arithmetic operations performed internally are done with a MathContext instance which is created with the precision set for the given instance and RoundingMode.HALF_EVEN mode.
Author:
M.Vokhmentsev
  • Constructor Summary

    Constructors
    Constructor
    Description
    BigDecimalMatrix(double[][] source)
    Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, and the default values of the needToScale flag and precision field.
    BigDecimalMatrix(double[][] source, boolean needToScale)
    Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, the specified value of the needToScale flag, and the default precision set for the class.
    BigDecimalMatrix(double[][] source, boolean needToScale, int precision)
    Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, and the specified values of the needToScale flag and precision field.
    BigDecimalMatrix(double[][] source, int precision)
    Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, the default value of the needToScale flag and the specified precision.
    Creates a new BigDecimalMatrix with a copy of the data of the given source matrix and the default values of the needToScale flag and precision field.
    BigDecimalMatrix(Matrix source, boolean needToScale)
    Creates a new BigDecimalMatrix with a copy of the data of the given source matrix, the specified value of the needToScale flag, and the default precision set for the class.
    BigDecimalMatrix(Matrix source, boolean needToScale, int precision)
    Creates a new BigDecimalMatrix with a copy of the data of the given source matrix and the specified values of the needToScale flag and precision field.
    BigDecimalMatrix(Matrix source, int precision)
    Creates a new BigDecimalMatrix with a copy of the data of the given source matrix, the default value of the needToScale flag, and the specified precision.
    Creates a new BigDecimalMatrix with a copy of the data of the given source array and the specified value of the needToScale flag.
    BigDecimalMatrix(Number[][] source, boolean needToScale)
    Creates a new BigDecimalMatrix with a copy of the data of the given source array, the specified value of the needToScale flag, and the default precision set for the class.
    BigDecimalMatrix(Number[][] source, boolean needToScale, int precision)
    Creates a new BigDecimalMatrix with a copy of the data of the given source array, and the specified values of the needToScale flag and precision field.
    BigDecimalMatrix(Number[][] source, int precision)
    Creates a new BigDecimalMatrix with a copy of the data of the given source array, the default value of the needToScale flag and the specified precision.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double[][] matrixB)
    Adds the given matrixB passed in as a two-dimentional array of doubles to this matrix and returns the sum.
    add(Matrix matrixB)
    Adds the given matrixB to this matrix and returns the sum.
    add(Number[][] matrixB)
    Adds the given matrixB passed in as a two-dimentional array of Number to this matrix and returns the sum.
    double
    Computes the condition number of the matrix, ║A║•║A-1║, and returns its value as a double value.
    Computes the determinant of the matrix and returns its value as a Number value.
    Computes the determinant of the matrix and returns its value as a BigDecimal value.
    double
    Computes the determinant of the matrix and returns its value as a double value.
    Computes the determinant of the matrix and returns its value as a Quadruple value.
    boolean
    equals(Object anotherOne)
    Indicates whether the other Matrix is equal to this one.
    Returns a two-dimentional array of BigDecimal instances containing the values of the corresponding matrix elements.
    Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of BigDecimals.
    Returns the last of the previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of BigDecimals.
    Number[][]
    Returns a two-dimentional array of Number containing the values of the corresponding matrix elements.
    static int
    Returns the current value of the precision used by default when creating new instances with constructors that don't have precision parameter.
    static boolean
    Returns the value of the static #scaleByDefault flag that is used to set corresponding instance flags when creating a new instances by constructors without needToScale parameter.
    double[][]
    Returns a two-dimentional array of primitive double values containing the values of the corresponding matrix elements, perhaps rounded.
    double[][]
    Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of primitive doubles.
    double[]
    Returns a copy of the last previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of doubles.
    Returns a string designation of the error code if an error has occurred during the solving or inversion of the matrix.
    Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a Matrix.
    Number[][]
    Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of Number.
    int
    Returns the value of precision used by this instance of BigDecimalMatrix.
    Returns a two-dimentional array of Quadruple instances containing the values of the corresponding matrix elements, perhaps rounded.
    Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of Quadruples.
    Returns the last of the previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of Quadruples.
    boolean
    Returns the value of an internal flag that defines whether row scaling will be applied while solving a system by this instance of Matrix.
    Returns a copy of the last previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of Numbers.
    int
    Returns a hash code value for the Matrix.
    Creates and returns a new Matrix instance containing the inversion of this instance.
    Creates and returns a new Matrix instance containing the inversion of this instance.
    multiply(double scalar)
    Multiplies this instance of Matrix by a scalar factor scalar passed in as a double parameter, and creates and returns a new matrix containing the product.
    multiply(double[] vector)
    Multiplies this instance of Matrix by a vector passed in as an array of doubles, and returns an array of Number values containing the product.
    multiply(double[][] factor)
    Multiplies this instance of Matrix by the factor passed in as a two-dimentional double array, and creates and returns a new matrix containing the product.
    multiply(Matrix factor)
    Multiplies this instance of Matrix by the matrix passed in as the factor argument, creates and returns a new matrix containing the product.
    multiply(Number scalar)
    Multiplies this instance of Matrix by a scalar factor scalar passed in as a Number parameter, and creates and returns a new matrix containing the product.
    multiply(Number[] vector)
    Multiplies this instance of Matrix by a vector passed in as an array of Number values and returns an array of Number values containing the product.
    multiply(Number[][] factor)
    Multiplies this instance of Matrix by the factor passed in as a two-dimentional array of Numbers, and creates and returns a new matrix containing the product.
    Computes the row-based norm of the matrix, ║A, and returns its value as a Number value.
    Computes the row-based norm of the matrix, ║A, and returns its value as a BigDecimal value.
    double
    Computes the row-based norm of the matrix, ║A, and returns its value as a double value.
    Computes the row-based norm of the matrix, ║A, and returns its value as a Quadruple value.
    static void
    setDefaultPrecision(int precision)
    Sets the value of the static defaultPrecision variable that is used to set corresponding instance fields when creating a new instances by constructors without precision parameter.
    static void
    setDefaultScaling(boolean scaleByDefault)
    Sets the value of the static scaleByDefault flag that is used to set corresponding instance flags when creating a new instances by constructors without needToScale parameter.
    solve(double[] vector)
    Solves a system of linear equations of form Ax = b and returns the found solution.
    solve(double[][] matrixB)
    Solves a matrix equation of form AX = B and returns the found solution.
    solve(Matrix matrixB)
    Solves a matrix equation of form AX = B and returns the found solution.
    solve(Number[] vector)
    Solves a system of linear equations of form Ax = b and returns the found solution.
    solve(Number[][] matrixB)
    Solves a matrix equation of form AX = B and returns the found solution.
    solveAccurately(double[] vector)
    Solves a system of linear equations of form Ax = b with increased accuracy and returns the found solution.
    solveAccurately(double[][] matrixB)
    Solves a matrix equation of form AX = B and returns the found solution.
    Solves a matrix equation of form AX = B and returns the found solution.
    Solves a system of linear equations of form Ax = b with increased accuracy and returns the found solution.
    solveAccurately(Number[][] matrixB)
    Solves a matrix equation of form AX = B and returns the found solution.
    solveSPD(double[] vector)
    Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients and returns the found solution.
    solveSPD(Number[] vector)
    Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients and returns the found solution.
    solveSPDAccurately(double[] vector)
    Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients, using an iterative refinement algorithm to achieve higher solution accuracy, and returns the found solution.
    Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients, using an iterative refinement algorithm to achieve higher solution accuracy, and returns the found solution.
    subtract(double[][] matrixB)
    Subtracts the given matrixB passed in as a two-dimentional array of doubles from this matrix and returns the difference.
    subtract(Matrix matrixB)
    Subtracts the given matrixB from this matrix and returns the difference.
    subtract(Number[][] matrixB)
    Subtracts the given matrixB passed in as a two-dimentional array of Number from this matrix and returns the difference.
    Creates and returns a new Matrix instance containing the transposition of this instance.
    Creates and returns a new Matrix instance containing a unity matrix of the same size as the source matrix.

    Methods inherited from class com.mvohm.quadmatrix.Matrix

    getSize

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BigDecimalMatrix

      public BigDecimalMatrix(Matrix source)
      Creates a new BigDecimalMatrix with a copy of the data of the given source matrix and the default values of the needToScale flag and precision field.
      Uses static scaleByDefault value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting.
      Uses static defaultPrecision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a matrix whose data get copied into the new Matrix's internal storage.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(Matrix source, boolean needToScale)
      Creates a new BigDecimalMatrix with a copy of the data of the given source matrix, the specified value of the needToScale flag, and the default precision set for the class.
      Uses the given needToScale value to set the new matrix's needToScale flag designating necessity to scale matrix rows while solving equation systems and inverting. The value of this flag can be obtained via getScaling() instance method.
      Uses static defaultPrecision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a matrix whose data get copied into the new Matrix's internal storage.
      needToScale - the value defining necessity to scale rows while solving equation systems and inverting.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(Matrix source, int precision)
      Creates a new BigDecimalMatrix with a copy of the data of the given source matrix, the default value of the needToScale flag, and the specified precision.
      Uses static scaleByDefault value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting.
      Uses the specified precision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a matrix whose data get copied into the new Matrix's internal storage.
      precision - the value defining the precision of the calculations that the newly-created instance will do.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(Matrix source, boolean needToScale, int precision)
      Creates a new BigDecimalMatrix with a copy of the data of the given source matrix and the specified values of the needToScale flag and precision field.
      Uses the given needToScale value to set the new matrix's needToScale flag designating necessity to scale matrix rows while solving equation systems and inverting.
      Uses the specified precision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a matrix whose data get copied into the new Matrix's internal storage.
      needToScale - the value defining necessity to scale rows while solving equation systems and inverting.
      precision - the value defining the precision of the calculations that the newly-created instance will do.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(double[][] source)
      Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, and the default values of the needToScale flag and precision field.
      Uses static scaleByDefault value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting.
      Uses static defaultPrecision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Throws IllegalArgumentException if the source argument is a non-square or empty array, or contains non-numeric values, Double.NaN, Double.NEGATIVE_INFINITY, or Double.POSITIVE_INFINITY.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(double[][] source, boolean needToScale)
      Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, the specified value of the needToScale flag, and the default precision set for the class.
      Uses the given needToScale value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting. The value of this flag can be obtained via getScaling() instance method.
      Uses static defaultPrecision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Throws IllegalArgumentException if the source argument is a non-square or empty array, or contains non-numeric values, Double.NaN, Double.NEGATIVE_INFINITY, or Double.POSITIVE_INFINITY.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      needToScale - the value defining necessity to scale rows while solving equation systems and inverting.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(double[][] source, int precision)
      Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, the default value of the needToScale flag and the specified precision.
      Uses static scaleByDefault value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting.
      Uses the specified precision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      precision - the value defining the precision of the calculations that the newly-created instance will do.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(double[][] source, boolean needToScale, int precision)
      Creates a new BigDecimalMatrix whose inner data are obtained by converting the values of the given source array into corresponding BigDecimal values by BigDecimal.valueOf(double) method, and the specified values of the needToScale flag and precision field.
      Uses the given needToScale value to set the new matrix's needToScale flag designating necessity to scale matrix rows while solving equation systems and inverting.
      Uses the specified precision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      needToScale - the value defining necessity to scale rows while solving equation systems and inverting.
      precision - the value defining the precision of the calculations that the newly-created instance will do.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(Number[][] source)
      Creates a new BigDecimalMatrix with a copy of the data of the given source array and the specified value of the needToScale flag.
      Translates the values of the specified source array to BigDecimal values with methods depending on the actual element type of the source array -- it's BigDecimal.valueOf(double) for Doubles, Quadruple.bigDecimalValue() for Quadruples, and just copying for BigDecimal values.
      Uses static scaleByDefault value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting.
      Uses static defaultPrecision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Throws IllegalArgumentException if the source argument is a non-square or empty array, or contains non-numeric values, Double.NaN, Double.NEGATIVE_INFINITY, or Double.POSITIVE_INFINITY.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(Number[][] source, boolean needToScale)
      Creates a new BigDecimalMatrix with a copy of the data of the given source array, the specified value of the needToScale flag, and the default precision set for the class.
      Translates the values of the specified source array to BigDecimal values with methods depending on the actual element type of the source array -- it's BigDecimal.valueOf(double) for Doubles, Quadruple.bigDecimalValue() for Quadruples, and just copying for BigDecimal values.
      Uses the given needToScale value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting. The value of this flag can be obtained via getScaling() instance method.
      Uses static defaultPrecision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Throws IllegalArgumentException if the source argument is a non-square or empty array, or contains non-numeric values, Double.NaN, Double.NEGATIVE_INFINITY, or Double.POSITIVE_INFINITY.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      needToScale - the value defining necessity to scale rows while solving equation systems and inverting.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(Number[][] source, int precision)
      Creates a new BigDecimalMatrix with a copy of the data of the given source array, the default value of the needToScale flag and the specified precision.
      Translates the values of the specified source array to BigDecimal values with methods depending on the actual element type of the source array -- it's BigDecimal.valueOf(double) for Doubles, Quadruple.bigDecimalValue() for Quadruples, and just copying for BigDecimal values.
      Uses static scaleByDefault value to set the new matrix's needToScale flag designating necessity to scale matrix rows before solving equation systems and inverting.
      Uses the specified precision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      precision - the value defining the precision of the calculations that the newly-created instance will do.
      See Also:
    • BigDecimalMatrix

      public BigDecimalMatrix(Number[][] source, boolean needToScale, int precision)
      Creates a new BigDecimalMatrix with a copy of the data of the given source array, and the specified values of the needToScale flag and precision field.

      Translates the values of the specified source array to BigDecimal values with methods depending on the actual element type of the source array -- it's BigDecimal.valueOf(double) for Doubles, Quadruple.bigDecimalValue() for Quadruples, and just copying for BigDecimal values.

      Uses the given needToScale value to set the new matrix's needToScale flag designating necessity to scale matrix rows while solving equation systems and inverting.
      Uses the specified precision value to set the new matrix's precision field that defines the precision of the computations that the instance methods perform.
      Parameters:
      source - a two-dimentional square array of doubles to be converted into the BigDecimal values of the internal storage of this instance.
      precision - the value defining the precision of the calculations that the
      needToScale - the value defining necessity to scale rows while solving equation systems and inverting. newly-created instance will do.
      See Also:
  • Method Details

    • setDefaultScaling

      public static void setDefaultScaling(boolean scaleByDefault)
      Sets the value of the static scaleByDefault flag that is used to set corresponding instance flags when creating a new instances by constructors without needToScale parameter.
      This flag determines the need to scale the rows of the matrix before LU-decomposing it so that the values of their norms are close enough to each other. This may increase the accuracy of the solution and the inversion, especially for matrices with a significantly non-uniform distribution of element values, at the cost of a insignificant increase in computation time.
      Parameters:
      scaleByDefault - the value of needToScale flag to set for new matrices created with constructors without needToScale parameter.
    • getDefaultScaling

      public static boolean getDefaultScaling()
      Returns the value of the static #scaleByDefault flag that is used to set corresponding instance flags when creating a new instances by constructors without needToScale parameter.
      Returns:
      the value of the static #scaleByDefault flag
      See Also:
    • setDefaultPrecision

      public static void setDefaultPrecision(int precision)
      Sets the value of the static defaultPrecision variable that is used to set corresponding instance fields when creating a new instances by constructors without precision parameter.
      This value is used to create a MathContext object that is used by all arithmetic operations performed by the instance and thus defines the precision of the calculations.
      Parameters:
      precision - the value of the precision to be used when creating new instances by constructors without precisionparameter
    • getDefaultPrecision

      public static int getDefaultPrecision()
      Returns the current value of the precision used by default when creating new instances with constructors that don't have precision parameter.
      Returns:
      the default precision value currently set for the BigDecimalMatrix class
      See Also:
    • getScaling

      public boolean getScaling()
      Returns the value of an internal flag that defines whether row scaling will be applied while solving a system by this instance of Matrix.
      Scaling of the rows of the matrix may be used while solving systems of linear equations. When an internal flag controlling the scaling is set to true, the rows of the matrix along with the corresponding elements of the vector b or the matrix B are scaled so that the norms of the rows are all be 1.0. In most cases this improves the accuracy of the solution, especially for matrices including both very large and very small elements. The default value of the flag signifying the necessity of the scaling for a certain subclass may be set via a static method setScaling() of the subclass, and the necessity of the scaling for a newly-created instance of Matrix may be controlled via the corresponding parameter of a constructor.
      Specified by:
      getScaling in class Matrix
      Returns:
      the value of the flag that defines whether the scaling will be applied while solving a system by this instance of Matrix
    • getPrecision

      public int getPrecision()
      Returns the value of precision used by this instance of BigDecimalMatrix.
      Returns:
      the value of precision used by this instance.
      See Also:
    • getData

      public Number[][] getData()
      Returns a two-dimentional array of Number containing the values of the corresponding matrix elements.
      The exact type of the array elements depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      The returned array is a copy of the corresponding internal array and can be safely modified. There is no loss of precision when copying, so the returned values are exactly equal to the values of the corresponding elements of the internal storage.
      BigDecimalMatrix returns an array containing the exact values of the corresponding elements of the internal storage
      Specified by:
      getData in class Matrix
      Returns:
      a two-dimentional array of Number containing the values of the corresponding matrix elements.
    • getDoubleData

      public double[][] getDoubleData()
      Returns a two-dimentional array of primitive double values containing the values of the corresponding matrix elements, perhaps rounded.
      If the type of the internal data of the particular class enables for higher precision than that provided by double, the values get rounded to the nearest possible double value.
      If the value of an internal data element exceeds the range of double values, it gets converted to Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY, depending on its sign.
      BigDecimalMatrix returns an array containing values of the internal matrix data rounded to nearest double values by BigDecimal.doubleValue() method.
      Specified by:
      getDoubleData in class Matrix
      Returns:
      a two-dimentional array of primitive double values containing rounded values of the corresponding elements of the internal data array.
    • getQuadrupleData

      public Quadruple[][] getQuadrupleData()
      Returns a two-dimentional array of Quadruple instances containing the values of the corresponding matrix elements, perhaps rounded.
      If the type of the internal data of the particular class enables for higher precision than that provided by Quadruple, the values get rounded to the nearest possible Quadruple value.
      If the value of an internal data element exceeds the range of Quadruple values, it gets converted to Quadruple.POSITIVE_INFINITY or Quadruple.NEGATIVE_INFINITY, depending on its sign.
      BigDecimalMatrix returns an array containing Quadruple values nearest to the values of the corresponding elements of the internal array of BigDecimal of the internal storage.
      Specified by:
      getQuadrupleData in class Matrix
      Returns:
      a two-dimentional array of Quadruple values containing the values of the corresponding matrix elements, perhaps rounded.
    • getBigDecimalData

      public BigDecimal[][] getBigDecimalData()
      Returns a two-dimentional array of BigDecimal instances containing the values of the corresponding matrix elements.
      If the type of the internal data of the particular class is double then the corresponding BigDecimal values are obtained using BigDecimal.valueOf(double) method. If the type of the internal data of the particular class is Quadruple then the corresponding BigDecimal values are obtained using Quadruple.bigDecimalValue() method. If an internal data element is not convertible to BigDecimal (i.e. it is NaN or Infinity), throws NumberFormatException.
      BigDecimalMatrix returns an array containing the exact values of the corresponding elements of the internal storage.
      Specified by:
      getBigDecimalData in class Matrix
      Returns:
      a two-dimentional array of BigDecimal values containing the values of the corresponding matrix elements translated to BigDecimal instances.
    • equals

      public boolean equals(Object anotherOne)
      Indicates whether the other Matrix is equal to this one.
      Matrices are considered to be equal if they belong to the same subtype, and their internal arrays containing the elements of the matrices are equal, and their needToScale flags are equal.
      Under those condition, the matrices yield equal results for all operations performed on them.
      Specified by:
      equals in class Matrix
      Returns:
      true, if the matrices are equal.
    • hashCode

      public int hashCode()
      Returns a hash code value for the Matrix.
      It is guaranteed, that for two matrices returning different hashcodes their Matrix.equals(Object) methods return false, and two matrices considered to be equal return equal hashcodes. For two different matrices, the probability of the equality of their hashcodes is reasonably low.
      Specified by:
      hashCode in class Matrix
      Returns:
      a hash code value for this object.
      See Also:
    • solve

      public Number[] solve(double[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using LU decomposition.
      The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the length of the vector does not match the size of the matrix, or the argument contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Before solving the equation, the values of the vector argument get converted to BigDecimal values, using BigDecimal.valueOf(double) method.
      Specified by:
      solve in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of doubles
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix,, or the system has no solution or has infinitely many solutions, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
      See Also:
    • solve

      public Number[] solve(Number[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using LU decomposition. Before solving, the given vector gets translated to an array of values of the type that is used to store internal matrix data (double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the length of the vector does not match the size of the matrix, or vector contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      Before solving the equation, the values of the vector argument get converted to exactly equal or nearest possible BigDecimal values, depending on the particular type of the vector elements.
      Specified by:
      solve in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of Numbers
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix, or the system has no solution or has infinitely many solutions, or the argument contains invalid values (NaN, Infinity, or null).
      NullPointerException - if the argument is null
      See Also:
    • solveSPD

      public Number[] solveSPD(double[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using Cholesky decomposition. The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an asymmetric or non-positively-defined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the length of the vector does not match the size of the matrix, or the argument contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Before solving the equation, the values of the vector argument get converted to BigDecimal values, using BigDecimal.valueOf(double) method.
      Specified by:
      solveSPD in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of Numbers
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix, or the matrix is asymmetric or not positively-defined, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
      See Also:
    • solveSPD

      public Number[] solveSPD(Number[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using Cholesky decomposition. Before solving, the given vector gets translated to an array of values of the type that is used to store internal matrix data (double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc). The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an asymmetric or non-positively-defined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the length of the vector does not match the size of the matrix, or vector contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message. Before solving the equation, the values of the vector argument get converted to exactly equal or nearest possible BigDecimal values, depending on the particular type of the vector elements.
      Specified by:
      solveSPD in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of Numbers
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix, or the matrix is asymmetric or not positively-defined, or the argument contains invalid values (NaN, Infinity, or null)
      NullPointerException - if the argument is null
      See Also:
    • solveAccurately

      public Number[] solveAccurately(double[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b with increased accuracy and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using LU decomposition. Uses an iterative refinement to find a more accurate solution. The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the length of the vector does not match the size of the matrix, or vector contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Before solving the equation, the values of the vector argument get converted to BigDecimal values, using BigDecimal.valueOf(double) method.
      The execution time is about 35% longer than that of the simple solve(double[]). In a typical case, the result error is reduced, compared to the simple solve(), by a factor from several units to several tens or a few hundreds, depending on the properties of the specific matrix data.
      For matrices 150 x 150 with uniformly-distributed random values and precision value of 40, average square root of MSE is reduced by approximately 70 times, from about 7.0e-38 down to 1.0e-39.
      Specified by:
      solveAccurately in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of doubles
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix, or the system has no solution or has infinitely many solutions, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
      See Also:
    • solveAccurately

      public Number[] solveAccurately(Number[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b with increased accuracy and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using LU decomposition. Before solving, the given vector gets translated to an array of values of the type that is used to store internal matrix data (double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      Uses an iterative refinement to find a more accurate solution. The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the length of the vector does not match the size of the matrix, or vector contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      Before solving the equation, the values of the vector argument get converted to exactly equal or nearest possible BigDecimal values, depending on the particular type of the vector elements.
      The execution time is about 35% longer than that of the simple solve(double[]). In a typical case, the result error is reduced, compared to the simple solve(), by a factor from several units to several tens or a few hundreds, depending on the properties of the specific matrix data.
      For matrices 150 x 150 with uniformly-distributed random values and precision value of 40, average square root of MSE is reduced by approximately 70 times, from about 7.0e-38 down to 1.0e-39.
      Specified by:
      solveAccurately in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of Numbers
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix, or the system has no solution or has infinitely many solutions, or the argument contains invalid values (NaN, Infinity, or null)
      NullPointerException - if the argument is null
      See Also:
    • solveSPDAccurately

      public Number[] solveSPDAccurately(double[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients, using an iterative refinement algorithm to achieve higher solution accuracy, and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using Cholesky decomposition. Uses an iterative refinement to find a more accurate solution. The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an asymmetric or non-SPD matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the length of the vector does not match the size of the matrix, or vector contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Before solving the equation, the values of the vector argument get converted to BigDecimal values, using BigDecimal.valueOf(double) method.
      The execution time is about 65% longer than that of the simple solveSPD(double[]). In a typical case, the result error is reduced, compared to the simple solveSPD(), by a factor from several units to several tens, depending on the properties of the specific matrix data.
      For matrices 150 x 150 with precision value of 40, average square root of MSE is reduced by approximately 11 times, from about 9.0e-38 down to 7.7e-39.
      Specified by:
      solveSPDAccurately in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of doubles
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix, or the matrix is asymmetric or not positively-defined, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
      See Also:
    • solveSPDAccurately

      public Number[] solveSPDAccurately(Number[] vector) throws IllegalArgumentException, NullPointerException
      Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients, using an iterative refinement algorithm to achieve higher solution accuracy, and returns the found solution.
      Solves the system Ax = b, formed by the inner matrix data A and the vector b passed in as the vector argument, using Cholesky decomposition. Uses an iterative refinement to find a more accurate solution. The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an asymmetric or non-SPD matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode(). If the length of the vector does not match the size of the matrix, or vector contains non-numeric values (NaN or Infinity) or null throws IllegalArgumentException with a relevant message.
      Before solving the equation, the values of the vector argument get converted to exactly equal or nearest possible BigDecimal values, depending on the particular type of the vector elements.
      The execution time is about 65% longer than that of the simple solveSPD(double[]). In a typical case, the result error is reduced, compared to the simple solveSPD(), by a factor from several units to several tens, depending on the properties of the specific matrix data.
      For matrices 150 x 150 with precision value of 40, average square root of MSE is reduced by approximately 11 times, from about 9.0e-38 down to 7.7e-39.
      Specified by:
      solveSPDAccurately in class Matrix
      Parameters:
      vector - the column vector b of the equation to be solved, Ax = b, as an array of doubles
      Returns:
      the found solution x to the equation Ax = b as an array of Number instances. The particular type of the elements of the array returned by BigDecimalMatrix is BigDecimal.
      Throws:
      IllegalArgumentException - if the length of the vector does not match the size of the matrix, or the matrix is asymmetric or not positively-defined, or the argument contains invalid values (NaN, Infinity, or null)
      NullPointerException - if the argument is null
      See Also:
    • getSolution

      public Number[] getSolution()
      Returns a copy of the last previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of Numbers.
      The exact type of the elements of the returned array depends on the particular subclass of this instance (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      If no system was solved with this instance of the Matrix, returns null.
      Specified by:
      getSolution in class Matrix
      Returns:
      the last of the previously found vector solutions, x, to a system of of linear equations of form Ax = b, as an array of BigDecimals, or null, if no system was solved with the matrix.
    • getDoubleSolution

      public double[] getDoubleSolution()
      Returns a copy of the last previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of doubles.
      If the particular subtype of the instance stores internal data with higher precision than that provided by double, the values of the elements of the returned vector get rounded to the nearest double values.
      If no system was solved with this instance of the Matrix, returns null.
      The elements of the array returned by QudrupleMatrix are corresponded values of the found solution, rounded to the closest double values
      Specified by:
      getDoubleSolution in class Matrix
      Returns:
      the last of the previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of primitive doubles. or null, if no system was solved with the matrix.
    • getQuadrupleSolution

      public Quadruple[] getQuadrupleSolution()
      Returns the last of the previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of Quadruples.
      If the particular subtype of the instance stores internal data with higher precision than that provided by Quadruple, the values of the elements of the returned vector get rounded to the nearest double values.
      If no system was solved with this instance of the Matrix, returns null.
      BigDecimalMatrix translates BigDecimal values of the internally stored solution to Quadruple values, using Quadruple(BigDecimal) constructor.
      Specified by:
      getQuadrupleSolution in class Matrix
      Returns:
      the last of the previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of Quadruples, or null, if no system was solved with the matrix.
    • getBigDecimalSolution

      public BigDecimal[] getBigDecimalSolution()
      Returns the last of the previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of BigDecimals.
      If no system was solved with this instance of the Matrix, returns null.
      If the solution contains values that can't be translated to BigDeciaml (NaN or Infinity), throws NumberFormatException. BigDecimalMatrix returns the exact values that was found by the corresponding solution method.
      Specified by:
      getBigDecimalSolution in class Matrix
      Returns:
      the last of the previously found vector solutions, x, to a system of linear equations of form Ax = b, as an array of BigDecimals. or null, if no system was solved with the matrix.
    • getErrorCode

      public String getErrorCode()
      Returns a string designation of the error code if an error has occurred during the solving or inversion of the matrix.
      This method can return the following values:
      • "OK" -- The last solution or inversion was successful;
      • "ASYMMETRIC" -- There was an attempt to solve or inverse the matrix using Cholesky decomposition, but the matrix is asymmetric;
      • "NON_SPD" -- There was an attempt to solve or inverse the matrix using Cholesky decomposition, but the matrix is not positively-defined;
      • "NON_INVERTIBLE" -- There was an attempt to solve or inverse the matrix using LU decomposition, but the matrix is inconsistent or underdetermined
      If no operations requiring decompositions were performed with this instance yet, returns OK.
      Specified by:
      getErrorCode in class Matrix
      Returns:
      a string designation of the error code if an error has occurred during the solving or inversion of the matrix, or "OK" in case of success.
      See Also:
      • Matrix.ErrorCodes
    • solve

      Solves a matrix equation of form AX = B and returns the found solution.
      Solves a matrix equation of form AX = B formed by the inner matrix data A and the matrix B passed in as the Matrix matrixB argument, using LU decomposition.
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode(). If the size of the matrixB does not match the size of this instance of the matrix, throws IllegalArgumentException with a relevant message.
      Specified by:
      solve in class Matrix
      Parameters:
      matrixB - the matrix B of the equation to be solved, AX = B
      Returns:
      the found solution X to the equation AX = B as a new instance of BigDecimalMatrix.
      Throws:
      IllegalArgumentException - if the size of the matrixB does not match the size of this instance or the system has no solution or has infinitely many solutions.
      NullPointerException - if the argument is null
      See Also:
    • solve

      public Matrix solve(double[][] matrixB) throws IllegalArgumentException, NullPointerException
      Solves a matrix equation of form AX = B and returns the found solution.
      Solves a matrix equation of form AX = B formed by the inner matrix data A and the matrix B passed in as the double[][] matrixB argument, using LU decomposition.
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or the argument contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Specified by:
      solve in class Matrix
      Parameters:
      matrixB - the matrix B of the equation to be solved, AX = B, as a two-dimentional array of primitive doubles
      Returns:
      the found solution X to the equation AX = B as a new instance of BigDecimalMatrix.
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance, or the system has no solution or has infinitely many solutions, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
      See Also:
    • solve

      public Matrix solve(Number[][] matrixB) throws IllegalArgumentException, NullPointerException
      Solves a matrix equation of form AX = B and returns the found solution.
      Solves a matrix equation of form AX = B formed by the inner matrix data A and the matrix B passed in as the Number[][] matrixB argument, using LU decomposition.
      Before solving, the given matrixB array gets translated to an array of values of the type that is used to store internal matrix data (double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or matrixB contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      Specified by:
      solve in class Matrix
      Parameters:
      matrixB - the matrix B of the equation to be solved, AX = B, as a two-dimentional array of Number
      Returns:
      the found solution X to the equation AX = B as a new instance of BigDecimalMatrix.
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance, or the system has no solution or has infinitely many solutions, or the argument contains invalid values (NaN, Infinity, or null).
      NullPointerException - if the argument is null
      See Also:
    • solveAccurately

      public Matrix solveAccurately(Matrix matrixB) throws IllegalArgumentException, NullPointerException
      Solves a matrix equation of form AX = B and returns the found solution.
      Solves a matrix equation of form AX = B formed by the inner matrix data A and the matrix B passed in as the matrixB argument, using LU decomposition.
      Uses an iterative refinement to find a more accurate solution.
      In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the size of the matrixB does not match the size of this instance of the matrix, throws IllegalArgumentException with a relevant message.
      The execution time is about 60 times longer than that of the simple solve(Matrix). In a typical case, the result error is reduced, compared to the simple solve(), by a factor from units to several tens or more, depending on specific values of the matrix elements. For matrices 150 x 150 with uniformly-distributed random values and precision value of 40, average square root of MSE is reduced by approximately 100 times, from about 2.0e-37 down to 2.0e-39.
      Specified by:
      solveAccurately in class Matrix
      Parameters:
      matrixB - the matrix B of the equation to be solved, AX = B
      Returns:
      the found solution X to the equation AX = B as a new instance of BigDecimalMatrix.
      Throws:
      IllegalArgumentException - if the size of the matrixB does not match the size of this instance or the system has no solution or has infinitely many solutions.
      NullPointerException - if the argument is null
      See Also:
    • solveAccurately

      public Matrix solveAccurately(double[][] matrixB) throws IllegalArgumentException, NullPointerException
      Solves a matrix equation of form AX = B and returns the found solution.
      Solves a matrix equation of form AX = B formed by the inner matrix data A and the matrix B passed in as the double[][] matrixB argument, using LU decomposition.
      Uses an iterative refinement to find a more accurate solution. In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or the argument contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      The execution time is about 60 times longer than that of the simple solve(Matrix). In a typical case, the result error is reduced, compared to the simple solve(), by a factor from units to several tens or more, depending on specific values of the matrix elements. For matrices 150 x 150 with uniformly-distributed random values and precision value of 40, average square root of MSE is reduced by approximately 100 times, from about 2.0e-37 down to 2.0e-39.
      Specified by:
      solveAccurately in class Matrix
      Parameters:
      matrixB - the matrix B of the equation to be solved, AX = B, as a two-dimentional array of primitive doubles
      Returns:
      the found solution X to the equation AX = B as a new instance of BigDecimalMatrix.
      Throws:
      IllegalArgumentException - if the size of the matrixB does not match the size of this instance or the system has no solution or has infinitely many solutions, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
      See Also:
    • solveAccurately

      public Matrix solveAccurately(Number[][] matrixB) throws IllegalArgumentException, NullPointerException
      Solves a matrix equation of form AX = B and returns the found solution.
      Solves a matrix equation of form AX = B formed by the inner matrix data A and the matrix B passed in as the Number[][] matrixB argument, using LU decomposition.
      Before solving, the given matrixB array gets translated to an array of values of the type that is used to store internal matrix data (double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      Uses an iterative refinement to find a more accurate solution. In case of an inconsistent or underdefined matrix throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or matrixB contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      The execution time is about 60 times longer than that of the simple solve(Matrix). In a typical case, the result error is reduced, compared to the simple solve(), by a factor from units to several tens or more, depending on specific values of the matrix elements. For matrices 150 x 150 with uniformly-distributed random values and precision value of 40, average square root of MSE is reduced by approximately 100 times, from about 2.0e-37 down to 2.0e-39.
      Specified by:
      solveAccurately in class Matrix
      Parameters:
      matrixB - the matrix B of the equation to be solved, AX = B, as a two-dimentional array of Number
      Returns:
      the found solution X to the equation AX = B as a new instance of BigDecimalMatrix.
      Throws:
      IllegalArgumentException - if the size of the matrixB does not match the size of this instance or the system has no solution or has infinitely many solutions, or the argument contains invalid values (NaN, Infinity, or null).
      NullPointerException - if the argument is null
      See Also:
    • getMatrixSolution

      public Matrix getMatrixSolution()
      Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a Matrix. If no matrix equation was solved with this instance of the Matrix, returns null.
      Specified by:
      getMatrixSolution in class Matrix
      Returns:
      the last of the previously found matrix solution X to a system of linear equations of form AX = B, as a BigDecimalMatrix, or null, if no matrix equation was solved with the matrix.
    • getNumberMatrixSolution

      public Number[][] getNumberMatrixSolution()
      Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of Number.
      The particular type of the elements of the returned vector depends on the particular subtype of Matrix (it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
      If no matrix equation was solved with this instance of the Matrix, returns null.
      BigDecimalMatrix#getNumberMatrixSolution() returns the exact values of the elements of the matrix solution found by a call to one of the BigDecimalMatrix#solve() or BigDecimalMatrix#solveAccurately() methods.
      Specified by:
      getNumberMatrixSolution in class Matrix
      Returns:
      the last of the previously found matrix solution X, to a system of linear equations of form AX = B, as a two-dimentional array of BigDecimal, or null, if no matrix equation was solved with the matrix.
    • getDoubleMatrixSolution

      public double[][] getDoubleMatrixSolution()
      Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of primitive doubles.
      If no matrix equation was solved with this instance of the Matrix, returns null.
      The returned array contains the values of the elements of the matrix solution found by a call to one of the BigDecimalMatrix#solve() or BigDecimalMatrix#solveAccurately() methods, rounded to nearest double values.
      Specified by:
      getDoubleMatrixSolution in class Matrix
      Returns:
      the last of the previously found matrix solution X, to a system of linear equations of form AX = B, as two-dimentional array of doubles, or null, if no matrix equation was solved with the matrix.
    • getQuadrupleMatrixSolution

      public Quadruple[][] getQuadrupleMatrixSolution()
      Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of Quadruples.
      If no matrix equation was solved with this instance of the Matrix, returns null.
      The returned array contains Quadruple values nearest to the corresponding BigDecimal elements of the matrix solution found by a call to one of the BigDecimalMatrix#solve() or BigDecimalMatrix#solveAccurately() methods.
      Specified by:
      getQuadrupleMatrixSolution in class Matrix
      Returns:
      the last of the previously found matrix solution X, to a system of linear equations of form AX = B, as two-dimentional array of Quadruples, or null, if no matrix equation was solved with the matrix.
    • getBigDecimalMatrixSolution

      public BigDecimal[][] getBigDecimalMatrixSolution()
      Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as a two-dimentional array of BigDecimals.
      If no matrix equation was solved with this instance of the Matrix, returns null.
      The returned array contains the exact values of the elements of the matrix solution found by a call to one of the BigDecimalMatrix#solve() or BigDecimalMatrix#solveAccurately() methods.
      Specified by:
      getBigDecimalMatrixSolution in class Matrix
      Returns:
      the last of the previously found matrix solution X, to a system of linear equations of form AX = B, as two-dimentional array of BigDecimal, or null, if no matrix equation was solved with the matrix.
    • inverse

      public Matrix inverse() throws IllegalArgumentException
      Creates and returns a new Matrix instance containing the inversion of this instance.
      Computes the inversion of the matrix by solving the equation AX = E, creates and returns a new Matrix containing the found inversion. The exact subtype of the returned matrix is the same as that of this instance. If the matrix is not invertible (i.e. inconsistent or underdefined), throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      The particular subtype of Matrix returned by BigDecimalMatrix#inverse() is BigDecimalMatrix.
      Specified by:
      inverse in class Matrix
      Returns:
      a new Matrix containing the inversion of the given matrix.
      Throws:
      IllegalArgumentException - if the matrix is not invertible (i.e. inconsistent or underdefined)
    • inverseAccurately

      public Matrix inverseAccurately() throws IllegalArgumentException
      Creates and returns a new Matrix instance containing the inversion of this instance.
      Computes the inversion of the matrix by solving the equation AX = E, creates and returns a new Matrix containing the found inversion. Uses an iterative refinement to achieve a more accurate solution to the equation. The exact subtype of the returned matrix is the same as that of this instance. If the matrix is not invertible (i.e. inconsistent or underdefined), throws IllegalArgumentException with a relevant message and sets internal variable errorCode, whose value can be obtained using method Matrix.getErrorCode().
      The execution time is about 30 times longer than that of the simple inverse(). In a typical case, the result error is reduced, compared to the simple inverse(), by a factor from several units to several tens, depending on specific values of the matrix elements. For matrices 150 x 150 with uniformly-distributed random values, average square root of MSE is reduced by approximately 25 times, from about 4.5e-38 down to about 1.8e-39
      Specified by:
      inverseAccurately in class Matrix
      Returns:
      a new BigDecimalMatrix containing the inversion of the given matrix.
      Throws:
      IllegalArgumentException - if the matrix is not invertible (i.e. inconsistent or underdefined)
    • transpose

      public Matrix transpose()
      Creates and returns a new Matrix instance containing the transposition of this instance.
      Computes the transposition of the matrix, creates and returns a new Matrix containing the found transposition.
      The exact subtype of the returned matrix is the same as that of this instance.
      Specified by:
      transpose in class Matrix
      Returns:
      a new BigDecimalMatrix containing the transposition of the given matrix.
    • unity

      public Matrix unity()
      Creates and returns a new Matrix instance containing a unity matrix of the same size as the source matrix.
      The exact subtype of the returned matrix is the same as that of this instance.
      Specified by:
      unity in class Matrix
      Returns:
      a new BigDecimalMatrix containing the unity matrix of the same size as this Matrix
    • multiply

      public Matrix multiply(Matrix factor) throws IllegalArgumentException, NullPointerException
      Multiplies this instance of Matrix by the matrix passed in as the factor argument, creates and returns a new matrix containing the product. The exact subtype of the returned matrix is the same as that of this instance. If the size of the factor does not match the size of the source matrix, throws IllegalArgumentException with a relevant message.
      Specified by:
      multiply in class Matrix
      Parameters:
      factor - a matrix to multiply this instance by
      Returns:
      a new BigDecimalMatrix representing the product
      Throws:
      IllegalArgumentException - if the size of the argument does not match the size of this instance
      NullPointerException - if the argument is null
    • multiply

      public Matrix multiply(double[][] factor) throws IllegalArgumentException, NullPointerException
      Multiplies this instance of Matrix by the factor passed in as a two-dimentional double array, and creates and returns a new matrix containing the product. The exact subtype of the returned matrix is the same as that of this instance.
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or matrixB contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Specified by:
      multiply in class Matrix
      Parameters:
      factor - two-dimentional double array representing a matrix to multiply this instance by
      Returns:
      a new BigDecimalMatrix representing the product
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or matrixB contains non-numeric values (NaN or Infinity)
      NullPointerException - if the argument is null
    • multiply

      public Matrix multiply(Number[][] factor) throws IllegalArgumentException, NullPointerException
      Multiplies this instance of Matrix by the factor passed in as a two-dimentional array of Numbers, and creates and returns a new matrix containing the product. The exact subtype of the returned matrix is the same as that of this instance.
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or matrixB contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      Specified by:
      multiply in class Matrix
      Parameters:
      factor - two-dimentional array of Number representing the matrix to multiply this instance by
      Returns:
      a new BigDecimalMatrix representing the product
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or matrixB contains non-numeric values (NaN or Infinity) or null
      NullPointerException - if the argument is null
    • multiply

      public Number[] multiply(double[] vector) throws IllegalArgumentException, NullPointerException
      Multiplies this instance of Matrix by a vector passed in as an array of doubles, and returns an array of Number values containing the product. The exact type of the elements of the returned array depends on the particular subtype of the Matrix.
      If the length of the vector does not match the size of the source matrix, or the argument contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Specified by:
      multiply in class Matrix
      Parameters:
      vector - the vector to multiply the matrix by.
      Returns:
      an array of BigDecimal values containing the product.
      Throws:
      IllegalArgumentException - if the length of the array does not match the size of the matrix, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
    • multiply

      public Number[] multiply(Number[] vector) throws IllegalArgumentException, NullPointerException
      Multiplies this instance of Matrix by a vector passed in as an array of Number values and returns an array of Number values containing the product. The exact type of the elements of the returned array depends on the particular subtype of the Matrix.
      If the length of the vector does not match the size of the source matrix, or the argument contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      Specified by:
      multiply in class Matrix
      Parameters:
      vector - the vector to multiply the matrix by.
      Returns:
      an array of BigDecimal values containing the product.
      Throws:
      IllegalArgumentException - if the length of the array does not match the size of the matrix, or the argument contains non-numeric values (NaN or Infinity) or null
      NullPointerException - if the argument is null
    • multiply

      public Matrix multiply(double scalar) throws IllegalArgumentException
      Multiplies this instance of Matrix by a scalar factor scalar passed in as a double parameter, and creates and returns a new matrix containing the product. The exact subtype of the returned matrix is the same as that of this instance. If the argument is a non-numeric value (NaN or Infinity), throws IllegalArgumentException.
      Specified by:
      multiply in class Matrix
      Parameters:
      scalar - a double value to multiply this matrix by.
      Returns:
      a new BigDecimalMatrix containing the product of the source matrix and the given scalar.
      Throws:
      IllegalArgumentException - if the argument is NaN or Infinity.
    • multiply

      public Matrix multiply(Number scalar) throws IllegalArgumentException, NullPointerException
      Multiplies this instance of Matrix by a scalar factor scalar passed in as a Number parameter, and creates and returns a new matrix containing the product. The exact subtype of the returned matrix is the same as that of this instance.
      If the argument is a non-numeric value (NaN or Infinity) or null, throws IllegalArgumentException. Before the multiplication, the value of the argument is translated into the corresponding BigDecimal value by a method depending on the actual type of the argument.
      Specified by:
      multiply in class Matrix
      Parameters:
      scalar - a Number value to multiply this matrix by.
      Returns:
      a new BigDecimalMatrix containing the product of the source matrix and the given scalar.
      Throws:
      IllegalArgumentException - if the argument is NaN, Infinity or null.
      NullPointerException - if the argument is null
    • add

      Adds the given matrixB to this matrix and returns the sum.
      Computes the sum of this matrix and the Matrix passed in, and creates and returns a new Matrix containing the found sum. The exact subtype of the returned matrix is the same as that of this instance. If the size of the matrixB does not match the size of this instance of the matrix, throws IllegalArgumentException with a relevant message.
      Specified by:
      add in class Matrix
      Parameters:
      matrixB - the matrix to add to the source matrix.
      Returns:
      a new BigDecimalMatrix containing the sum of the two matrices.
      Throws:
      IllegalArgumentException - if the size of the matrixB does not match the size of this instance.
      NullPointerException - if the argument is null
    • add

      public Matrix add(double[][] matrixB) throws IllegalArgumentException, NullPointerException
      Adds the given matrixB passed in as a two-dimentional array of doubles to this matrix and returns the sum.
      Computes the sum of this matrix and the matrix passed in, and creates and returns a new Matrix containing the found sum. The exact subtype of the returned matrix is the same as that of this instance.
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or the argument contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Specified by:
      add in class Matrix
      Parameters:
      matrixB - the matrix to add to the source matrix.
      Returns:
      a new BigDecimalMatrix containing the sum of the two matrices.
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
    • add

      public Matrix add(Number[][] matrixB) throws IllegalArgumentException, NullPointerException
      Adds the given matrixB passed in as a two-dimentional array of Number to this matrix and returns the sum.
      Computes the sum of this matrix and the matrix passed in, and creates and returns a new Matrix containing the found sum. The exact subtype of the returned matrix is the same as that of this instance.
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or the argument contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      Specified by:
      add in class Matrix
      Parameters:
      matrixB - the matrix to add to the source matrix.
      Returns:
      a new BigDecimalMatrix containing the sum of the two matrices.
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance, or the argument contains non-numeric values (NaN or Infinity), or null.
      NullPointerException - if the argument is null
    • subtract

      public Matrix subtract(Matrix matrixB) throws IllegalArgumentException, NullPointerException
      Subtracts the given matrixB from this matrix and returns the difference.
      Computes the difference of this matrix and the Matrix passed in, and creates and returns a new Matrix containing the found difference. The exact subtype of the returned matrix is the same as that of this instance. If the size of the matrixB does not match the size of this instance of the matrix, throws IllegalArgumentException with a relevant message.
      Specified by:
      subtract in class Matrix
      Parameters:
      matrixB - the matrix to subtract from the source matrix.
      Returns:
      a new BigDecimalMatrix containing the difference of the two matrices.
      Throws:
      IllegalArgumentException - if the size of the matrixB does not match the size of this instance.
      NullPointerException - if the argument is null
    • subtract

      public Matrix subtract(double[][] matrixB) throws IllegalArgumentException, NullPointerException
      Subtracts the given matrixB passed in as a two-dimentional array of doubles from this matrix and returns the difference.
      Computes the difference of this matrix and the matrix passed in, creates and returns a new Matrix containing the found difference. The exact subtype of the returned matrix is the same as that of this instance.
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or the argument contains non-numeric values (NaN or Infinity), throws IllegalArgumentException with a relevant message.
      Specified by:
      subtract in class Matrix
      Parameters:
      matrixB - the matrix to subtract from the source matrix.
      Returns:
      a new BigDecimalMatrix containing the difference of the two matrices.
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance, or the argument contains non-numeric values (NaN or Infinity).
      NullPointerException - if the argument is null
    • subtract

      public Matrix subtract(Number[][] matrixB) throws IllegalArgumentException, NullPointerException
      Subtracts the given matrixB passed in as a two-dimentional array of Number from this matrix and returns the difference.
      Computes the difference of this matrix and the matrix passed in, creates and returns a new Matrix containing the found difference. The exact subtype of the returned matrix is the same as that of this instance.
      If the passed-in array is non-square, or its size does not match the size of this instance of the matrix, or the argument contains non-numeric values (NaN or Infinity) or null, throws IllegalArgumentException with a relevant message.
      Specified by:
      subtract in class Matrix
      Parameters:
      matrixB - the matrix to subtract from the source matrix.
      Returns:
      a new BigDecimalMatrix containing the difference of the two matrices.
      Throws:
      IllegalArgumentException - if the passed-in array is non-square, or its size does not match the size of this instance, or the argument contains non-numeric values (NaN or Infinity) or null.
      NullPointerException - if the argument is null
    • determinant

      public Number determinant()
      Computes the determinant of the matrix and returns its value as a Number value.
      The particular type of the returned Number depends on the exact subtype of this instance of Matrix (it is double for DoubleMatrix, Quadruple for QuadrupleMatrix, and BigDecimal for BigDecimalMatrix).
      Specified by:
      determinant in class Matrix
      Returns:
      the value of the determinant of the given Matrix as an instance of class BigDecimal
    • determinantAsDouble

      public double determinantAsDouble()
      Computes the determinant of the matrix and returns its value as a double value. BigDecimalMatrix#determinantAsDouble() returns the result of the corresponding computations rounded to the nearest double value.
      Specified by:
      determinantAsDouble in class Matrix
      Returns:
      the value of the determinant of the given Matrix
    • determinantAsQuadruple

      public Quadruple determinantAsQuadruple()
      Computes the determinant of the matrix and returns its value as a Quadruple value. The precision of the result depends on the particular subtype of the instance. BigDecimalMatrix#determinantAsQuadruple() returns a Quadruple value closest to the internally calculated BigDecimal value.
      Specified by:
      determinantAsQuadruple in class Matrix
      Returns:
      the value of the determinant of the given Matrix
    • determinantAsBigDecimal

      public BigDecimal determinantAsBigDecimal()
      Computes the determinant of the matrix and returns its value as a BigDecimal value. The precision of the result depends on the particular subtype of the instance. For BigDecimalMatrix, it is defined by the precision value of this BigDecimalMatrix instance.
      Specified by:
      determinantAsBigDecimal in class Matrix
      Returns:
      the value of the determinant of the given Matrix
    • norm

      public Number norm()
      Computes the row-based norm of the matrix, ║A, and returns its value as a Number value.
      The particular type of the returned Number depends on the exact subtype of this instance of Matrix (it is double for DoubleMatrix, Quadruple for QuadrupleMatrix, and BigDecimal for BigDecimalMatrix).
      Specified by:
      norm in class Matrix
      Returns:
      the value of the norm of the given Matrix as an instance of class BigDecimal
    • normAsDouble

      public double normAsDouble()
      Computes the row-based norm of the matrix, ║A, and returns its value as a double value. BigDecimalMatrix#normAsDouble() returns the result of the corresponding computations rounded to the nearest double value.
      Specified by:
      normAsDouble in class Matrix
      Returns:
      the value of the norm of the given Matrix
    • normAsQuadruple

      public Quadruple normAsQuadruple()
      Computes the row-based norm of the matrix, ║A, and returns its value as a Quadruple value. The precision of the result depends on the particular subtype of the instance. BigDecimalMatrix#normAsQuadruple() returns a Quadruple value closest to the internally calculated BigDecimal value.
      Specified by:
      normAsQuadruple in class Matrix
      Returns:
      the value of the norm of the given Matrix
    • normAsBigDecimal

      public BigDecimal normAsBigDecimal()
      Computes the row-based norm of the matrix, ║A, and returns its value as a BigDecimal value. The precision of the result depends on the particular subtype of the instance. BigDecimalMatrix returns a BigDecimal value exactly equal to the internally calculated value.
      Specified by:
      normAsBigDecimal in class Matrix
      Returns:
      the value of the norm of the given Matrix
    • cond

      public double cond()
      Computes the condition number of the matrix, ║A║•║A-1║, and returns its value as a double value.
      For non-invertible matrices returns Double.POSITIVE_INFINITY.
      Specified by:
      cond in class Matrix
      Returns:
      the value of the condition number of the given Matrix, or Double.POSITIVE_INFINITY for non-invertible matrices