/** {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { final double t0 = t.getValue(); if (t0 < knots[0] || t0 > knots[n]) { throw new OutOfRangeException(t0, knots[0], knots[n]); } int i = Arrays.binarySearch(knots, t0); if (i < 0) { i = -i - 2; } // This will handle the case where t is the last knot value // There are only n-1 polynomials, so if t is the last knot // then we will use the last polynomial to calculate the value. if ( i >= polynomials.length ) { i--; } return polynomials[i].value(t.subtract(knots[i])); }
/** Interpolate value at a specified abscissa. * <p> * Calling this method is equivalent to call the {@link * PolynomialFunction#value(DerivativeStructure) value} methods of all polynomials * returned by {@link #getPolynomials() getPolynomials}, except it does not build the * intermediate polynomials, so this method is faster and numerically more stable. * </p> * @param x interpolation abscissa * @return interpolated value * @exception NoDataException if sample is empty */ public DerivativeStructure[] value(final DerivativeStructure x) throws NoDataException { // safety check checkInterpolation(); final DerivativeStructure[] value = new DerivativeStructure[topDiagonal.get(0).length]; Arrays.fill(value, x.getField().getZero()); DerivativeStructure valueCoeff = x.getField().getOne(); for (int i = 0; i < topDiagonal.size(); ++i) { double[] dividedDifference = topDiagonal.get(i); for (int k = 0; k < value.length; ++k) { value[k] = value[k].add(valueCoeff.multiply(dividedDifference[k])); } final DerivativeStructure deltaX = x.subtract(abscissae.get(i)); valueCoeff = valueCoeff.multiply(deltaX); } return value; }
/** * {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { verifyInputArray(a, c); final int n = c.length; DerivativeStructure value = new DerivativeStructure(t.getFreeParameters(), t.getOrder(), a[n]); for (int i = n - 1; i >= 0; i--) { value = t.subtract(c[i]).multiply(value).add(a[i]); } return value; }
/** {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { final double t0 = t.getValue(); if (t0 < knots[0] || t0 > knots[n]) { throw new OutOfRangeException(t0, knots[0], knots[n]); } int i = Arrays.binarySearch(knots, t0); if (i < 0) { i = -i - 2; } // This will handle the case where t is the last knot value // There are only n-1 polynomials, so if t is the last knot // then we will use the last polynomial to calculate the value. if ( i >= polynomials.length ) { i--; } return polynomials[i].value(t.subtract(knots[i])); }
/** {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { final double t0 = t.getValue(); if (t0 < knots[0] || t0 > knots[n]) { throw new OutOfRangeException(t0, knots[0], knots[n]); } int i = Arrays.binarySearch(knots, t0); if (i < 0) { i = -i - 2; } // This will handle the case where t is the last knot value // There are only n-1 polynomials, so if t is the last knot // then we will use the last polynomial to calculate the value. if ( i >= polynomials.length ) { i--; } return polynomials[i].value(t.subtract(knots[i])); }
/** Interpolate value at a specified abscissa. * <p> * Calling this method is equivalent to call the {@link * PolynomialFunction#value(DerivativeStructure) value} methods of all polynomials * returned by {@link #getPolynomials() getPolynomials}, except it does not build the * intermediate polynomials, so this method is faster and numerically more stable. * </p> * @param x interpolation abscissa * @return interpolated value * @exception NoDataException if sample is empty */ public DerivativeStructure[] value(final DerivativeStructure x) throws NoDataException { // safety check checkInterpolation(); final DerivativeStructure[] value = new DerivativeStructure[topDiagonal.get(0).length]; Arrays.fill(value, x.getField().getZero()); DerivativeStructure valueCoeff = x.getField().getOne(); for (int i = 0; i < topDiagonal.size(); ++i) { double[] dividedDifference = topDiagonal.get(i); for (int k = 0; k < value.length; ++k) { value[k] = value[k].add(valueCoeff.multiply(dividedDifference[k])); } final DerivativeStructure deltaX = x.subtract(abscissae.get(i)); valueCoeff = valueCoeff.multiply(deltaX); } return value; }
/** Interpolate value at a specified abscissa. * <p> * Calling this method is equivalent to call the {@link * PolynomialFunction#value(DerivativeStructure) value} methods of all polynomials * returned by {@link #getPolynomials() getPolynomials}, except it does not build the * intermediate polynomials, so this method is faster and numerically more stable. * </p> * @param x interpolation abscissa * @return interpolated value * @exception NoDataException if sample is empty */ public DerivativeStructure[] value(final DerivativeStructure x) throws NoDataException { // safety check checkInterpolation(); final DerivativeStructure[] value = new DerivativeStructure[topDiagonal.get(0).length]; Arrays.fill(value, x.getField().getZero()); DerivativeStructure valueCoeff = x.getField().getOne(); for (int i = 0; i < topDiagonal.size(); ++i) { double[] dividedDifference = topDiagonal.get(i); for (int k = 0; k < value.length; ++k) { value[k] = value[k].add(valueCoeff.multiply(dividedDifference[k])); } final DerivativeStructure deltaX = x.subtract(abscissae.get(i)); valueCoeff = valueCoeff.multiply(deltaX); } return value; }
/** * {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { verifyInputArray(a, c); final int n = c.length; DerivativeStructure value = new DerivativeStructure(t.getFreeParameters(), t.getOrder(), a[n]); for (int i = n - 1; i >= 0; i--) { value = t.subtract(c[i]).multiply(value).add(a[i]); } return value; }
/** * {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { verifyInputArray(a, c); final int n = c.length; DerivativeStructure value = new DerivativeStructure(t.getFreeParameters(), t.getOrder(), a[n]); for (int i = n - 1; i >= 0; i--) { value = t.subtract(c[i]).multiply(value).add(a[i]); } return value; }