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)); }
// 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(); }
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(); }
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(); }
Divide( Polynomial polynomial ) { return(new Rational( numerator.Clone(), denominator * polynomial )); }
/// <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); }
/// <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); }
Divide( Polynomial polynomial ) { return(new Rational(Clone(), polynomial.Clone())); }
public Rational Divide(Polynomial polynomial) { return new Rational(Clone(),polynomial.Clone()); }