Ejemplo n.º 1
0
        /// <summary>
        /// Operator to multiply a polynomial per an monomial.
        /// </summary>
        /// <param name="polynomial">
        /// The polynomial.
        /// </param>
        /// <param name="monomial">
        /// The monomial.
        /// </param>
        /// <returns>
        /// Polynomial
        /// </returns>
        public static Polynomial operator *(Polynomial polynomial, Monomial monomial)
        {
            Polynomial p = polynomial.Clone();

            if (monomial.Coefficient.Equals(0))
            {
                p.Monomials.Clear();
                p.Coefficient = 0;
            }
            else
            {
                var arrayController = ArrayController.GetInstance();
                Dictionary <string, Monomial> monomialCollection = arrayController.CloneDictionary(p.Monomials);

                foreach (var monomialInCollection in monomialCollection.Values)
                {
                    string oldKey = monomialInCollection.VariablesToString();

                    monomialInCollection.Multiply(monomial);
                    string key = monomialInCollection.VariablesToString();

                    if (!p.Monomials.ContainsKey(key))
                    {
                        p.Monomials.Add(key, monomialInCollection);
                    }
                    else
                    {
                        p.Monomials[key] = monomialInCollection;
                    }

                    p.Monomials.Remove(oldKey);
                }

                if (!p.Coefficient.Equals(0))
                {
                    Monomial maux = monomial.Clone();
                    maux.Multiply(p.Coefficient);
                    string key = monomial.VariablesToString();

                    if (!p.Monomials.ContainsKey(key))
                    {
                        p.Monomials.Add(key, maux);
                    }
                    else
                    {
                        p.Monomials[key] = maux;
                    }
                }

                p.Coefficient = 0;
            }

            return(p);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the mcm of the denominators's fractions
        /// </summary>
        /// <param name="af1"></param>
        /// <returns></returns>
        private Polynomial GetMcm(AlgebraicFraction af1)
        {
            // Calculate the mcm of the denominators obtaining a new denominator
            Polynomial oldDenominator = af1.Denominator;

            var arrayController = ArrayController.GetInstance();

            af1.Denominator = arrayController.GetMcm(
                new[]
            {
                af1.Denominator,
                this.Denominator
            }
                ).GetExplicitPolynomial();

            return(oldDenominator);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the opposite or the minus monomial.
        /// </summary>
        /// <returns>
        /// The <see cref="Monomial"/>.
        /// </returns>
        public Monomial ReverseOf()
        {
            var arrayController = ArrayController.GetInstance();

            return(new Monomial(-this.Coefficient, arrayController.CloneDictionary(this.Variables)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a clone of the polynomial
        /// </summary>
        /// <returns></returns>
        public Polynomial Clone()
        {
            var arrayController = ArrayController.GetInstance();

            return(new Polynomial(this.Coefficient, arrayController.CloneDictionary(this.Monomials).Values.ToArray()));
        }