Java Code Examples for org.apache.commons.math.util.MathUtils#sortInPlace()

The following examples show how to use org.apache.commons.math.util.MathUtils#sortInPlace() . 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: PolynomialFunctionLagrangeForm.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Evaluate the Lagrange polynomial using
 * <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
 * Neville's Algorithm</a>. It takes O(n^2) time.
 *
 * @param x Interpolating points array.
 * @param y Interpolating values array.
 * @param z Point at which the function value is to be computed.
 * @return the function value.
 * @throws DimensionMismatchException if {@code x} and {@code y} have
 * different lengths.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strictly increasing order.
 * @throws NumberIsTooSmallException if the size of {@code x} is less
 * than 2.
 */
public static double evaluate(double x[], double y[], double z) {
    if (verifyInterpolationArray(x, y, false)) {
        return evaluateInternal(x, y, z);
    }

    // Array is not sorted.
    final double[] xNew = new double[x.length];
    final double[] yNew = new double[y.length];
    System.arraycopy(x, 0, xNew, 0, x.length);
    System.arraycopy(y, 0, yNew, 0, y.length);

    MathUtils.sortInPlace(xNew, yNew);
    // Second check in case some abscissa is duplicated.
    verifyInterpolationArray(xNew, yNew, true);
    return evaluateInternal(xNew, yNew, z);
}
 
Example 2
Source File: PolynomialFunctionLagrangeForm.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Evaluate the Lagrange polynomial using
 * <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
 * Neville's Algorithm</a>. It takes O(n^2) time.
 *
 * @param x Interpolating points array.
 * @param y Interpolating values array.
 * @param z Point at which the function value is to be computed.
 * @return the function value.
 * @throws DimensionMismatchException if {@code x} and {@code y} have
 * different lengths.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strictly increasing order.
 * @throws NumberIsTooSmallException if the size of {@code x} is less
 * than 2.
 */
public static double evaluate(double x[], double y[], double z) {
    if (verifyInterpolationArray(x, y, false)) {
        return evaluateInternal(x, y, z);
    }

    // Array is not sorted.
    final double[] xNew = new double[x.length];
    final double[] yNew = new double[y.length];
    System.arraycopy(x, 0, xNew, 0, x.length);
    System.arraycopy(y, 0, yNew, 0, y.length);

    MathUtils.sortInPlace(xNew, yNew);
    // Second check in case some abscissa is duplicated.
    verifyInterpolationArray(xNew, yNew, true);
    return evaluateInternal(xNew, yNew, z);
}
 
Example 3
Source File: PolynomialFunctionLagrangeForm.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Evaluate the Lagrange polynomial using
 * <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
 * Neville's Algorithm</a>. It takes O(n^2) time.
 *
 * @param x Interpolating points array.
 * @param y Interpolating values array.
 * @param z Point at which the function value is to be computed.
 * @return the function value.
 * @throws DimensionMismatchException if {@code x} and {@code y} have
 * different lengths.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strictly increasing order.
 * @throws NumberIsTooSmallException if the size of {@code x} is less
 * than 2.
 */
public static double evaluate(double x[], double y[], double z) {
    if (verifyInterpolationArray(x, y, false)) {
        return evaluateInternal(x, y, z);
    }

    // Array is not sorted.
    final double[] xNew = new double[x.length];
    final double[] yNew = new double[y.length];
    System.arraycopy(x, 0, xNew, 0, x.length);
    System.arraycopy(y, 0, yNew, 0, y.length);

    MathUtils.sortInPlace(xNew, yNew);
    // Second check in case some abscissa is duplicated.
    verifyInterpolationArray(xNew, yNew, true);
    return evaluateInternal(xNew, yNew, z);
}
 
Example 4
Source File: PolynomialFunctionLagrangeForm.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Lagrange polynomial with the given abscissas and function
 * values. The order of interpolating points are not important.
 * <p>
 * The constructor makes copy of the input arrays and assigns them.</p>
 *
 * @param x interpolating points
 * @param y function values at interpolating points
 * @throws DimensionMismatchException if the array lengths are different.
 * @throws NumberIsTooSmallException if the number of points is less than 2.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if two abscissae have the same value.
 */
public PolynomialFunctionLagrangeForm(double x[], double y[]) {
    this.x = new double[x.length];
    this.y = new double[y.length];
    System.arraycopy(x, 0, this.x, 0, x.length);
    System.arraycopy(y, 0, this.y, 0, y.length);
    coefficientsComputed = false;

    if (!verifyInterpolationArray(x, y, false)) {
        MathUtils.sortInPlace(this.x, this.y);
        // Second check in case some abscissa is duplicated.
        verifyInterpolationArray(this.x, this.y, true);
    }
}
 
Example 5
Source File: PolynomialFunctionLagrangeForm.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Lagrange polynomial with the given abscissas and function
 * values. The order of interpolating points are not important.
 * <p>
 * The constructor makes copy of the input arrays and assigns them.</p>
 *
 * @param x interpolating points
 * @param y function values at interpolating points
 * @throws DimensionMismatchException if the array lengths are different.
 * @throws NumberIsTooSmallException if the number of points is less than 2.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if two abscissae have the same value.
 */
public PolynomialFunctionLagrangeForm(double x[], double y[]) {
    this.x = new double[x.length];
    this.y = new double[y.length];
    System.arraycopy(x, 0, this.x, 0, x.length);
    System.arraycopy(y, 0, this.y, 0, y.length);
    coefficientsComputed = false;

    if (!verifyInterpolationArray(x, y, false)) {
        MathUtils.sortInPlace(this.x, this.y);
        // Second check in case some abscissa is duplicated.
        verifyInterpolationArray(this.x, this.y, true);
    }
}
 
Example 6
Source File: PolynomialFunctionLagrangeForm.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Lagrange polynomial with the given abscissas and function
 * values. The order of interpolating points are not important.
 * <p>
 * The constructor makes copy of the input arrays and assigns them.</p>
 *
 * @param x interpolating points
 * @param y function values at interpolating points
 * @throws DimensionMismatchException if the array lengths are different.
 * @throws NumberIsTooSmallException if the number of points is less than 2.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if two abscissae have the same value.
 */
public PolynomialFunctionLagrangeForm(double x[], double y[]) {
    this.x = new double[x.length];
    this.y = new double[y.length];
    System.arraycopy(x, 0, this.x, 0, x.length);
    System.arraycopy(y, 0, this.y, 0, y.length);
    coefficientsComputed = false;

    if (!verifyInterpolationArray(x, y, false)) {
        MathUtils.sortInPlace(this.x, this.y);
        // Second check in case some abscissa is duplicated.
        verifyInterpolationArray(this.x, this.y, true);
    }
}