// ----------------------------------- // ----- instance methods ------------ // ----------------------------------- /// <summary> /// Tests whether the point is located inside the interval bounds. /// </summary> /// <param name="x">The point to test.</param> /// <returns>True if the interval contains the specified point, false otherwise.</returns> public bool Contains(T x) { return ((calc.mor(x, LeftBound) && calc.mor(RightBound, x)) || (IsLeftInclusive && calc.eqv(LeftBound, x)) || (IsRightInclusive && calc.eqv(RightBound, x))); }
public override bool Equals(object obj) { if (obj is LagrangePolynom <T, C> ) { LagrangePolynom <T, C> poly = obj as LagrangePolynom <T, C>; // Если количество точек совпадает, проверяем поточечно. if (poly.points.Length == this.points.Length) { for (int i = 0; i < poly.points.Length; i++) { if (!calc.eqv(this.points[i].X, poly.points[i].X) || !calc.eqv(this.points[i].Y, poly.points[i].Y)) { return(false); } } return(true); } // Если количество точек не совпадает, то... // К сожалению, может иметь место линейная зависимость. // Например, параболу тоже при желании можно определить по пяти точкам. // Единственный выход - приводить все к канонической форме и сравнивать по коэффициентам. return(this.AsStandardPolynom.Equals(poly.AsStandardPolynom)); } else if (obj is Polynom <T, C> ) { return(this.AsStandardPolynom.Equals(obj as Polynom <T, C>)); } return(false); }
/// <summary> /// Returns the runs test series count for a sequence of observations. /// The sample median for that sequence must first be calculated. /// </summary> /// <typeparam name="T">The type of observations' values.</typeparam> /// <typeparam name="C">The calculator for the <typeparamref name="T"/> type.</typeparam> /// <param name="values">The list of observations.</param> /// <param name="sampleMedian">The sample median of the observations' sequence.</param> /// <returns>The amount of series for the runs test.</returns> public static int RunsTest_SeriesCount <T, C>(this IEnumerable <T> values, T sampleMedian) where C : ICalc <T>, new() { int count = values.Count(); if (count == 0) { throw new ArgumentException("Cannot return the series count for an empty sequence."); } else if (count == 1) { return(0); } int signChanges = 0; IEnumerator <T> enumerator = values.GetEnumerator(); ICalc <T> calc = Numeric <T, C> .Calculator; enumerator.MoveNext(); // Find the first value not equal to the median. // - while (calc.eqv(enumerator.Current, sampleMedian)) { if (enumerator.MoveNext() == false) { return(0); } } bool isPlus = calc.mor(enumerator.Current, sampleMedian); while (enumerator.MoveNext()) { if (!isPlus && calc.mor(enumerator.Current, sampleMedian)) { signChanges++; isPlus = true; } else if (isPlus && calc.mor(sampleMedian, enumerator.Current)) { signChanges++; isPlus = false; } } return(signChanges + 1); }