Add(Rational rational)
        {
            if (_denominator.Equals(rational._denominator))
            {
                return(new Rational(
                           _numerator + rational._numerator,
                           _denominator.Clone()));
            }

            Polynomial num   = (_numerator * rational._denominator) + (rational._numerator * _denominator);
            Polynomial denom = _denominator * rational._denominator;

            return(new Rational(num, denom));
        }
Exemplo n.º 2
0
 // TODO: Implement polynomial factorization to normalize rationals
 /// <summary>
 /// Initializes a new instance of the Rational class,
 /// by directly referencing the two provided polynomials (no deep copy).
 /// </summary>
 public Rational(
     Polynomial numerator,
     Polynomial denominator)
 {
     _numerator = numerator.Clone();
     _denominator = denominator.Clone();
 }
Exemplo n.º 3
0
        Add(
            Rational rational
            )
        {
            if (denominator.Equals(rational.denominator))
            {
                return(new Rational(
                           numerator + rational.numerator,
                           denominator.Clone()
                           ));
            }
            Polynomial num   = numerator * rational.denominator + rational.numerator * denominator;
            Polynomial denom = denominator * rational.denominator;

            return(new Rational(num, denom));
        }
 Rational(
     Polynomial numerator,
     Polynomial denominator)
 {
     _numerator   = numerator.Clone();
     _denominator = denominator.Clone();
 }
Exemplo n.º 5
0
 Rational(
     Polynomial numerator,
     Polynomial denominator
     )
 {
     this.numerator   = numerator.Clone();
     this.denominator = denominator.Clone();
 }
 Rational(
     Polynomial numerator,
     Polynomial denominator
     )
 {
     this.numerator = numerator.Clone();
     this.denominator = denominator.Clone();
 }
Exemplo n.º 7
0
 Divide(
     Polynomial polynomial
     )
 {
     return(new Rational(
                numerator.Clone(),
                denominator * polynomial
                ));
 }
Exemplo n.º 8
0
        /// <summary>
        /// substraction of two Polynomials (piecewise)
        /// </summary>
        /// <param name="a">left Polynomial</param>
        /// <param name="b">right Polynomial</param>
        /// <returns>resulting Polynomial</returns>
        public static Polynomial Substract(Polynomial a, Polynomial b)
        {
            var aa = a.Clone() as Polynomial;
            var bb = b.Clone() as Polynomial;

            if (aa.Degree != bb.Degree)
            {
                mkSameLength(ref aa, ref bb);
            }

            int n = aa.Degree;

            double[] res = new double[n];


            for (int ii = 0; ii < n; ii++)
            {
                res[ii] = aa.Coeffs[ii] - bb.Coeffs[ii];
            }
            Polynomial res_poly = new Polynomial(res);

            return(res_poly);
        }
Exemplo n.º 9
0
        /// <summary>
        /// pointwise multiplication of two Polynomials
        /// </summary>
        /// <param name="a">left Polynomial</param>
        /// <param name="b">right Polynomial</param>
        /// <returns>resulting Polynomial</returns>
        public static Polynomial MultiplyPointwise(Polynomial a, Polynomial b)
        {
            var aa = a.Clone() as Polynomial;
            var bb = b.Clone() as Polynomial;

            if (aa.Coeffs.Length != bb.Coeffs.Length)
            {
                mkSameLength(ref aa, ref bb);
            }

            int n = aa.Coeffs.Length;

            double[] res = new double[aa.Coeffs.Length];


            for (int ii = 0; ii < n; ii++)
            {
                res[ii] = aa.Coeffs[ii] * bb.Coeffs[ii];
            }
            Polynomial res_poly = new Polynomial(res);

            return(res_poly);
        }
Exemplo n.º 10
0
 Divide(
     Polynomial polynomial
     )
 {
     return(new Rational(Clone(), polynomial.Clone()));
 }
Exemplo n.º 11
0
        public Rational Divide(Polynomial polynomial)
		{
			return new Rational(Clone(),polynomial.Clone());
		}