/// <summary> /// Gets the amount of polynom sequence's sign variations either /// at positive or negative infinity using polynom's degree and the sign of its higher coefficient. /// /// Works fast. /// </summary> /// <typeparam name="T">The type of polynom coefficients.</typeparam> /// <typeparam name="C">The calculator for the coefficients' type.</typeparam> /// <param name="list">The sequence of polynoms to be evaluated for sign variations.</param> /// <param name="negativeInfinity">If this flag is set to FALSE, the evalution is at positive infinity. Otherwise, at negative infinity.</param> /// <returns>The number of polynom's sign variations.</returns> public static int InfinitySignVariations <T, C>(this IList <Polynom <T, C> > list, bool negativeInfinity) where C : ICalc <T>, new() { int signPrev = 0; int signNew = 0; int k = 0; for (int i = 0; i < list.Count; i++) { if (list[i].Degree == 0) { signNew = WhiteMath <T, C> .Sign(list[i][0]); } else { signNew = WhiteMath <T, C> .Sign(list[i][list[i].Degree]) * (negativeInfinity ? ((list[i].Degree % 2 == 0 ? 1 : -1)) : 1); } if (signNew == 0) { continue; } else if (signNew != signPrev && signPrev != 0) { k++; } signPrev = signNew; } return(k); }
// -------------------------------------------- // --------- ЗНАК ФУНКЦИИ --------------------- // -------------------------------------------- /// <summary> /// Returns the number of sign variations in the function list for some certain /// point. /// </summary> /// <typeparam name="T">The type of polynom coefficients.</typeparam> /// <typeparam name="C">The type of polynom coefficients' calculator.</typeparam> /// <param name="list">The list of the polynoms to be analyzed.</param> /// <returns>The number of sign variations within the list. Zero values do not count.</returns> public static int SignVariations <T, C>(this IList <IFunction <T, T> > list, Numeric <T, C> point) where C : ICalc <T>, new() { int signPrev = 0; int signNew = 0; int k = 0; for (int i = 0; i < list.Count; i++) { signNew = WhiteMath <T, C> .Sign(list[i].Value(point)); if (signPrev == 0) { if (signNew != 0) { k++; } else { continue; } } else if (signPrev < 0 || signPrev > 0) { if (signNew != 0) { k++; } else { continue; } } signPrev = signNew; } return(k); }