示例#1
0
        /// <summary>
        /// The method returns product of polynominal addition
        /// </summary>
        /// <param name="poly">Polynominal coefficients (vector starting with free term)</param>
        /// <returns>Polynominal</returns>
        public Polynominal Add(Polynominal poly)
        {
            int         M        = this.Degree();
            int         N        = poly.Degree();
            int         K        = Math.Max(M, N);
            Polynominal Poly1Ext = new Polynominal(K);
            Polynominal Poly2Ext = new Polynominal(K);
            Polynominal Add      = new Polynominal(K);

            for (int m = 0; m < M + 1; m++)
            {
                Poly1Ext.SetElement(m, this.Element(m));
            }

            for (int n = 0; n < N + 1; n++)
            {
                Poly2Ext.SetElement(n, poly.Element(n));
            }

            for (int k = 0; k < K + 1; k++)
            {
                Add.SetElement(k, Poly1Ext.Element(k) + Poly2Ext.Element(k));
            }

            return(Add);
        }
示例#2
0
        /// <summary>
        /// The method returns product of polynominal multiplication by scalar
        /// </summary>
        /// <param name="Value">Complex value</param>
        /// <returns>Polynominal</returns>
        public Polynominal Scale(Complex Value)
        {
            Polynominal scale = new Polynominal(this.Degree());

            for (int i = 0; i < this.Degree() + 1; i++)
            {
                scale.SetElement(i, this.Element(i) * Value);
            }

            return(scale);
        }
示例#3
0
        /// <summary>
        /// The method calculates polynominal derivative
        /// </summary>
        /// <returns>Polynominal</returns>
        public Polynominal Derivative()
        {
            int         Degree     = this.Degree();
            int         NumCoefs   = Degree + 1;
            Polynominal Derivative = new Polynominal(this.Degree() - 1);

            if (Degree > 0)
            {
                for (int i = 1; i < NumCoefs; i++)
                {
                    Derivative.SetElement(i - 1, i * this.Element(i));
                }
            }
            else
            {
                return(new Polynominal(new Double[1] {
                    0
                }));
            }

            return(Derivative);
        }
示例#4
0
        /// <summary>
        /// The method calculates polynominal roots
        /// </summary>
        /// <param name="Seed">Seed root (if unknown any complex number can be given)</param>
        /// <param name="Accuracy">Result accuracy</param>
        /// <returns>Polynominal roots</returns>
        public Complex[] Roots(Complex Seed, Double Accuracy)
        {
            int N = this.Degree();

            Complex[] Roots  = new Complex[N];
            int       degree = N;

            Polynominal tmpoly = this;

            for (int n = 0; n < N; n++)
            {
                while (true)
                {
                    Complex _tmp0 = tmpoly.Derivative().Evaluate(Seed);
                    Complex _tmp1 = (degree - 1) * Complex.Pow(tmpoly.Derivative().Evaluate(Seed), 2);
                    Complex _tmp2 = degree * tmpoly.Evaluate(Seed) * tmpoly.Derivative().Derivative().Evaluate(Seed);
                    Complex _tmp3 = Complex.Pow((degree - 1) * (_tmp1 - _tmp2), 0.5);
                    Complex _tmp4 = MaximizeResultAbsolute(_tmp0, _tmp3);

                    Seed = Seed - (degree * tmpoly.Evaluate(Seed)) / _tmp4;
                    Complex result = tmpoly.Evaluate(Seed);

                    if (Complex.Abs(result) < Math.Abs(Accuracy))
                    {
                        Roots[n] = Seed;
                        tmpoly   = tmpoly.ByBinominalDivision(Seed);
                        degree--;
                        Random _Random = new Random();
                        Seed = -10 + (_Random.NextDouble() * 15);
                        break;
                    }
                }
            }

            return(Roots);
        }
示例#5
0
 /// <summary>
 /// Subtracts two polynominals
 /// </summary>
 /// <param name="poly">Subtrahend polynominal</param>
 /// <returns>Difference</returns>
 public Polynominal Sub(Polynominal poly)
 {
     return(this.Add(poly.Scale(-1)));
 }