Пример #1
0
 public OneVariableMonomial Divide(OneVariableMonomial otherMonomial)
 {
     if (this.degree < otherMonomial.degree)
     {
         throw new Exception("Division is not closed under the field of monomials. To yield another monomial, degree of numerator must be greater!");
     }
     else
     {
         return(new OneVariableMonomial(this.degree - otherMonomial.degree, this.coefficient / otherMonomial.coefficient));
     }
 }
Пример #2
0
        public OneVariablePolynomial Multiply(OneVariableMonomial monomial)
        {
            if (monomial.coefficient == 0)
            {
                return(new OneVariablePolynomial());
            }

            List <double> result = new List <double>(new double[this.coefficients.Count + monomial.degree]);

            for (int i = 0; i < this.coefficients.Count; i++)
            {
                result[i + monomial.degree] = this.coefficients[i] * monomial.coefficient;
            }

            return(new OneVariablePolynomial(result));
        }
Пример #3
0
        /// <summary>
        /// Divides the polynomial with the divisor.
        /// </summary>
        /// <param name="divisor">The divisor. Denoted by g in the CLO book.</param>
        /// <returns>The quotient and remainder in the form of a tuple.</returns>
        public Dictionary <string, OneVariablePolynomial> Divide(OneVariablePolynomial divisor)
        {
            OneVariablePolynomial quotient  = new OneVariablePolynomial();
            OneVariablePolynomial remainder = this;

            while (!remainder.IsZero() && divisor.LeadingTerm().degree <= remainder.LeadingTerm().degree)
            {
                OneVariableMonomial update = remainder.LeadingTerm().Divide(divisor.LeadingTerm());
                quotient  = quotient.Add(new OneVariablePolynomial(update));
                remainder = remainder.Add(divisor.Multiply(update), false); // A false addition is basically a subtraction.
            }

            return(new Dictionary <string, OneVariablePolynomial>()
            {
                { "quotient", quotient },
                { "remainder", remainder }
            });
        }
Пример #4
0
 public OneVariablePolynomial(OneVariableMonomial monomial)
 {
     this.coefficients = new List <double>(new double[monomial.degree + 1]);
     this.coefficients[monomial.degree] = monomial.coefficient;
 }