Package com.mvohm.quadmatrix
Class QuadrupleMatrix
java.lang.Object
com.mvohm.quadmatrix.Matrix
com.mvohm.quadmatrix.QuadrupleMatrix
An implementation of the abstract class
Matrix that uses an array of
Quadruple values to store the internal data and arithmetic provided by Quadruple
to perform calculations.
- Author:
- M.Vokhmentsev
-
Constructor Summary
ConstructorsConstructorDescriptionQuadrupleMatrix(double[][] source) Creates a newQuadrupleMatrixwhose inner data are obtained by converting the values of the givensourcearray into correspondingQuadruplevalues without precision loss, and the default value of theneedToScaleflag.QuadrupleMatrix(double[][] source, boolean needToScale) Creates a newQuadrupleMatrixwhose inner data are obtained by converting the values of the givensourcearray into correspondingQuadruplevalues without precision loss, and the specified value of theneedToScaleflag that is passed in as theneedToScaleargument.QuadrupleMatrix(Matrix source) Creates a newQuadrupleMatrixwith a copy of the data of the givensourcematrix and the default value of theneedToScaleflag.QuadrupleMatrix(Matrix source, boolean needToScale) Creates a newQuadrupleMatrixwith a copy of the data of the givensourcematrix and the value of theneedToScaleflag that is passed in as theneedToScaleargument.QuadrupleMatrix(Number[][] source) Creates a newQuadrupleMatrixwith a copy of the data of the givensourcearray and the default value of theneedToScaleflag.QuadrupleMatrix(Number[][] source, boolean needToScale) Creates a newQuadrupleMatrixwith a copy of the data of the givensourcearray and the specified value of theneedToScaleflag. -
Method Summary
Modifier and TypeMethodDescriptionadd(double[][] matrixB) Adds the givenmatrixBpassed in as a two-dimentional array ofdoubles to this matrix and returns the sum.Adds the givenmatrixBto this matrix and returns the sum.Adds the givenmatrixBpassed in as a two-dimentional array of Number to this matrix and returns the sum.doublecond()Computes the condition number of the matrix, ║A║•║A-1║, and returns its value as adoublevalue.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.doubleComputes the determinant of the matrix and returns its value as adoublevalue.Computes the determinant of the matrix and returns its value as a Quadruple value.booleanIndicates whether the otherMatrixis equal to this one.BigDecimal[][]Returns a two-dimentional array ofBigDecimalinstances containing the values of the corresponding matrix elements.BigDecimal[][]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[][]getData()Returns a two-dimentional array ofNumbercontaining the values of the corresponding matrix elements.static booleanReturns the value of the static#scaleByDefaultflag that is used to set corresponding instance flags when creating a new instances by constructors withoutneedToScaleparameter.double[][]Returns a two-dimentional array of primitivedoublevalues 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 primitivedoubles.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 ofdoubles.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 aMatrix.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.Quadruple[][]Returns a two-dimentional array ofQuadrupleinstances containing the values of the corresponding matrix elements, perhaps rounded.Quadruple[][]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.booleanReturns the value of an internal flag that defines whether row scaling will be applied while solving a system by this instance of Matrix.Number[]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.inthashCode()Returns a hash code value for theMatrix.inverse()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 ofMatrixby a scalar factorscalarpassed in as adoubleparameter, and creates and returns a new matrix containing the product.Number[]multiply(double[] vector) Multiplies this instance ofMatrixby a vector passed in as an array ofdoubles, and returns an array of Number values containing the product.multiply(double[][] factor) Multiplies this instance ofMatrixby thefactorpassed in as a two-dimentional double array, and creates and returns a new matrix containing the product.Multiplies this instance ofMatrixby the matrix passed in as thefactorargument, creates and returns a new matrix containing the product.Multiplies this instance ofMatrixby a scalar factorscalarpassed in as a Number parameter, and creates and returns a new matrix containing the product.Number[]Multiplies this instance ofMatrixby thefactorpassed in as a two-dimentional array ofNumbers, and creates and returns a new matrix containing the product.norm()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.doubleComputes the row-based norm of the matrix, ║A║∞, and returns its value as adoublevalue.Computes the row-based norm of the matrix, ║A║∞, and returns its value as a Quadruple value.static voidsetDefaultScaling(boolean scaleByDefault) Sets the value of the staticscaleByDefaultflag that is used to set corresponding instance flags when creating a new instances by constructors withoutneedToScaleparameter.Number[]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.Solves a matrix equation of form AX = B and returns the found solution.Number[]Solves a system of linear equations of form Ax = b and returns the found solution.Solves a matrix equation of form AX = B and returns the found solution.Number[]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.solveAccurately(Matrix matrixB) Solves a matrix equation of form AX = B and returns the found solution.Number[]solveAccurately(Number[] vector) 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.Number[]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.Number[]Solves a system of linear equations of form Ax = b for a symmetric positively-defined matrix of coefficients and returns the found solution.Number[]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.Number[]solveSPDAccurately(Number[] 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.subtract(double[][] matrixB) Subtracts the givenmatrixBpassed in as a two-dimentional array ofdoubles from this matrix and returns the difference.Subtracts the givenmatrixBfrom this matrix and returns the difference.Subtracts the givenmatrixBpassed 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.unity()Creates and returns a new Matrix instance containing a unity matrix of the same size as the source matrix.
-
Constructor Details
-
QuadrupleMatrix
Creates a newQuadrupleMatrixwith a copy of the data of the givensourcematrix and the default value of theneedToScaleflag.
Uses static scaleByDefault value to set the new matrix'sneedToScaleflag designating necessity to scale matrix rows before solving equation systems and inverting.- Parameters:
source- a matrix whose data get copied into the new Matrix's internal storage.- See Also:
-
QuadrupleMatrix
Creates a newQuadrupleMatrixwith a copy of the data of the givensourcematrix and the value of theneedToScaleflag that is passed in as theneedToScaleargument.
Uses the givenneedToScalevalue to set the new matrix'sneedToScaleflag designating necessity to scale matrix rows while solving equation systems and inverting. The value of this flag can be obtained viagetScaling()instance method.- 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:
-
QuadrupleMatrix
public QuadrupleMatrix(double[][] source) Creates a newQuadrupleMatrixwhose inner data are obtained by converting the values of the givensourcearray into correspondingQuadruplevalues without precision loss, and the default value of theneedToScaleflag.
Uses static scaleByDefault value to set the new matrix'sneedToScaleflag designating necessity to scale matrix rows before solving equation systems and inverting.
Throws IllegalArgumentException if thesourceargument is a non-square or empty array, or contains non-numeric values,Double.NaN,Double.NEGATIVE_INFINITY, orDouble.POSITIVE_INFINITY.- Parameters:
source- a two-dimentional square array ofdoubles to be converted into theQuadruplevalues of the internal storage of this instance.- See Also:
-
setDefaultScaling(boolean)scaleByDefault
-
QuadrupleMatrix
public QuadrupleMatrix(double[][] source, boolean needToScale) Creates a newQuadrupleMatrixwhose inner data are obtained by converting the values of the givensourcearray into correspondingQuadruplevalues without precision loss, and the specified value of theneedToScaleflag that is passed in as theneedToScaleargument.
Uses the givenneedToScalevalue to set the new matrix'sneedToScaleflag designating necessity to scale matrix rows before solving equation systems and inverting. The value of this flag can be obtained viagetScaling()instance method.
Throws IllegalArgumentException if thesourceargument is a non-square or empty array, or contains non-numeric values,Double.NaN,Double.NEGATIVE_INFINITY, orDouble.POSITIVE_INFINITY.- Parameters:
source- a two-dimentional square array ofdoubles to be converted into theQuadruplevalues of the internal storage of this instance.needToScale- the value defining necessity to scale rows while solving equation systems and inverting.- See Also:
-
setDefaultScaling(boolean)scaleByDefault
-
QuadrupleMatrix
Creates a newQuadrupleMatrixwith a copy of the data of the givensourcearray and the default value of theneedToScaleflag.
Translates the values of the specifiedsourcearray toQuadruplevalues usingQuadrupleconstructors depending on the actual element type of the source array.
Uses static scaleByDefault value to set the new matrix'sneedToScaleflag designating necessity to scale matrix rows before solving equation systems and inverting.
Throws IllegalArgumentException if thesourceargument is a non-square or empty array, or contains non-numeric values,Double.NaN,Double.NEGATIVE_INFINITYorDouble.POSITIVE_INFINITY), ornull.- Parameters:
source- a two-dimentional square array of Number values to be copied into the internal storage of this instance.- See Also:
-
QuadrupleMatrix
Creates a newQuadrupleMatrixwith a copy of the data of the givensourcearray and the specified value of theneedToScaleflag.
Translates the values of the specifiedsourcearray toQuadruplevalues usingQuadrupleconstructors depending on the actual element type of the source array.
Uses the givenneedToScalevalue to set the new matrix'sneedToScaleflag designating necessity to scale matrix rows while solving equation systems and inverting. The value of this flag can be obtained viagetScaling()instance method.
Uses static scaleByDefault value to set the new matrix'sneedToScaleflag designating necessity to scale matrix rows before solving equation systems and inverting.
Throws IllegalArgumentException if thesourceargument is a non-square or empty array, or contains non-numeric values,Double.NaN,Double.NEGATIVE_INFINITYorDouble.POSITIVE_INFINITY), ornull.- Parameters:
source- a two-dimentional square array of Number values to be copied into the internal storage of this instance.needToScale- the value defining necessity to scale rows while solving equation systems and inverting.
-
-
Method Details
-
setDefaultScaling
public static void setDefaultScaling(boolean scaleByDefault) Sets the value of the staticscaleByDefaultflag that is used to set corresponding instance flags when creating a new instances by constructors withoutneedToScaleparameter.
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 ofneedToScaleflag to set for new matrices created with constructors withoutneedToScaleparameter.
-
getDefaultScaling
public static boolean getDefaultScaling()Returns the value of the static#scaleByDefaultflag that is used to set corresponding instance flags when creating a new instances by constructors withoutneedToScaleparameter.- Returns:
- the value of the static
#scaleByDefaultflag - 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 totrue, 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 methodsetScaling()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:
getScalingin classMatrix- Returns:
- the value of the flag that defines whether the scaling will be applied while solving a system by this instance of Matrix
-
getData
Returns a two-dimentional array ofNumbercontaining 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.
QuadrupleMatrix returns a copy of the internal matrix data as a two-dimentional array ofQuadruple. -
getDoubleData
public double[][] getDoubleData()Returns a two-dimentional array of primitivedoublevalues 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 bydouble, the values get rounded to the nearest possibledoublevalue.
If the value of an internal data element exceeds the range ofdoublevalues, it gets converted to Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY, depending on its sign.
QuadrupleMatrix returns an array containing values of the internal matrix data rounded to nearestdoublevalues.- Specified by:
getDoubleDatain classMatrix- Returns:
- a two-dimentional array of primitive
doublevalues containing rounded values of the corresponding elements of the internal data array
-
getQuadrupleData
Returns a two-dimentional array ofQuadrupleinstances 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 byQuadruple, the values get rounded to the nearest possibleQuadruplevalue.
If the value of an internal data element exceeds the range ofQuadruplevalues, it gets converted to Quadruple.POSITIVE_INFINITY or Quadruple.NEGATIVE_INFINITY, depending on its sign.
QuadrupleMatrix returns an array containing the exact values of the corresponding elements of the internal storage.- Specified by:
getQuadrupleDatain classMatrix- Returns:
- a two-dimentional array of
Quadruplevalues containing the values of the corresponding matrix elements, perhaps rounded.
-
getBigDecimalData
Returns a two-dimentional array ofBigDecimalinstances containing the values of the corresponding matrix elements.
If the type of the internal data of the particular class isdoublethen the correspondingBigDecimalvalues are obtained using BigDecimal.valueOf(double) method. If the type of the internal data of the particular class isQuadruplethen the correspondingBigDecimalvalues are obtained using Quadruple.bigDecimalValue() method. If an internal data element is not convertible toBigDecimal(i.e. it is NaN or Infinity), throwsNumberFormatException.
QuadrupleMatrix returns an array containing the values of the corresponding elements of the internal storage, translated to BigDecimal values using Quadruple.bigDecimalValue().- Specified by:
getBigDecimalDatain classMatrix- Returns:
- a two-dimentional array of
BigDecimalvalues containing the values of the corresponding matrix elements translated toBigDecimalinstances.
-
equals
Indicates whether the otherMatrixis 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 theirneedToScaleflags are equal.
Under those condition, the matrices yield equal results for all operations performed on them. -
hashCode
public int hashCode()Returns a hash code value for theMatrix.
It is guaranteed, that for two matrices returning different hashcodes theirMatrix.equals(Object)methods returnfalse, 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. -
solve
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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the length of thevectordoes not match the size of the matrix, or the argument contains non-numeric values (NaN or Infinity), throwsIllegalArgumentExceptionwith a relevant message.
Before solving the equation, the values of thevectorargument get converted toQuadruplevalues, usingQuadruple(double)constructor.- Specified by:
solvein classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofdoubles- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- See Also:
-
solve
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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the length of thevectordoes not match the size of the matrix, orvectorcontains non-numeric values (NaNorInfinity) ornull, throwsIllegalArgumentExceptionwith a relevant message. Before solving the equation, the values of thevectorargument get converted to exactly equal or nearest possibleQuadruplevalues, depending on the particular type of thevectorelements.- Specified by:
solvein classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofNumbers- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- See Also:
-
solveSPD
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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the length of thevectordoes not match the size of the matrix, or the argument contains non-numeric values (NaN or Infinity), throwsIllegalArgumentExceptionwith a relevant message.
Before solving the equation, the values of thevectorargument get converted toQuadruplevalues, usingQuadruple(double)constructor.- Specified by:
solveSPDin classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofNumbers- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- See Also:
-
solveSPD
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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the length of thevectordoes not match the size of the matrix, orvectorcontains non-numeric values (NaNorInfinity) ornull, throwsIllegalArgumentExceptionwith a relevant message. Before solving the equation, the values of thevectorargument get converted to exactly equal or nearest possibleQuadruplevalues, depending on the particular type of thevectorelements.- Specified by:
solveSPDin classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofNumbers- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- 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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the length of thevectordoes not match the size of the matrix, orvectorcontains non-numeric values (NaN or Infinity), throwsIllegalArgumentExceptionwith a relevant message.
The execution time is about 50% longer than that of the simple solve(double[]). In a typical case, the result error is reduced, compared to the simplesolve(), 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, average square root of MSE is reduced by approximately 40 times, from about 2.5e-37 down to 6.3e-39.- Specified by:
solveAccuratelyin classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofdoubles- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- 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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the length of thevectordoes not match the size of the matrix, orvectorcontains non-numeric values (NaNorInfinity) ornull, throwsIllegalArgumentExceptionwith a relevant message.
Before solving the equation, the values of thevectorargument get converted to exactly equal or nearest possibleQuadruplevalues, depending on the particular type of thevectorelements.
The execution time is about 50% longer than that of the simple solve(Number[]). In a typical case, the result error is reduced, compared to the simplesolve(), 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, average square root of MSE is reduced by approximately 40 times, from about 2.5e-37 down to 6.3e-39.- Specified by:
solveAccuratelyin classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofNumbers- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- 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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the length of thevectordoes not match the size of the matrix, orvectorcontains non-numeric values (NaN or Infinity), throwsIllegalArgumentExceptionwith a relevant message.
The execution time is about 75% longer than that of the simple solveSPD(double[]). In a typical case, the result error is reduced, compared to the simplesolveSPD(), by a factor of several units, depending on the properties of the specific matrix data.
For matrices 150 x 150, average square root of MSE is reduced by approximately 5 times, from about 3.5e-38 down to 7.0e-39.- Specified by:
solveSPDAccuratelyin classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofdoubles- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- 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 thevectorargument, 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode(). If the length of thevectordoes not match the size of the matrix, orvectorcontains non-numeric values (NaNorInfinity) ornullthrowsIllegalArgumentExceptionwith a relevant message.
Before solving the equation, the values of thevectorargument get converted to exactly equal or nearest possibleQuadruplevalues, depending on the particular type of thevectorelements.
The execution time is about 75% longer than that of the simple solveSPD(double[]). In a typical case, the result error is reduced, compared to the simplesolveSPD(), by a factor of several units, depending on the properties of the specific matrix data.
For matrices 150 x 150, average square root of MSE is reduced by approximately 5 times, from about 3.5e-38 down to 7.0e-39.- Specified by:
solveSPDAccuratelyin classMatrix- Parameters:
vector- the column vector b of the equation to be solved, Ax = b, as an array ofdoubles- 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
QuadrupleMatrixisQuadruple. - Throws:
IllegalArgumentException- if the length of thevectordoes 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 isnull- See Also:
-
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 theMatrix, returnsnull.- Specified by:
getSolutionin classMatrix- 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
Quadruples, ornull, 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 ofdoubles.
If the particular subtype of the instance stores internal data with higher precision than that provided bydouble, the values of the elements of the returned vector get rounded to the nearestdoublevalues.
If no system was solved with this instance of theMatrix, returnsnull.
The elements of the array returned byQudrupleMatrixare corresponded values of the found solution, rounded to the closestdoublevalues- Specified by:
getDoubleSolutionin classMatrix- 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. ornull, if no system was solved with the matrix.
-
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 byQuadruple, the values of the elements of the returned vector get rounded to the nearestdoublevalues.
If no system was solved with this instance of theMatrix, returnsnull.QudrupleMatrixreturns the exact values that was found by the corresponding solution method.- Specified by:
getQuadrupleSolutionin classMatrix- 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
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 theMatrix, returnsnull.
If the solution contains values that can't be translated toBigDeciaml(NaNorInfinity), throwsNumberFormatException.QuadrupleMatrixtranslatesQuadruplevalues of the internally stored solution toBigDecimalvalues, usingQuadruple.bigDecimalValue()method.- Specified by:
getBigDecimalSolutionin classMatrix- 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
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
- Specified by:
getErrorCodein classMatrix- 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 theMatrix matrixBargument, using LU decomposition.
In case of an inconsistent or underdefined matrix throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode(). If the size of thematrixBdoes not match the size of this instance of the matrix, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
solvein classMatrix- 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
QuadrupleMatrix. - Throws:
IllegalArgumentException- if the size of thematrixBdoes not match the size of this instance or the system has no solution or has infinitely many solutions.NullPointerException- if the argument isnull- See Also:
-
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 thedouble[][] matrixBargument, using LU decomposition.
In case of an inconsistent or underdefined matrix throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, 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), throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
solvein classMatrix- Parameters:
matrixB- the matrix B of the equation to be solved, AX = B, as a two-dimentional array of primitivedoubles- Returns:
- the found solution X to the equation AX = B
as a new instance of
QuadrupleMatrix. - 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 (NaNorInfinity).NullPointerException- if the argument isnull- See Also:
-
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 theNumber[][] matrixBargument, using LU decomposition.
Before solving, the givenmatrixBarray 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, 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, ormatrixBcontains non-numeric values (NaNorInfinity) ornull, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
solvein classMatrix- 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
QuadrupleMatrix. - 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 isnull- See Also:
-
solveAccurately
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 thematrixBargument, using LU decomposition.
Uses an iterative refinement to find a more accurate solution.
In case of an inconsistent or underdefined matrix throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
If the size of thematrixBdoes not match the size of this instance of the matrix, throwsIllegalArgumentExceptionwith a relevant message.
The execution time is about 30 times longer than that of the simple solve(Matrix). In a typical case, the result error is reduced, compared to the simplesolve(), by a factor from several units to several tens, depending on specific values of the matrix elements. For matrices 200 x 200 with uniformly-distributed random values, average square root of MSE is reduced by approximately 40 times, from about 1.2e-36 down to about 3.0e-38.- Specified by:
solveAccuratelyin classMatrix- 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
QuadrupleMatrix. - Throws:
IllegalArgumentException- if the size of thematrixBdoes not match the size of this instance or the system has no solution or has infinitely many solutions.NullPointerException- if the argument isnull- 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 thedouble[][] matrixBargument, using LU decomposition.
Uses an iterative refinement to find a more accurate solution. In case of an inconsistent or underdefined matrix throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, 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), throwsIllegalArgumentExceptionwith a relevant message.
The execution time is about 30 times longer than that of the simple solve(Matrix). In a typical case, the result error is reduced, compared to the simplesolve(), by a factor from several units to several tens, depending on specific values of the matrix elements. For matrices 200 x 200 with uniformly-distributed random values, average square root of MSE is reduced by approximately 40 times, from about 1.2e-36 down to about 3.0e-38.- Specified by:
solveAccuratelyin classMatrix- Parameters:
matrixB- the matrix B of the equation to be solved, AX = B, as a two-dimentional array of primitivedoubles- Returns:
- the found solution X to the equation AX = B
as a new instance of
QuadrupleMatrix. - Throws:
IllegalArgumentException- if the size of thematrixBdoes 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 isnull- 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 theNumber[][] matrixBargument, using LU decomposition.
Before solving, the givenmatrixBarray 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 throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, 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, ormatrixBcontains non-numeric values (NaNorInfinity) ornull, throwsIllegalArgumentExceptionwith a relevant message.
The execution time is about 30 times longer than that of the simple solve(Matrix). In a typical case, the result error is reduced, compared to the simplesolve(), by a factor from several units to several tens, depending on specific values of the matrix elements. For matrices 200 x 200 with uniformly-distributed random values, average square root of MSE is reduced by approximately 40 times, from about 1.2e-36 down to about 3.0e-38.- Specified by:
solveAccuratelyin classMatrix- 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
QuadrupleMatrix. - Throws:
IllegalArgumentException- if the size of thematrixBdoes 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 isnull- See Also:
-
getMatrixSolution
Returns the last of the previously found matrix solutions, X, to a matrix equation of form AX = B, as aMatrix. If no matrix equation was solved with this instance of theMatrix, returnsnull.- Specified by:
getMatrixSolutionin classMatrix- Returns:
- the last of the previously found matrix solution X to a system of
linear equations of form AX = B, as a
QuadrupleMatrix, ornull, if no matrix equation was solved with the matrix.
-
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 ofMatrix(it is Double for DoubleMatrix, Quadruple for QuadrupleMatrix, etc).
If no matrix equation was solved with this instance of theMatrix, returnsnull.QuadrupleMatrix#getNumberMatrixSolution()returns the exact values of the elements of the matrix solution found by the call to one of theQuadrupleMatrix#solve()orQuadrupleMatrix#solveAccurately()methods.- Specified by:
getNumberMatrixSolutionin classMatrix- 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 Quadruple,
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 primitivedoubles.
If no matrix equation was solved with this instance of theMatrix, returnsnull.
The returned array contains the values of the elements of the matrix solution found by a call to one of theQuadrupleMatrix#solve()orQuadrupleMatrix#solveAccurately()methods, rounded to nearestdoublevalues.- Specified by:
getDoubleMatrixSolutionin classMatrix- 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, ornull, if no matrix equation was solved with the matrix.
-
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 theMatrix, returnsnull.
The returned array contains the exact values of the elements of the matrix solution found by a call to one of theQuadrupleMatrix#solve()orQuadrupleMatrix#solveAccurately()methods.- Specified by:
getQuadrupleMatrixSolutionin classMatrix- 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
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 theMatrix, returnsnull.
The returned array contains the values of the elements of the matrix solution found by a call to one of theQuadrupleMatrix#solve()orQuadrupleMatrix#solveAccurately()methods, translated to BigDecimal values using Quadruple.bigDecimalValue() method. If the internal storage contains element that can't be translated to BigDecimal values (NaN or Infinity), throws NumberFormatException.- Specified by:
getBigDecimalMatrixSolutionin classMatrix- 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
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 newMatrixcontaining 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), throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, whose value can be obtained using method Matrix.getErrorCode().
The particular subtype ofMatrixreturned byQuadrupleMatrix#inverse()isQuadrupleMatrix.- Specified by:
inversein classMatrix- Returns:
- a new
Matrixcontaining the inversion of the given matrix. - Throws:
IllegalArgumentException- if the matrix is not invertible (i.e. inconsistent or underdefined)
-
inverseAccurately
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 newMatrixcontaining 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), throwsIllegalArgumentExceptionwith a relevant message and sets internal variableerrorCode, 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 simpleinverse(), by a factor of several units, depending on specific values of the matrix elements. For matrices 200 x 200 with uniformly-distributed random values, average square root of MSE is reduced by approximately 5 times, from about 2.0e-37 down to about 4.0e-38- Specified by:
inverseAccuratelyin classMatrix- Returns:
- a new
QuadrupleMatrixcontaining the inversion of the given matrix. - Throws:
IllegalArgumentException- if the matrix is not invertible (i.e. inconsistent or underdefined)
-
transpose
Creates and returns a new Matrix instance containing the transposition of this instance.
Computes the transposition of the matrix, creates and returns a newMatrixcontaining the found transposition.
The exact subtype of the returned matrix is the same as that of this instance. -
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. -
multiply
Multiplies this instance ofMatrixby the matrix passed in as thefactorargument, 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 thefactordoes not match the size of the source matrix, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
multiplyin classMatrix- Parameters:
factor- a matrix to multiply this instance by- Returns:
- a new
QuadrupleMatrixrepresenting the product - Throws:
IllegalArgumentException- if the size of the argument does not match the size of this instanceNullPointerException- if the argument isnull
-
multiply
Multiplies this instance ofMatrixby thefactorpassed 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, ormatrixBcontains non-numeric values (NaNorInfinity), throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
multiplyin classMatrix- Parameters:
factor- two-dimentional double array representing a matrix to multiply this instance by- Returns:
- a new
QuadrupleMatrixrepresenting 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, ormatrixBcontains non-numeric values (NaNorInfinity)NullPointerException- if the argument isnull
-
multiply
Multiplies this instance ofMatrixby thefactorpassed in as a two-dimentional array ofNumbers, 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, ormatrixBcontains non-numeric values (NaNorInfinity) ornull, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
multiplyin classMatrix- Parameters:
factor- two-dimentional array of Number representing the matrix to multiply this instance by- Returns:
- a new
QuadrupleMatrixrepresenting 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, ormatrixBcontains non-numeric values (NaNorInfinity) ornullNullPointerException- if the argument isnull
-
multiply
Multiplies this instance ofMatrixby a vector passed in as an array ofdoubles, 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 theMatrix.
If the length of thevectordoes not match the size of the source matrix, or the argument contains non-numeric values (NaN or Infinity), throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
multiplyin classMatrix- Parameters:
vector- the vector to multiply the matrix by.- Returns:
- an array of Quadruple 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 isnull
-
multiply
Multiplies this instance ofMatrixby 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 theMatrix.
If the length of thevectordoes not match the size of the source matrix, or the argument contains non-numeric values (NaN or Infinity) ornull,throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
multiplyin classMatrix- Parameters:
vector- the vector to multiply the matrix by.- Returns:
- an array of Quadruple 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) ornullNullPointerException- if the argument isnull
-
multiply
Multiplies this instance ofMatrixby a scalar factorscalarpassed in as adoubleparameter, 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 (NaNorInfinity), throws IllegalArgumentException.- Specified by:
multiplyin classMatrix- Parameters:
scalar- adoublevalue to multiply this matrix by.- Returns:
- a new
QuadrupleMatrixcontaining the product of the source matrix and the given scalar. - Throws:
IllegalArgumentException- if the argument isNaNorInfinity.
-
multiply
Multiplies this instance ofMatrixby a scalar factorscalarpassed 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 (NaNorInfinity) or null, throws IllegalArgumentException. Before the multiplication, the value of the argument is translated into the correspondingQuadrupleby one of theQuadrupleconstructors, depending on the actual type of the argument.- Specified by:
multiplyin classMatrix- Parameters:
scalar- a Number value to multiply this matrix by.- Returns:
- a new
QuadrupleMatrixcontaining the product of the source matrix and the given scalar. - Throws:
IllegalArgumentException- if the argument isNaN,Infinityor null.NullPointerException- if the argument isnull
-
add
Adds the givenmatrixBto this matrix and returns the sum.
Computes the sum of this matrix and theMatrixpassed in, and creates and returns a newMatrixcontaining the found sum. The exact subtype of the returned matrix is the same as that of this instance. If the size of thematrixBdoes not match the size of this instance of the matrix, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
addin classMatrix- Parameters:
matrixB- the matrix to add to the source matrix.- Returns:
- a new
QuadrupleMatrixcontaining the sum of the two matrices. - Throws:
IllegalArgumentException- if the size of thematrixBdoes not match the size of this instance.NullPointerException- if the argument isnull
-
add
Adds the givenmatrixBpassed in as a two-dimentional array ofdoubles to this matrix and returns the sum.
Computes the sum of this matrix and the matrix passed in, and creates and returns a newMatrixcontaining 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), throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
addin classMatrix- Parameters:
matrixB- the matrix to add to the source matrix.- Returns:
- a new
QuadrupleMatrixcontaining 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 (NaNorInfinity).NullPointerException- if the argument isnull
-
add
Adds the givenmatrixBpassed 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 newMatrixcontaining 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) ornull, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
addin classMatrix- Parameters:
matrixB- the matrix to add to the source matrix.- Returns:
- a new
QuadrupleMatrixcontaining 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 (NaNorInfinity), ornull.NullPointerException- if the argument isnull
-
subtract
Subtracts the givenmatrixBfrom this matrix and returns the difference.
Computes the difference of this matrix and theMatrixpassed in, and creates and returns a newMatrixcontaining the found difference. The exact subtype of the returned matrix is the same as that of this instance. If the size of thematrixBdoes not match the size of this instance of the matrix, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
subtractin classMatrix- Parameters:
matrixB- the matrix to subtract from the source matrix.- Returns:
- a new
QuadrupleMatrixcontaining the difference of the two matrices. - Throws:
IllegalArgumentException- if the size of thematrixBdoes not match the size of this instance.NullPointerException- if the argument isnull
-
subtract
Subtracts the givenmatrixBpassed in as a two-dimentional array ofdoubles from this matrix and returns the difference.
Computes the difference of this matrix and the matrix passed in, creates and returns a newMatrixcontaining 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), throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
subtractin classMatrix- Parameters:
matrixB- the matrix to subtract from the source matrix.- Returns:
- a new
QuadrupleMatrixcontaining 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 (NaNorInfinity).NullPointerException- if the argument isnull
-
subtract
Subtracts the givenmatrixBpassed 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 newMatrixcontaining 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) ornull, throwsIllegalArgumentExceptionwith a relevant message.- Specified by:
subtractin classMatrix- Parameters:
matrixB- the matrix to subtract from the source matrix.- Returns:
- a new
QuadrupleMatrixcontaining 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 (NaNorInfinity) ornull.NullPointerException- if the argument isnull
-
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 ofMatrix(it isdoublefor DoubleMatrix, Quadruple for QuadrupleMatrix, and BigDecimal for BigDecimalMatrix).- Specified by:
determinantin classMatrix- Returns:
- the value of the determinant of the given
Matrixas an instance of classQuadruple
-
determinantAsDouble
public double determinantAsDouble()Computes the determinant of the matrix and returns its value as adoublevalue.QuadrupleMatrix#determinantAsDouble()returns the result of the corresponding computations rounded to the nearestdoublevalue.- Specified by:
determinantAsDoublein classMatrix- Returns:
- the value of the determinant of the given
Matrix
-
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.QuadrupleMatrix#determinantAsQuadruple()returns aQuadruplevalue exactly equal to the internally calculatedQuadruplevalue.- Specified by:
determinantAsQuadruplein classMatrix- Returns:
- the value of the determinant of the given
Matrix
-
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. ForQuadrupleMatrix, it is limited to the precision provided by calculations withQuadruples.- Specified by:
determinantAsBigDecimalin classMatrix- Returns:
- the value of the determinant of the given
Matrix
-
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 ofMatrix(it isdoublefor DoubleMatrix, Quadruple for QuadrupleMatrix, and BigDecimal for BigDecimalMatrix). -
normAsDouble
public double normAsDouble()Computes the row-based norm of the matrix, ║A║∞, and returns its value as adoublevalue.QuadrupleMatrix#normAsDouble()returns the result of the corresponding computations rounded to the nearestdoublevalue.- Specified by:
normAsDoublein classMatrix- Returns:
- the value of the norm of the given
Matrix
-
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.QuadrupleMatrix#normAsQuadruple()returns aQuadruplevalue exactly equal to the internally calculated value.- Specified by:
normAsQuadruplein classMatrix- Returns:
- the value of the norm of the given
Matrix
-
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. ForQuadrupleMatrix, it is limited to the precision provided by calculations withQuadruples.- Specified by:
normAsBigDecimalin classMatrix- 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 adoublevalue.
For non-invertible matrices returnsDouble.POSITIVE_INFINITY.
-