Example #1
0
        // ----------------------------
        // ----------------------------
        // ----------------------------

        /// <summary>
        /// Gets the grapher points array as specified.
        /// </summary>
        /// <returns></returns>
        public Point <double>[] GetPointsArray()
        {
            Point <double>[] arr = new Point <double> [PointsArray.Count];

            ServiceMethods.Copy(PointsArray, arr);
            return(arr);
        }
Example #2
0
        /// <summary>
        /// Performs the polynom division with the remainder.
        /// </summary>
        /// <param name="one">The dividend polynom.</param>
        /// <param name="two">The divisor polynom.</param>
        /// <param name="rem">The reference to the polynom to which the remainder result will be assigned.</param>
        /// <returns>The division result.</returns>
        public static Polynom <T, C> Div(Polynom <T, C> one, Polynom <T, C> two, out Polynom <T, C> rem)
        {
            if (one.Degree < two.Degree)
            {
                rem = one.Clone() as Polynom <T, C>;
                return(new Polynom <T, C>(Numeric <T, C> .Zero));
            }

            Numeric <T, C>[] oneCopy = new Numeric <T, C> [one.coefficients.Length];
            Numeric <T, C>[] result  = new Numeric <T, C> [one.Degree - two.Degree + 1];

            ServiceMethods.Copy(one.coefficients, oneCopy);

            for (int i = oneCopy.Length - 1; i >= two.Degree; i--)
            {
                // Очередной коэффициент результата
                result[result.Length - oneCopy.Length + i] = oneCopy[i] / two.coefficients[two.coefficients.Length - 1];

                // При обратном умножении получаем ноль в соответствующем коэффициенте.
                oneCopy[i] = Numeric <T, C> .Zero;

                // Теперь из делимого вычтем делитель, умноженный на полученный коэффициент.
                for (int j = two.coefficients.Length - 2; j >= 0; j--)
                {
                    oneCopy[i + j - two.coefficients.Length + 1] -= two.coefficients[j] * result[result.Length - oneCopy.Length + i];
                }
            }

            rem = new Polynom <T, C>(oneCopy);

            return(new Polynom <T, C>(result));
        }
Example #3
0
        /// <summary>
        /// Returns the standard array grapher scaled by points array indices.
        /// </summary>
        /// <param name="minInd">The lower index of points array to copy to the new grapher.</param>
        /// <param name="maxInd">The upper index of points array to copy to the new grapher.</param>
        /// <returns></returns>
        public StandardGrapher newGrapherByIndexBounds(int minInd, int maxInd)
        {
            // проверяем корректность границ заданных индексов

            if (minInd >= maxInd)
            {
                throw new GrapherActionImpossibleException(String.Format("Неверно заданы границы отрезка масштабирования: индексы начала ({0}) больше или совпадает с индексом конца ({1}).", minInd, maxInd));
            }
            if (minInd < 0 || maxInd >= PointsArray.Count)
            {
                throw new GrapherActionImpossibleException("Неверно заданы границы отрезка масштабирования: индексы выходят за границы массива.");
            }

            // создаем копию объекта

            StandardGrapher temp = (StandardGrapher)this.MemberwiseClone();

            // temp.PointsArray = new Point<double>[maxInd - minInd + 1 + (minInd == 0 ? 0 : 1) + (maxInd == PointsArray.Count - 1 ? 0 : 1)];
            // ServiceMethods.Copy(this.PointsArray, minInd - (minInd == 0 ? 0 : 1), temp.PointsArray, 0, (maxInd == (PointsArray.Count - 1) ? maxInd : maxInd + 1) - (minInd == 0 ? minInd : (minInd - 1)) + 1);

            temp.PointsArray = new Point <double> [maxInd - minInd + 1];
            ServiceMethods.Copy(this.PointsArray, minInd, temp.PointsArray, 0, maxInd - minInd + 1);

            // находим новые минимальные и максимальные значения

            temp.FindMaximumsAndMinimums();

            if (Step1 != 0 && Step2 != 0)
            {
                temp.Step1 = this.Step1 * (temp.xMax - temp.xMin) / (this.xMax - this.xMin);
                temp.Step2 = this.Step2 * (temp.yMax - temp.yMin) / (this.yMax - this.yMin);
                if (this.yMax == this.yMin)
                {
                    temp.Step2 = this.Step2;
                }
            }

            return(temp);
        } // масштабированный по номеру измерения аргумента графер