Example #1
0
        public Polynomial Subtract(Polynomial polynomial)
        {
            Polynomial difference = new Polynomial();

            // Traverse to add the terms of this polynomial
            foreach (Monomial monomial in terms)
            {
                difference.Append(new Monomial(monomial.Coefficient, monomial.Exponent));
            }
            // Traverse to add the inverse terms of received polyomial
            foreach (Monomial monomial in polynomial.terms)
            {
                difference.Append(new Monomial(-monomial.Coefficient, monomial.Exponent));
            }
            return(difference);
        }
Example #2
0
        public Polynomial Add(Polynomial polynomial)
        {
            Polynomial sum = new Polynomial();

            // Traverse to add the terms of this polynomial
            foreach (Monomial monomial in terms)
            {
                sum.Append(new Monomial(monomial.Coefficient, monomial.Exponent));
            }
            // Traverse to add the terms of received polyomial
            foreach (Monomial monomial in polynomial.terms)
            {
                sum.Append(new Monomial(monomial.Coefficient, monomial.Exponent));
            }
            return(sum);
        }
Example #3
0
        public Polynomial Multiply(Polynomial polynomial)
        {
            Polynomial product = new Polynomial();

            // Traverse the terms of this polynomial
            foreach (Monomial m1 in terms)
            {
                // Traverse to terms of received polyomial
                foreach (Monomial m2 in polynomial.terms)
                {
                    // Multiply each pair of monomials and
                    // add to product
                    product.Append(m1.Multiply(m2));
                }
            }
            return(product);
        }