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

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY . 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: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 2
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 3
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 4
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 5
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 6
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 7
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 8
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
Example 9
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a polynomial with the given coefficients.  The first element
 * of the coefficients array is the constant term.  Higher degree
 * coefficients follow in sequence.  The degree of the resulting polynomial
 * is the index of the last non-null element of the array, or 0 if all elements
 * are null.
 * <p>
 * The constructor makes a copy of the input array and assigns the copy to
 * the coefficients property.</p>
 *
 * @param c Polynomial coefficients.
 * @throws NullArgumentException if {@code c} is {@code null}.
 * @throws NoDataException if {@code c} is empty.
 */
public PolynomialFunction(double c[])
    throws NullArgumentException, NoDataException {
    super();
    MathUtils.checkNotNull(c);
    int n = c.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    while ((n > 1) && (c[n - 1] == 0)) {
        --n;
    }
    this.coefficients = new double[n];
    System.arraycopy(c, 0, this.coefficients, 0, n);
}
 
Example 10
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a polynomial with the given coefficients.  The first element
 * of the coefficients array is the constant term.  Higher degree
 * coefficients follow in sequence.  The degree of the resulting polynomial
 * is the index of the last non-null element of the array, or 0 if all elements
 * are null.
 * <p>
 * The constructor makes a copy of the input array and assigns the copy to
 * the coefficients property.</p>
 *
 * @param c Polynomial coefficients.
 * @throws NullArgumentException if {@code c} is {@code null}.
 * @throws NoDataException if {@code c} is empty.
 */
public PolynomialFunction(double c[])
    throws NullArgumentException, NoDataException {
    super();
    MathUtils.checkNotNull(c);
    int n = c.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    while ((n > 1) && (c[n - 1] == 0)) {
        --n;
    }
    this.coefficients = new double[n];
    System.arraycopy(c, 0, this.coefficients, 0, n);
}
 
Example 11
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses Horner's Method to evaluate the polynomial with the given coefficients at
 * the argument.
 *
 * @param coefficients Coefficients of the polynomial to evaluate.
 * @param argument Input value.
 * @return the value of the polynomial.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double evaluate(double[] coefficients, double argument)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    double result = coefficients[n - 1];
    for (int j = n - 2; j >= 0; j--) {
        result = argument * result + coefficients[j];
    }
    return result;
}
 
Example 12
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses Horner's Method to evaluate the polynomial with the given coefficients at
 * the argument.
 *
 * @param coefficients Coefficients of the polynomial to evaluate.
 * @param argument Input value.
 * @return the value of the polynomial.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double evaluate(double[] coefficients, double argument)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    double result = coefficients[n - 1];
    for (int j = n - 2; j >= 0; j--) {
        result = argument * result + coefficients[j];
    }
    return result;
}
 
Example 13
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses Horner's Method to evaluate the polynomial with the given coefficients at
 * the argument.
 *
 * @param coefficients Coefficients of the polynomial to evaluate.
 * @param argument Input value.
 * @return the value of the polynomial.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double evaluate(double[] coefficients, double argument)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    double result = coefficients[n - 1];
    for (int j = n - 2; j >= 0; j--) {
        result = argument * result + coefficients[j];
    }
    return result;
}
 
Example 14
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses Horner's Method to evaluate the polynomial with the given coefficients at
 * the argument.
 *
 * @param coefficients Coefficients of the polynomial to evaluate.
 * @param argument Input value.
 * @return the value of the polynomial.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double evaluate(double[] coefficients, double argument)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    double result = coefficients[n - 1];
    for (int j = n - 2; j >= 0; j--) {
        result = argument * result + coefficients[j];
    }
    return result;
}
 
Example 15
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
public DerivativeStructure value(final DerivativeStructure t)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    DerivativeStructure result =
            new DerivativeStructure(t.getFreeParameters(), t.getOrder(), coefficients[n - 1]);
    for (int j = n - 2; j >= 0; j--) {
        result = result.multiply(t).add(coefficients[j]);
    }
    return result;
}
 
Example 16
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
public DerivativeStructure value(final DerivativeStructure t)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    DerivativeStructure result =
            new DerivativeStructure(t.getFreeParameters(), t.getOrder(), coefficients[n - 1]);
    for (int j = n - 2; j >= 0; j--) {
        result = result.multiply(t).add(coefficients[j]);
    }
    return result;
}
 
Example 17
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses Horner's Method to evaluate the polynomial with the given coefficients at
 * the argument.
 *
 * @param coefficients Coefficients of the polynomial to evaluate.
 * @param argument Input value.
 * @return the value of the polynomial.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double evaluate(double[] coefficients, double argument)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    double result = coefficients[n - 1];
    for (int j = n - 2; j >= 0; j--) {
        result = argument * result + coefficients[j];
    }
    return result;
}
 
Example 18
Source File: PolynomialFunctionNewtonForm.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Verifies that the input arrays are valid.
 * <p>
 * The centers must be distinct for interpolation purposes, but not
 * for general use. Thus it is not verified here.</p>
 *
 * @param a the coefficients in Newton form formula
 * @param c the centers
 * @throws NullArgumentException if any argument is {@code null}.
 * @throws NoDataException if any array has zero length.
 * @throws DimensionMismatchException if the size difference between
 * {@code a} and {@code c} is not equal to 1.
 * @see org.apache.commons.math3.analysis.interpolation.DividedDifferenceInterpolator#computeDividedDifference(double[],
 * double[])
 */
protected static void verifyInputArray(double a[], double c[])
    throws NullArgumentException, NoDataException, DimensionMismatchException {
    MathUtils.checkNotNull(a);
    MathUtils.checkNotNull(c);
    if (a.length == 0 || c.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (a.length != c.length + 1) {
        throw new DimensionMismatchException(LocalizedFormats.ARRAY_SIZES_SHOULD_HAVE_DIFFERENCE_1,
                                             a.length, c.length);
    }
}
 
Example 19
Source File: PolynomialFunctionNewtonForm.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Verifies that the input arrays are valid.
 * <p>
 * The centers must be distinct for interpolation purposes, but not
 * for general use. Thus it is not verified here.</p>
 *
 * @param a the coefficients in Newton form formula
 * @param c the centers
 * @throws NullArgumentException if any argument is {@code null}.
 * @throws NoDataException if any array has zero length.
 * @throws DimensionMismatchException if the size difference between
 * {@code a} and {@code c} is not equal to 1.
 * @see org.apache.commons.math3.analysis.interpolation.DividedDifferenceInterpolator#computeDividedDifference(double[],
 * double[])
 */
protected static void verifyInputArray(double a[], double c[])
    throws NullArgumentException, NoDataException, DimensionMismatchException {
    MathUtils.checkNotNull(a);
    MathUtils.checkNotNull(c);
    if (a.length == 0 || c.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (a.length != c.length + 1) {
        throw new DimensionMismatchException(LocalizedFormats.ARRAY_SIZES_SHOULD_HAVE_DIFFERENCE_1,
                                             a.length, c.length);
    }
}
 
Example 20
Source File: PolynomialFunctionNewtonForm.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Verifies that the input arrays are valid.
 * <p>
 * The centers must be distinct for interpolation purposes, but not
 * for general use. Thus it is not verified here.</p>
 *
 * @param a the coefficients in Newton form formula
 * @param c the centers
 * @throws NullArgumentException if any argument is {@code null}.
 * @throws NoDataException if any array has zero length.
 * @throws DimensionMismatchException if the size difference between
 * {@code a} and {@code c} is not equal to 1.
 * @see org.apache.commons.math3.analysis.interpolation.DividedDifferenceInterpolator#computeDividedDifference(double[],
 * double[])
 */
protected static void verifyInputArray(double a[], double c[])
    throws NullArgumentException, NoDataException, DimensionMismatchException {
    MathUtils.checkNotNull(a);
    MathUtils.checkNotNull(c);
    if (a.length == 0 || c.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (a.length != c.length + 1) {
        throw new DimensionMismatchException(LocalizedFormats.ARRAY_SIZES_SHOULD_HAVE_DIFFERENCE_1,
                                             a.length, c.length);
    }
}