Interpolate( double t, out double error ) { if (null == _samples) { throw new InvalidOperationException(Resources.InvalidOperationNoSamplesProvided); } const double tiny = 1.0e-15; int closestIndex; int offset = SuggestOffset(t, out closestIndex); double[] c = new double[_effectiveOrder]; double[] d = new double[_effectiveOrder]; int ns = closestIndex - offset; double den, ho, hp; double x = 0; error = 0; if (_samples.GetT(closestIndex) == t) { return(_samples.GetX(closestIndex)); } for (int i = 0; i < _effectiveOrder; i++) { c[i] = _samples.GetX(offset + i); d[i] = c[i] + tiny; // prevent rare zero-over-zero condition } x = _samples.GetX(offset + ns--); for (int level = 1; level < _effectiveOrder; level++) { for (int i = 0; i < _effectiveOrder - level; i++) { hp = _samples.GetT(offset + i + level) - t; ho = (_samples.GetT(offset + i) - t) * d[i] / hp; den = ho - c[i + 1]; if (den == 0) { // TODO (cdr, 2006-06-09): Check sign (positive or negative infinity?) error = 0; return(double.PositiveInfinity); // or is it NegativeInfinity? } den = (c[i + 1] - d[i]) / den; d[i] = c[i + 1] * den; c[i] = ho * den; } error = (2 * (ns + 1) < (_effectiveOrder - level) ? c[ns + 1] : d[ns--]); x += error; } return(x); }
Interpolate( double t ) { if (null == _samples) { throw new InvalidOperationException(Resources.InvalidOperationNoSamplesProvided); } const double tiny = 1.0e-15; int closestIndex; int offset = SuggestOffset(t, out closestIndex); double[] c = new double[_effectiveOrder]; double[] d = new double[_effectiveOrder]; int ns = closestIndex - offset; if (Number.AlmostEqual(_samples.GetT(closestIndex), t)) { return(_samples.GetX(closestIndex)); } for (int i = 0; i < _effectiveOrder; i++) { c[i] = _samples.GetX(offset + i); d[i] = c[i] + tiny; // prevent rare zero-over-zero condition } double x = _samples.GetX(offset + ns--); for (int level = 1; level < _effectiveOrder; level++) { for (int i = 0; i < _effectiveOrder - level; i++) { double hp = _samples.GetT(offset + i + level) - t; double ho = (_samples.GetT(offset + i) - t) * d[i] / hp; double den = ho - c[i + 1]; if (Number.AlmostZero(den)) { // BUGBUG: check - positive or negative infinity? return(double.PositiveInfinity); } den = (c[i + 1] - d[i]) / den; d[i] = c[i + 1] * den; c[i] = ho * den; } x += (2 * (ns + 1) < (_effectiveOrder - level) ? c[ns + 1] : d[ns--]); } return(x); }
public double Interpolate(double t, out double error) { if (samples == null) { throw new InvalidOperationException("No Samples Provided. Preparation Required."); } const double tiny = 1.0e-15; int closestIndex; int offset = SuggestOffset(t, out closestIndex); double[] c = new double[effectiveOrder]; double[] d = new double[effectiveOrder]; int ns = closestIndex - offset; double den, ho, hp; double x = 0; error = 0; if (samples.GetT(closestIndex) == t) { return(samples.GetX(closestIndex)); } for (int i = 0; i < effectiveOrder; i++) { c[i] = samples.GetX(offset + i); d[i] = c[i] + tiny; //prevent rare zero-over-zero condition } x = samples.GetX(offset + ns--); for (int level = 1; level < effectiveOrder; level++) { for (int i = 0; i < effectiveOrder - level; i++) { hp = samples.GetT(offset + i + level) - t; ho = (samples.GetT(offset + i) - t) * d[i] / hp; den = ho - c[i + 1]; if (den == 0) { #warning : Check sign (positive or negative infinity?) error = 0; return(double.PositiveInfinity); //or is it NegativeInfinity? } den = (c[i + 1] - d[i]) / den; d[i] = c[i + 1] * den; c[i] = ho * den; } error = (2 * (ns + 1) < (effectiveOrder - level) ? c[ns + 1] : d[ns--]); x += error; } return(x); }
Interpolate( double t, out double error ) { if (null == _samples) { throw new InvalidOperationException(Resources.InvalidOperationNoSamplesProvided); } int closestIndex; int offset = SuggestOffset(t, out closestIndex); double[] c = new double[_effectiveOrder]; double[] d = new double[_effectiveOrder]; int ns = closestIndex - offset; double den, ho, hp; double x = 0; error = 0; if (_samples.GetT(closestIndex) == t) { return(_samples.GetX(closestIndex)); } for (int i = 0; i < _effectiveOrder; i++) { c[i] = _samples.GetX(offset + i); d[i] = c[i]; } x = _samples.GetX(offset + ns--); for (int level = 1; level < _effectiveOrder; level++) { for (int i = 0; i < _effectiveOrder - level; i++) { ho = _samples.GetT(offset + i) - t; hp = _samples.GetT(offset + i + level) - t; den = (c[i + 1] - d[i]) / (ho - hp); d[i] = hp * den; c[i] = ho * den; } error = (2 * (ns + 1) < (_effectiveOrder - level) ? c[ns + 1] : d[ns--]); x += error; } return(x); }
Interpolate(double t) { if (null == _samples) { throw new InvalidOperationException(Properties.LocalStrings.InvalidOperationNoSamplesProvided); } int closestIndex; int offset = SuggestOffset(t, out closestIndex); double[] c = new double[_effectiveOrder]; double[] d = new double[_effectiveOrder]; int ns = closestIndex - offset; if (Number.AlmostEqual(_samples.GetT(closestIndex), t)) { return(_samples.GetX(closestIndex)); } for (int i = 0; i < _effectiveOrder; i++) { c[i] = _samples.GetX(offset + i); d[i] = c[i]; } double x = _samples.GetX(offset + ns--); for (int level = 1; level < _effectiveOrder; level++) { for (int i = 0; i < _effectiveOrder - level; i++) { double ho = _samples.GetT(offset + i) - t; double hp = _samples.GetT(offset + i + level) - t; double den = (c[i + 1] - d[i]) / (ho - hp); d[i] = hp * den; c[i] = ho * den; } x += (2 * (ns + 1) < (_effectiveOrder - level) ? c[ns + 1] : d[ns--]); } return(x); }