/// <summary> /// Factory method to create the required implementation of the interpolation algorithm /// </summary> /// <param name="fit">interpolation algorithm type</param> /// <param name="standards">Data points to be fitted</param> /// <returns>Interpolation algorithm</returns> public static Interpolator Create(CurveFits fit, IEnumerable <DPoint> standards) { Interpolator interp = null; //ensure points are sorted in order of x values List <DPoint> standardsList = new List <DPoint>(standards); standardsList.Sort((a, b) => a.X.CompareTo(b.X)); switch (fit) { case CurveFits.Interpolate: interp = new SimpleInterpolator(standardsList); break; case CurveFits.LinearZero: interp = new BestLineThruOriginInterpolation(standardsList); break; case CurveFits.Linear: interp = new BestLineInterpolation(standardsList); break; case CurveFits.Quadratic: interp = new QuadraticInterpolator(standardsList); break; case CurveFits.QuadraticThruZero: interp = new QuadraticThruZeroInterpolator(standardsList); break; default: break; } return(interp); }
public void CoefficientsTest() { QuadraticInterpolator target = new QuadraticInterpolator(standards()); double[] actual; actual = target.Coefficients(); Assert.AreEqual(3, actual.Length); Assert.AreEqual(8, actual[0]); Assert.AreEqual(-3, actual[1]); Assert.AreEqual(2, actual[2]); }
/// <summary> /// Factory method to create the required implementation of the interpolation algorithm /// </summary> /// <param name="fit">interpolation algorithm type</param> /// <param name="standards">Data points to be fitted</param> /// <returns>Interpolation algorithm</returns> public static Interpolator Create(CurveFits fit, IEnumerable<DPoint> standards) { Interpolator interp = null; //ensure points are sorted in order of x values List<DPoint> standardsList = new List<DPoint>(standards); standardsList.Sort((a, b) => a.X.CompareTo(b.X)); switch (fit) { case CurveFits.Interpolate: interp = new SimpleInterpolator(standardsList); break; case CurveFits.LinearZero: interp = new BestLineThruOriginInterpolation(standardsList); break; case CurveFits.Linear: interp = new BestLineInterpolation(standardsList); break; case CurveFits.Quadratic: interp = new QuadraticInterpolator(standardsList); break; case CurveFits.QuadraticThruZero: interp = new QuadraticThruZeroInterpolator(standardsList); break; default: break; } return interp; }
public void QuadraticCalculateTest() { QuadraticInterpolator target = new QuadraticInterpolator(standards()); Assert.AreEqual("0.9987", target.RSquared().ToString("0.0000")); //passes thru origin Assert.AreEqual("-9.950", target.Calculate(0).ToString("0.000")); Assert.AreEqual("-742059.95", target.Calculate(1000).ToString("0.00")); }