public static Polynomial operator +(Polynomial x, Polynomial y) { int biggerDegree = Math.Max(x.PolynomialDegree, y.PolynomialDegree); Polynomial result = new Polynomial(); double tmp = 0.0; for (int i = 0; i <= biggerDegree; ++i) { tmp = 0.0; if (i <= x.PolynomialDegree) { tmp += x[i]; } if (i <= y.PolynomialDegree) { tmp += y[i]; } result.AddCoefficient(tmp); } result.Normalize(); return(result); }
public static Polynomial operator -(Polynomial x) { Polynomial result = new Polynomial(); for (int i = 0; i <= x.PolynomialDegree; ++i) { result.AddCoefficient(-x[i]); } return(result); }
public static Polynomial operator *(Polynomial x, Polynomial y) { Polynomial result = new Polynomial(); for (int i = 0; i <= x.PolynomialDegree; ++i) { for (int j = 0; j <= y.PolynomialDegree; ++j) { if (result.PolynomialDegree < i + j) { result.AddCoefficient(0.0); } result[i + j] += x[i] * y[j]; } } result.Normalize(); return(result); }
public static Polynomial operator +(Polynomial x, Polynomial y) { int biggerDegree = Math.Max(x.PolynomialDegree, y.PolynomialDegree); Polynomial result = new Polynomial(); double tmp = 0.0; for (int i = 0; i <= biggerDegree; ++i) { tmp = 0.0; if (i <= x.PolynomialDegree) { tmp += x[i]; } if (i <= y.PolynomialDegree) { tmp += y[i]; } result.AddCoefficient(tmp); } result.Normalize(); return result; }
public static Polynomial operator *(Polynomial x, Polynomial y) { Polynomial result = new Polynomial(); for (int i = 0; i <= x.PolynomialDegree; ++i) { for (int j = 0; j <= y.PolynomialDegree; ++j) { if (result.PolynomialDegree < i + j) { result.AddCoefficient(0.0); } result[i + j] += x[i] * y[j]; } } result.Normalize(); return result; }
public static Polynomial operator -(Polynomial x) { Polynomial result = new Polynomial(); for (int i = 0; i <= x.PolynomialDegree; ++i) { result.AddCoefficient(-x[i]); } return result; }