Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#DIMENSIONS_MISMATCH_2x2

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#DIMENSIONS_MISMATCH_2x2 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**Solve  a  system of composed of a Lower Triangular Matrix
 * {@link RealMatrix}.
 * <p>
 * This method is called to solve systems of equations which are
 * of the lower triangular form. The matrix {@link RealMatrix}
 * is assumed, though not checked, to be in lower triangular form.
 * The vector {@link RealVector} is overwritten with the solution.
 * The matrix is checked that it is square and its dimensions match
 * the length of the vector.
 * </p>
 * @param rm RealMatrix which is lower triangular
 * @param b  RealVector this is overwritten
 * @exception IllegalArgumentException if the matrix and vector are not conformable
 * @exception ArithmeticException there is a zero or near zero on the diagonal of rm
 */
public static void solveLowerTriangularSystem( RealMatrix rm, RealVector b){
    if ((rm == null) || (b == null) || ( rm.getRowDimension() != b.getDimension())) {
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE,
                (rm == null) ? 0 : rm.getRowDimension(),
                (b == null) ? 0 : b.getDimension());
    }
    if( rm.getColumnDimension() != rm.getRowDimension() ){
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
                rm.getRowDimension(),rm.getRowDimension(),
                rm.getRowDimension(),rm.getColumnDimension());
    }
    int rows = rm.getRowDimension();
    for( int i = 0 ; i < rows ; i++ ){
        double diag = rm.getEntry(i, i);
        if( FastMath.abs(diag) < Precision.SAFE_MIN ){
            throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
        }
        double bi = b.getEntry(i)/diag;
        b.setEntry(i,  bi );
        for( int j = i+1; j< rows; j++ ){
            b.setEntry(j, b.getEntry(j)-bi*rm.getEntry(j,i)  );
        }
    }
}
 
Example 2
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Solver a  system composed  of an Upper Triangular Matrix
 * {@link RealMatrix}.
 * <p>
 * This method is called to solve systems of equations which are
 * of the lower triangular form. The matrix {@link RealMatrix}
 * is assumed, though not checked, to be in upper triangular form.
 * The vector {@link RealVector} is overwritten with the solution.
 * The matrix is checked that it is square and its dimensions match
 * the length of the vector.
 * </p>
 * @param rm RealMatrix which is upper triangular
 * @param b  RealVector this is overwritten
 * @exception IllegalArgumentException if the matrix and vector are not conformable
 * @exception ArithmeticException there is a zero or near zero on the diagonal of rm
 */
public static void solveUpperTriangularSystem( RealMatrix rm, RealVector b){
    if ((rm == null) || (b == null) || ( rm.getRowDimension() != b.getDimension())) {
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE,
                (rm == null) ? 0 : rm.getRowDimension(),
                (b == null) ? 0 : b.getDimension());
    }
    if( rm.getColumnDimension() != rm.getRowDimension() ){
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
                rm.getRowDimension(),rm.getRowDimension(),
                rm.getRowDimension(),rm.getColumnDimension());
    }
    int rows = rm.getRowDimension();
    for( int i = rows-1 ; i >-1 ; i-- ){
        double diag = rm.getEntry(i, i);
        if( FastMath.abs(diag) < Precision.SAFE_MIN ){
            throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
        }
        double bi = b.getEntry(i)/diag;
        b.setEntry(i,  bi );
        for( int j = i-1; j>-1; j-- ){
            b.setEntry(j, b.getEntry(j)-bi*rm.getEntry(j,i)  );
        }
    }
}
 
Example 3
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**Solve  a  system of composed of a Lower Triangular Matrix
 * {@link RealMatrix}.
 * <p>
 * This method is called to solve systems of equations which are
 * of the lower triangular form. The matrix {@link RealMatrix}
 * is assumed, though not checked, to be in lower triangular form.
 * The vector {@link RealVector} is overwritten with the solution.
 * The matrix is checked that it is square and its dimensions match
 * the length of the vector.
 * </p>
 * @param rm RealMatrix which is lower triangular
 * @param b  RealVector this is overwritten
 * @exception IllegalArgumentException if the matrix and vector are not conformable
 * @exception ArithmeticException there is a zero or near zero on the diagonal of rm
 */
public static void solveLowerTriangularSystem( RealMatrix rm, RealVector b){
    if ((rm == null) || (b == null) || ( rm.getRowDimension() != b.getDimension())) {
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE,
                (rm == null) ? 0 : rm.getRowDimension(),
                (b == null) ? 0 : b.getDimension());
    }
    if( rm.getColumnDimension() != rm.getRowDimension() ){
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
                rm.getRowDimension(),rm.getRowDimension(),
                rm.getRowDimension(),rm.getColumnDimension());
    }
    int rows = rm.getRowDimension();
    for( int i = 0 ; i < rows ; i++ ){
        double diag = rm.getEntry(i, i);
        if( FastMath.abs(diag) < Precision.SAFE_MIN ){
            throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
        }
        double bi = b.getEntry(i)/diag;
        b.setEntry(i,  bi );
        for( int j = i+1; j< rows; j++ ){
            b.setEntry(j, b.getEntry(j)-bi*rm.getEntry(j,i)  );
        }
    }
}
 
Example 4
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Solver a  system composed  of an Upper Triangular Matrix
 * {@link RealMatrix}.
 * <p>
 * This method is called to solve systems of equations which are
 * of the lower triangular form. The matrix {@link RealMatrix}
 * is assumed, though not checked, to be in upper triangular form.
 * The vector {@link RealVector} is overwritten with the solution.
 * The matrix is checked that it is square and its dimensions match
 * the length of the vector.
 * </p>
 * @param rm RealMatrix which is upper triangular
 * @param b  RealVector this is overwritten
 * @exception IllegalArgumentException if the matrix and vector are not conformable
 * @exception ArithmeticException there is a zero or near zero on the diagonal of rm
 */
public static void solveUpperTriangularSystem( RealMatrix rm, RealVector b){
    if ((rm == null) || (b == null) || ( rm.getRowDimension() != b.getDimension())) {
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE,
                (rm == null) ? 0 : rm.getRowDimension(),
                (b == null) ? 0 : b.getDimension());
    }
    if( rm.getColumnDimension() != rm.getRowDimension() ){
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
                rm.getRowDimension(),rm.getRowDimension(),
                rm.getRowDimension(),rm.getColumnDimension());
    }
    int rows = rm.getRowDimension();
    for( int i = rows-1 ; i >-1 ; i-- ){
        double diag = rm.getEntry(i, i);
        if( FastMath.abs(diag) < Precision.SAFE_MIN ){
            throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
        }
        double bi = b.getEntry(i)/diag;
        b.setEntry(i,  bi );
        for( int j = i-1; j>-1; j-- ){
            b.setEntry(j, b.getEntry(j)-bi*rm.getEntry(j,i)  );
        }
    }
}
 
Example 5
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}
 
Example 6
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}
 
Example 7
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}
 
Example 8
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}
 
Example 9
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}
 
Example 10
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}
 
Example 11
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}
 
Example 12
Source File: MatrixDimensionMismatchException.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an exception from the mismatched dimensions.
 *
 * @param wrongRowDim Wrong row dimension.
 * @param wrongColDim Wrong column dimension.
 * @param expectedRowDim Expected row dimension.
 * @param expectedColDim Expected column dimension.
 */
public MatrixDimensionMismatchException(int wrongRowDim,
                                        int wrongColDim,
                                        int expectedRowDim,
                                        int expectedColDim) {
    super(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
          new Integer[] { wrongRowDim, wrongColDim },
          new Integer[] { expectedRowDim, expectedColDim });
}