public static Polynomial Multiplication(Polynomial a, double b) { Polynomial newPolynomial = a.Clone(); for (int i = 0; i < newPolynomial.coefficients.Length; i++) { newPolynomial.coefficients[i] *= b; } return(newPolynomial); }
public static Polynomial Division(Polynomial a, double b) { if (b == 0) { throw new DivideByZeroException(); } Polynomial newPolynomial = a.Clone(); for (int i = 0; i < newPolynomial.coefficients.Length; i++) { newPolynomial.coefficients[i] /= b; } return(newPolynomial); }
public static Polynomial Add(Polynomial a, Polynomial b) { if (ReferenceEquals(a, b)) { throw new ArgumentNullException("a"); } if (ReferenceEquals(lhs, null)) { throw new ArgumentNullException("a"); } Polynomial newPolynomial = a.Clone(); int j = a.coefficients.Length - 1; if (a.coefficients.Length != b.coefficients.Length) { j = newPolynomial.coefficients.Length - (newPolynomial.coefficients.Length - b.coefficients.Length); } for (int i = b.coefficients.Length - 1; i > -1; i--) { newPolynomial.coefficients[j--] += b.coefficients[i]; } return(newPolynomial); }