Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#ZERO_DENOMINATOR
The following examples show how to use
org.apache.commons.math.exception.util.LocalizedFormats#ZERO_DENOMINATOR .
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 |
/**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) < MathUtils.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 |
/** 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) < MathUtils.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 |
/**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) < MathUtils.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 |
/** 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) < MathUtils.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: Math_36_BigFraction_t.java From coming with MIT License | 5 votes |
/** * Create a {@link BigFraction} given the numerator and denominator as * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms. * * @param num the numerator, must not be {@code null}. * @param den the denominator, must not be {@code null}. * @throws ZeroException if the denominator is zero. * @throws NullArgumentException if either of the arguments is null */ public BigFraction(BigInteger num, BigInteger den) { MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR); MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR); if (BigInteger.ZERO.equals(den)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } if (BigInteger.ZERO.equals(num)) { numerator = BigInteger.ZERO; denominator = BigInteger.ONE; } else { // reduce numerator and denominator by greatest common denominator final BigInteger gcd = num.gcd(den); if (BigInteger.ONE.compareTo(gcd) < 0) { num = num.divide(gcd); den = den.divide(gcd); } // move sign to numerator if (BigInteger.ZERO.compareTo(den) > 0) { num = num.negate(); den = den.negate(); } // store the values in the final fields numerator = num; denominator = den; } }
Example 6
Source File: Math_36_BigFraction_s.java From coming with MIT License | 5 votes |
/** * Create a {@link BigFraction} given the numerator and denominator as * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms. * * @param num the numerator, must not be {@code null}. * @param den the denominator, must not be {@code null}. * @throws ZeroException if the denominator is zero. * @throws NullArgumentException if either of the arguments is null */ public BigFraction(BigInteger num, BigInteger den) { MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR); MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR); if (BigInteger.ZERO.equals(den)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } if (BigInteger.ZERO.equals(num)) { numerator = BigInteger.ZERO; denominator = BigInteger.ONE; } else { // reduce numerator and denominator by greatest common denominator final BigInteger gcd = num.gcd(den); if (BigInteger.ONE.compareTo(gcd) < 0) { num = num.divide(gcd); den = den.divide(gcd); } // move sign to numerator if (BigInteger.ZERO.compareTo(den) > 0) { num = num.negate(); den = den.negate(); } // store the values in the final fields numerator = num; denominator = den; } }
Example 7
Source File: BigFraction_s.java From coming with MIT License | 5 votes |
/** * Create a {@link BigFraction} given the numerator and denominator as * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms. * * @param num the numerator, must not be {@code null}. * @param den the denominator, must not be {@code null}. * @throws ZeroException if the denominator is zero. * @throws NullArgumentException if either of the arguments is null */ public BigFraction(BigInteger num, BigInteger den) { MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR); MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR); if (BigInteger.ZERO.equals(den)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } if (BigInteger.ZERO.equals(num)) { numerator = BigInteger.ZERO; denominator = BigInteger.ONE; } else { // reduce numerator and denominator by greatest common denominator final BigInteger gcd = num.gcd(den); if (BigInteger.ONE.compareTo(gcd) < 0) { num = num.divide(gcd); den = den.divide(gcd); } // move sign to numerator if (BigInteger.ZERO.compareTo(den) > 0) { num = num.negate(); den = den.negate(); } // store the values in the final fields numerator = num; denominator = den; } }
Example 8
Source File: BigFraction_t.java From coming with MIT License | 5 votes |
/** * Create a {@link BigFraction} given the numerator and denominator as * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms. * * @param num the numerator, must not be {@code null}. * @param den the denominator, must not be {@code null}. * @throws ZeroException if the denominator is zero. * @throws NullArgumentException if either of the arguments is null */ public BigFraction(BigInteger num, BigInteger den) { MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR); MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR); if (BigInteger.ZERO.equals(den)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } if (BigInteger.ZERO.equals(num)) { numerator = BigInteger.ZERO; denominator = BigInteger.ONE; } else { // reduce numerator and denominator by greatest common denominator final BigInteger gcd = num.gcd(den); if (BigInteger.ONE.compareTo(gcd) < 0) { num = num.divide(gcd); den = den.divide(gcd); } // move sign to numerator if (BigInteger.ZERO.compareTo(den) > 0) { num = num.negate(); den = den.negate(); } // store the values in the final fields numerator = num; denominator = den; } }
Example 9
Source File: Math_36_BigFraction_t.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by the passed <code>BigInteger</code>, * ie "this * 1 / bg", returning the result in reduced form. * </p> * * @param bg * the <code>BigInteger</code> to divide by, must not be * <code>null</code>. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code BigInteger} is {@code null}. * @throws ZeroException * if the fraction to divide by is zero. */ public BigFraction divide(final BigInteger bg) { if (BigInteger.ZERO.equals(bg)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return new BigFraction(numerator, denominator.multiply(bg)); }
Example 10
Source File: Math_36_BigFraction_t.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by another, returning the result in * reduced form. * </p> * * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code fraction} is {@code null}. * @throws ZeroException if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (BigInteger.ZERO.equals(fraction.numerator)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return multiply(fraction.reciprocal()); }
Example 11
Source File: Math_36_BigFraction_s.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by the passed <code>BigInteger</code>, * ie "this * 1 / bg", returning the result in reduced form. * </p> * * @param bg * the <code>BigInteger</code> to divide by, must not be * <code>null</code>. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code BigInteger} is {@code null}. * @throws ZeroException * if the fraction to divide by is zero. */ public BigFraction divide(final BigInteger bg) { if (BigInteger.ZERO.equals(bg)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return new BigFraction(numerator, denominator.multiply(bg)); }
Example 12
Source File: Math_36_BigFraction_s.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by another, returning the result in * reduced form. * </p> * * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code fraction} is {@code null}. * @throws ZeroException if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (BigInteger.ZERO.equals(fraction.numerator)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return multiply(fraction.reciprocal()); }
Example 13
Source File: BigFraction_s.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by the passed <code>BigInteger</code>, * ie "this * 1 / bg", returning the result in reduced form. * </p> * * @param bg * the <code>BigInteger</code> to divide by, must not be * <code>null</code>. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code BigInteger} is {@code null}. * @throws ZeroException * if the fraction to divide by is zero. */ public BigFraction divide(final BigInteger bg) { if (BigInteger.ZERO.equals(bg)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return new BigFraction(numerator, denominator.multiply(bg)); }
Example 14
Source File: BigFraction_s.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by another, returning the result in * reduced form. * </p> * * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code fraction} is {@code null}. * @throws ZeroException if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (BigInteger.ZERO.equals(fraction.numerator)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return multiply(fraction.reciprocal()); }
Example 15
Source File: BigFraction_t.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by the passed <code>BigInteger</code>, * ie "this * 1 / bg", returning the result in reduced form. * </p> * * @param bg * the <code>BigInteger</code> to divide by, must not be * <code>null</code>. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code BigInteger} is {@code null}. * @throws ZeroException * if the fraction to divide by is zero. */ public BigFraction divide(final BigInteger bg) { if (BigInteger.ZERO.equals(bg)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return new BigFraction(numerator, denominator.multiply(bg)); }
Example 16
Source File: BigFraction_t.java From coming with MIT License | 3 votes |
/** * <p> * Divide the value of this fraction by another, returning the result in * reduced form. * </p> * * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. * @throws NullArgumentException if the {@code fraction} is {@code null}. * @throws ZeroException if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (BigInteger.ZERO.equals(fraction.numerator)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } return multiply(fraction.reciprocal()); }