當前位置: 首頁>>代碼示例>>Java>>正文


Java PolynomialFunctionLagrangeForm類代碼示例

本文整理匯總了Java中org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm的典型用法代碼示例。如果您正苦於以下問題:Java PolynomialFunctionLagrangeForm類的具體用法?Java PolynomialFunctionLagrangeForm怎麽用?Java PolynomialFunctionLagrangeForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PolynomialFunctionLagrangeForm類屬於org.apache.commons.math.analysis.polynomials包,在下文中一共展示了PolynomialFunctionLagrangeForm類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: unwrap

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * @param lagrange A Commons polynomial in Lagrange form, not null
 * @return An OG 1-D function mapping doubles to doubles
 */
public static Function1D<Double, Double> unwrap(final PolynomialFunctionLagrangeForm lagrange) {
  Validate.notNull(lagrange);
  return new Function1D<Double, Double>() {

    @Override
    public Double evaluate(final Double x) {
      try {
        return lagrange.value(x);
      } catch (final org.apache.commons.math.MathException e) {
        throw new MathException(e);
      }
    }

  };
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:20,代碼來源:CommonsMathWrapper.java

示例2: interpolate

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Computes an interpolating function for the data set.
 *
 * @param x the interpolating points array
 * @param y the interpolating values array
 * @return a function which interpolates the data set
 * @throws DuplicateSampleAbscissaException if arguments are invalid
 */
public PolynomialFunctionNewtonForm interpolate(double x[], double y[]) throws
    DuplicateSampleAbscissaException {

    /**
     * a[] and c[] are defined in the general formula of Newton form:
     * p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... +
     *        a[n](x-c[0])(x-c[1])...(x-c[n-1])
     */
    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y);

    /**
     * When used for interpolation, the Newton form formula becomes
     * p(x) = f[x0] + f[x0,x1](x-x0) + f[x0,x1,x2](x-x0)(x-x1) + ... +
     *        f[x0,x1,...,x[n-1]](x-x0)(x-x1)...(x-x[n-2])
     * Therefore, a[k] = f[x0,x1,...,xk], c[k] = x[k].
     * <p>
     * Note x[], y[], a[] have the same length but c[]'s size is one less.</p>
     */
    final double[] c = new double[x.length-1];
    System.arraycopy(x, 0, c, 0, c.length);

    final double[] a = computeDividedDifference(x, y);
    return new PolynomialFunctionNewtonForm(a, c);

}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:34,代碼來源:DividedDifferenceInterpolator.java

示例3: computeDividedDifference

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Returns a copy of the divided difference array.
 * <p>
 * The divided difference array is defined recursively by <pre>
 * f[x0] = f(x0)
 * f[x0,x1,...,xk] = (f(x1,...,xk) - f(x0,...,x[k-1])) / (xk - x0)
 * </pre></p>
 * <p>
 * The computational complexity is O(N^2).</p>
 *
 * @param x the interpolating points array
 * @param y the interpolating values array
 * @return a fresh copy of the divided difference array
 * @throws DuplicateSampleAbscissaException if any abscissas coincide
 */
protected static double[] computeDividedDifference(final double x[], final double y[])
    throws DuplicateSampleAbscissaException {

    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y);

    final double[] divdiff = y.clone(); // initialization

    final int n = x.length;
    final double[] a = new double [n];
    a[0] = divdiff[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n-i; j++) {
            final double denominator = x[j+i] - x[j];
            if (denominator == 0.0) {
                // This happens only when two abscissas are identical.
                throw new DuplicateSampleAbscissaException(x[j], j, j+i);
            }
            divdiff[j] = (divdiff[j+1] - divdiff[j]) / denominator;
        }
        a[i] = divdiff[0];
    }

    return a;
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:40,代碼來源:DividedDifferenceInterpolator.java

示例4: interpolate

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Compute an interpolating function for the dataset.
 *
 * @param x Interpolating points array.
 * @param y Interpolating values array.
 * @return a function which interpolates the dataset.
 * @throws org.apache.commons.math.exception.DimensionMismatchException
 * if the array lengths are different.
 * @throws org.apache.commons.math.exception.NumberIsTooSmallException
 * if the number of points is less than 2.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strictly increasing order.
 */
public PolynomialFunctionNewtonForm interpolate(double x[], double y[]) {
    /**
     * a[] and c[] are defined in the general formula of Newton form:
     * p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... +
     *        a[n](x-c[0])(x-c[1])...(x-c[n-1])
     */
    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true);

    /**
     * When used for interpolation, the Newton form formula becomes
     * p(x) = f[x0] + f[x0,x1](x-x0) + f[x0,x1,x2](x-x0)(x-x1) + ... +
     *        f[x0,x1,...,x[n-1]](x-x0)(x-x1)...(x-x[n-2])
     * Therefore, a[k] = f[x0,x1,...,xk], c[k] = x[k].
     * <p>
     * Note x[], y[], a[] have the same length but c[]'s size is one less.</p>
     */
    final double[] c = new double[x.length-1];
    System.arraycopy(x, 0, c, 0, c.length);

    final double[] a = computeDividedDifference(x, y);
    return new PolynomialFunctionNewtonForm(a, c);
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:36,代碼來源:DividedDifferenceInterpolator.java

示例5: interpolate

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
@Override
public Double interpolate(final Interpolator1DDataBundle data, final Double value) {
  Validate.notNull(value, "value");
  Validate.notNull(data, "data bundle");
  final int n = data.size();
  final double[] keys = data.getKeys();
  final double[] values = data.getValues();
  if (n <= _degree) {
    throw new MathException("Need at least " + (_degree + 1) + " data points to perform polynomial interpolation of degree " + _degree);
  }
  if (data.getLowerBoundIndex(value) == n - 1) {
    return values[n - 1];
  }
  final int lower = data.getLowerBoundIndex(value);
  final int lowerBound = lower - _offset;
  final int upperBound = _degree + 1 + lowerBound;
  if (lowerBound < 0) {
    throw new MathException("Could not get lower bound: index " + lowerBound + " must be greater than or equal to zero");
  }
  if (upperBound > n + 1) {
    throw new MathException("Could not get upper bound: index " + upperBound + " must be less than or equal to " + (n + 1));
  }
  final double[] x = Arrays.copyOfRange(keys, lowerBound, upperBound);
  final double[] y = Arrays.copyOfRange(values, lowerBound, upperBound);
  try {
    final PolynomialFunctionLagrangeForm lagrange = _interpolator.interpolate(x, y);
    return CommonsMathWrapper.unwrap(lagrange).evaluate(value);
  } catch (final org.apache.commons.math.MathException e) {
    throw new MathException(e);
  }
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:32,代碼來源:PolynomialInterpolator1D.java

示例6: testLagrange

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
@Test
public void testLagrange() {
  final int n = OG_POLYNOMIAL.getCoefficients().length;
  final double[] x = new double[n];
  final double[] y = new double[n];
  for (int i = 0; i < n; i++) {
    x[i] = i;
    y[i] = OG_POLYNOMIAL.evaluate(x[i]);
  }
  final Function1D<Double, Double> unwrapped = CommonsMathWrapper.unwrap(new PolynomialFunctionLagrangeForm(x, y));
  for (int i = 0; i < 100; i++) {
    assertEquals(unwrapped.evaluate(i + 0.5), OG_POLYNOMIAL.evaluate(i + 0.5), 1e-9);
  }
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:15,代碼來源:CommonsMathWrapperTest.java

示例7: interpolate

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Computes an interpolating function for the data set.
 *
 * @param x the interpolating points array
 * @param y the interpolating values array
 * @return a function which interpolates the data set
 * @throws DuplicateSampleAbscissaException if arguments are invalid
 */
public UnivariateRealFunction interpolate(double x[], double y[]) throws
    DuplicateSampleAbscissaException {

    /**
     * a[] and c[] are defined in the general formula of Newton form:
     * p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... +
     *        a[n](x-c[0])(x-c[1])...(x-c[n-1])
     */
    double a[], c[];

    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y);

    /**
     * When used for interpolation, the Newton form formula becomes
     * p(x) = f[x0] + f[x0,x1](x-x0) + f[x0,x1,x2](x-x0)(x-x1) + ... +
     *        f[x0,x1,...,x[n-1]](x-x0)(x-x1)...(x-x[n-2])
     * Therefore, a[k] = f[x0,x1,...,xk], c[k] = x[k].
     * <p>
     * Note x[], y[], a[] have the same length but c[]'s size is one less.</p>
     */
    c = new double[x.length-1];
    for (int i = 0; i < c.length; i++) {
        c[i] = x[i];
    }
    a = computeDividedDifference(x, y);

    PolynomialFunctionNewtonForm p;
    p = new PolynomialFunctionNewtonForm(a, c);
    return p;
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:39,代碼來源:DividedDifferenceInterpolator.java

示例8: computeDividedDifference

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Returns a copy of the divided difference array.
 * <p> 
 * The divided difference array is defined recursively by <pre>
 * f[x0] = f(x0)
 * f[x0,x1,...,xk] = (f(x1,...,xk) - f(x0,...,x[k-1])) / (xk - x0)
 * </pre></p>
 * <p>
 * The computational complexity is O(N^2).</p>
 *
 * @param x the interpolating points array
 * @param y the interpolating values array
 * @return a fresh copy of the divided difference array
 * @throws DuplicateSampleAbscissaException if any abscissas coincide
 */
protected static double[] computeDividedDifference(double x[], double y[])
    throws DuplicateSampleAbscissaException {

    int i, j, n;
    double divdiff[], a[], denominator;

    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y);

    n = x.length;
    divdiff = new double[n];
    for (i = 0; i < n; i++) {
        divdiff[i] = y[i];      // initialization
    }

    a = new double [n];
    a[0] = divdiff[0];
    for (i = 1; i < n; i++) {
        for (j = 0; j < n-i; j++) {
            denominator = x[j+i] - x[j];
            if (denominator == 0.0) {
                // This happens only when two abscissas are identical.
                throw new DuplicateSampleAbscissaException(x[j], j, j+i);
            }
            divdiff[j] = (divdiff[j+1] - divdiff[j]) / denominator;
        }
        a[i] = divdiff[0];
    }

    return a;
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:46,代碼來源:DividedDifferenceInterpolator.java

示例9: interpolate

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Computes an interpolating function for the data set.
 *
 * @param x the interpolating points array
 * @param y the interpolating values array
 * @return a function which interpolates the data set
 * @throws DuplicateSampleAbscissaException if arguments are invalid
 */
public PolynomialFunctionNewtonForm interpolate(double x[], double y[]) throws
    DuplicateSampleAbscissaException {

    /**
     * a[] and c[] are defined in the general formula of Newton form:
     * p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... +
     *        a[n](x-c[0])(x-c[1])...(x-c[n-1])
     */
    double a[], c[];

    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y);

    /**
     * When used for interpolation, the Newton form formula becomes
     * p(x) = f[x0] + f[x0,x1](x-x0) + f[x0,x1,x2](x-x0)(x-x1) + ... +
     *        f[x0,x1,...,x[n-1]](x-x0)(x-x1)...(x-x[n-2])
     * Therefore, a[k] = f[x0,x1,...,xk], c[k] = x[k].
     * <p>
     * Note x[], y[], a[] have the same length but c[]'s size is one less.</p>
     */
    c = new double[x.length-1];
    for (int i = 0; i < c.length; i++) {
        c[i] = x[i];
    }
    a = computeDividedDifference(x, y);

    return new PolynomialFunctionNewtonForm(a, c);

}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:38,代碼來源:DividedDifferenceInterpolator.java

示例10: testNullLagrange

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullLagrange() {
  CommonsMathWrapper.unwrap((PolynomialFunctionLagrangeForm) null);
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:5,代碼來源:CommonsMathWrapperTest.java

示例11: computeDividedDifference

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Return a copy of the divided difference array.
 * <p>
 * The divided difference array is defined recursively by <pre>
 * f[x0] = f(x0)
 * f[x0,x1,...,xk] = (f(x1,...,xk) - f(x0,...,x[k-1])) / (xk - x0)
 * </pre></p>
 * <p>
 * The computational complexity is O(N^2).</p>
 *
 * @param x Interpolating points array.
 * @param y Interpolating values array.
 * @return a fresh copy of the divided difference array.
 * @throws org.apache.commons.math.exception.DimensionMismatchException
 * if the array lengths are different.
 * @throws org.apache.commons.math.exception.NumberIsTooSmallException
 * if the number of points is less than 2.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strictly increasing order.
 */
protected static double[] computeDividedDifference(final double x[], final double y[]) {
    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true);

    final double[] divdiff = y.clone(); // initialization

    final int n = x.length;
    final double[] a = new double [n];
    a[0] = divdiff[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n-i; j++) {
            final double denominator = x[j+i] - x[j];
            divdiff[j] = (divdiff[j+1] - divdiff[j]) / denominator;
        }
        a[i] = divdiff[0];
    }

    return a;
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:39,代碼來源:DividedDifferenceInterpolator.java

示例12: computeDividedDifference

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Return a copy of the divided difference array.
 * <p>
 * The divided difference array is defined recursively by <pre>
 * f[x0] = f(x0)
 * f[x0,x1,...,xk] = (f[x1,...,xk] - f[x0,...,x[k-1]]) / (xk - x0)
 * </pre></p>
 * <p>
 * The computational complexity is O(N^2).</p>
 *
 * @param x Interpolating points array.
 * @param y Interpolating values array.
 * @return a fresh copy of the divided difference array.
 * @throws org.apache.commons.math.exception.DimensionMismatchException
 * if the array lengths are different.
 * @throws org.apache.commons.math.exception.NumberIsTooSmallException
 * if the number of points is less than 2.
 * @throws org.apache.commons.math.exception.NonMonotonousSequenceException
 * if {@code x} is not sorted in strictly increasing order.
 */
protected static double[] computeDividedDifference(final double x[], final double y[]) {
    PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true);

    final double[] divdiff = y.clone(); // initialization

    final int n = x.length;
    final double[] a = new double [n];
    a[0] = divdiff[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n-i; j++) {
            final double denominator = x[j+i] - x[j];
            divdiff[j] = (divdiff[j+1] - divdiff[j]) / denominator;
        }
        a[i] = divdiff[0];
    }

    return a;
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:39,代碼來源:DividedDifferenceInterpolator.java

示例13: interpolate

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Computes an interpolating function for the data set.
 *
 * @param x the interpolating points array
 * @param y the interpolating values array
 * @return a function which interpolates the data set
 * @throws MathException if arguments are invalid
 */
public PolynomialFunctionLagrangeForm interpolate(double x[], double y[])
    throws MathException {
    return new PolynomialFunctionLagrangeForm(x, y);
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:13,代碼來源:NevilleInterpolator.java

示例14: interpolate

import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm; //導入依賴的package包/類
/**
 * Computes an interpolating function for the data set.
 *
 * @param x the interpolating points array
 * @param y the interpolating values array
 * @return a function which interpolates the data set
 * @throws org.apache.commons.math.exception.DimensionMismatchException if
 * the array lengths are different.
 * @throws org.apache.commons.math.exception.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 interpolate(double x[], double y[]) {
    return new PolynomialFunctionLagrangeForm(x, y);
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:17,代碼來源:NevilleInterpolator.java


注:本文中的org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。