/** * Computes an interpolating function for the data set. * * @param x Interpolating points. * @param y Interpolating values. * @return a function which interpolates the data set * @throws DimensionMismatchException if the array lengths are different. * @throws NumberIsTooSmallException if the number of points is less than 2. * @throws NonMonotonicSequenceException if two abscissae have the same * value. */ public PolynomialFunctionLagrangeForm interpolate(double x[], double y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { return new PolynomialFunctionLagrangeForm(x, y); } }
/** * Returns a copy of the coefficients array. * <p> * Changes made to the returned copy will not affect the polynomial.</p> * <p> * Note that coefficients computation can be ill-conditioned. Use with caution * and only when it is necessary.</p> * * @return a fresh copy of the coefficients array */ public double[] getCoefficients() { if (!coefficientsComputed) { computeCoefficients(); } double[] out = new double[coefficients.length]; System.arraycopy(coefficients, 0, out, 0, coefficients.length); return out; }
final int n = degree() + 1; coefficients = new double[n]; for (int i = 0; i < n; i++) {
if (verifyInterpolationArray(x, y, false)) { return evaluateInternal(x, y, z); verifyInterpolationArray(xNew, yNew, true); return evaluateInternal(xNew, yNew, z);
/** * 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 NonMonotonicSequenceException * if two abscissae have the same value. */ public PolynomialFunctionLagrangeForm(double x[], double y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { 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)) { MathArrays.sortInPlace(this.x, this.y); // Second check in case some abscissa is duplicated. verifyInterpolationArray(this.x, this.y, true); } }
/** * Calculate the function value at the given point. * * @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.math3.exception.NonMonotonicSequenceException * if {@code x} is not sorted in strictly increasing order. * @throws NumberIsTooSmallException if the size of {@code x} is less * than 2. */ public double value(double z) { return evaluateInternal(x, y, z); }
if (verifyInterpolationArray(x, y, false)) { return evaluateInternal(x, y, z); verifyInterpolationArray(xNew, yNew, true); return evaluateInternal(xNew, yNew, z);
NumberIsTooSmallException, NonMonotonicSequenceException { PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true);
/** * Calculate the function value at the given point. * * @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.math3.exception.NonMonotonicSequenceException * if {@code x} is not sorted in strictly increasing order. * @throws NumberIsTooSmallException if the size of {@code x} is less * than 2. */ public double value(double z) { return evaluateInternal(x, y, z); }
if (verifyInterpolationArray(x, y, false)) { return evaluateInternal(x, y, z); verifyInterpolationArray(xNew, yNew, true); return evaluateInternal(xNew, yNew, z);
PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true);
/** * Calculate the function value at the given point. * * @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.math3.exception.NonMonotonicSequenceException * if {@code x} is not sorted in strictly increasing order. * @throws NumberIsTooSmallException if the size of {@code x} is less * than 2. */ public double value(double z) { return evaluateInternal(x, y, z); }
/** * Returns a copy of the coefficients array. * <p> * Changes made to the returned copy will not affect the polynomial.</p> * <p> * Note that coefficients computation can be ill-conditioned. Use with caution * and only when it is necessary.</p> * * @return a fresh copy of the coefficients array */ public double[] getCoefficients() { if (!coefficientsComputed) { computeCoefficients(); } double[] out = new double[coefficients.length]; System.arraycopy(coefficients, 0, out, 0, coefficients.length); return out; }
/** * Computes an interpolating function for the data set. * * @param x Interpolating points. * @param y Interpolating values. * @return a function which interpolates the data set * @throws DimensionMismatchException if the array lengths are different. * @throws NumberIsTooSmallException if the number of points is less than 2. * @throws NonMonotonicSequenceException if two abscissae have the same * value. */ public PolynomialFunctionLagrangeForm interpolate(double x[], double y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { return new PolynomialFunctionLagrangeForm(x, y); } }
final int n = degree() + 1; coefficients = new double[n]; for (int i = 0; i < n; i++) {
/** * 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 NonMonotonicSequenceException * if two abscissae have the same value. */ public PolynomialFunctionLagrangeForm(double x[], double y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { 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)) { MathArrays.sortInPlace(this.x, this.y); // Second check in case some abscissa is duplicated. verifyInterpolationArray(this.x, this.y, true); } }
/** * Returns a copy of the coefficients array. * <p> * Changes made to the returned copy will not affect the polynomial.</p> * <p> * Note that coefficients computation can be ill-conditioned. Use with caution * and only when it is necessary.</p> * * @return a fresh copy of the coefficients array */ public double[] getCoefficients() { if (!coefficientsComputed) { computeCoefficients(); } double[] out = new double[coefficients.length]; System.arraycopy(coefficients, 0, out, 0, coefficients.length); return out; }
/** * Computes an interpolating function for the data set. * * @param x Interpolating points. * @param y Interpolating values. * @return a function which interpolates the data set * @throws DimensionMismatchException if the array lengths are different. * @throws NumberIsTooSmallException if the number of points is less than 2. * @throws NonMonotonicSequenceException if two abscissae have the same * value. */ public PolynomialFunctionLagrangeForm interpolate(double x[], double y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { return new PolynomialFunctionLagrangeForm(x, y); } }
final int n = degree() + 1; coefficients = new double[n]; for (int i = 0; i < n; i++) {
/** * 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 NonMonotonicSequenceException * if two abscissae have the same value. */ public PolynomialFunctionLagrangeForm(double x[], double y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { 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)) { MathArrays.sortInPlace(this.x, this.y); // Second check in case some abscissa is duplicated. verifyInterpolationArray(this.x, this.y, true); } }