Esempio n. 1
0
        /// <summary>
        /// Returns real roots of the specified polynomial which belongs to the specified interval
        /// </summary>
        /// <param name="input"></param>
        /// <param name="lowerBound">lower boundary of the interval</param>
        /// <param name="upperBound">upper boundary of the interval</param>
        /// <returns></returns>
        public static decimal[] RealRoots(Polynomial input, decimal lowerBound, decimal upperBound)
        {
            List<decimal> output = new List<decimal>();
            Complex[] roots = input.Roots();
            foreach (Complex c in roots)
            {
                if (c.IsReal() && !output.Contains((decimal)c.Re) && ((decimal)c.Re) >= lowerBound && ((decimal)c.Re) <= upperBound)
                    output.Add((decimal)c.Re);
            }

            return output.ToArray();
        }