public static void TestOneVariablePolynomialDivision() { OneVariablePolynomial dividend = new OneVariablePolynomial(new double[] { 1, 1, 2, 1 }); OneVariablePolynomial divisor = new OneVariablePolynomial(new double[] { 1, 2 }); Dictionary <string, OneVariablePolynomial> result = dividend.Divide(divisor); System.Console.WriteLine(string.Join(",", result["quotient"].coefficients)); }
/// <summary> /// Finds the Greatest Common Divisor between this and another polynomial /// </summary> /// <param name="otherPolynomial">The other polynomial with which the GCD is to be calculated</param> /// <returns>The Greatest Common Divisor</returns> public OneVariablePolynomial GCD(OneVariablePolynomial otherPolynomial) { OneVariablePolynomial h = this; OneVariablePolynomial s = otherPolynomial; OneVariablePolynomial rem = new OneVariablePolynomial(); while (!s.IsZero()) { rem = h.Divide(s)["remainder"]; h = s; s = rem; } return(rem); }