Question: namespace Polynomials { class polynomial { private int[] poly = new int[1]; public int degree = 0; public polynomial(params int[] poly) { this.poly = new

 namespace Polynomials { class polynomial { private int[] poly = new

namespace Polynomials { class polynomial { private int[] poly = new int[1]; public int degree = 0;

public polynomial(params int[] poly) { this.poly = new int[poly.Length];

for (int i = 0; i

public int Degree() //calcultes the degree of the polynomial { for (int i = 0; i

public polynomial deriv(polynomial p2) //calculates thd derivative of a polynomial { int[] deriv = new int[p2.poly.Length-1]; //deriv degree must be one smaller

for (int i = 0; i

public polynomial Product(polynomial p2) //calculates the product of two polynomials { int[] prod = new int[p2.poly.Length * poly.Length]; for (int i = 0; i

polynomial ans = new polynomial(prod); return ans; }

public polynomial Sum(polynomial p2) //calculates the sum of two polynomials { int[] sum;

if (p2.poly.Length > poly.Length) //determines larger degree poly sum = new int[p2.poly.Length]; else sum = new int[poly.Length]; //sets sum array size to larger poly

for (int i = 0; i p2.poly.Length - 1) sum[i] = poly[i]; else sum[i] = p2.poly[i]; }

polynomial ans = new polynomial(sum); return ans; }

public double Newtonsmethod(polynomial p2, double guess) // calculates a root from an initial gues using newton's method { double xn = 13.3; double xn1 = guess; double diff = xn - xn1; while ( diff > 0.0000001 && diff

if (Math.Abs(polyEval(p2, xn))

public double polyEval(polynomial p2, double input) //evaluates a polynomial at specified value { double value = 0; for(int i = poly.Length - 1; i >= 0; i--) { value += poly[i] * Math.Pow(input, i); } return value; }

public void Print() // prints polynomial { for (int i = this.poly.Length - 1; i >= 0; i--) { if (this.poly[i] == 0) continue; else if (i == 1) { if (this.poly[i] == 1) Console.Write("x + "); else Console.Write("{0}x + ", this.poly[i]); } else if (i == 0) Console.Write("{0}", this.poly[i]); else { if (this.poly[i] == 1) Console.Write("x^{0} + ", i); else Console.Write("{0}x^{1} + ", this.poly[i], i); } } //end for Console.WriteLine(" ");

} //end print

public override string ToString() { return base.ToString(); }

public override bool Equals(object obj) { return base.Equals(obj); }

public override int GetHashCode() { return base.GetHashCode(); } } //end class

} //end namespace

Division of two polynomials (2690) In midterm in class, you had done sum and product of two real polynomials ax) and bx) in Q4 and Q5 then (26%) Create a method (in your class Polynomial before) Division that (a) (12%) Calculates the quotient q(x) and remainder r(x) when a(x) is divided b(x) with a(x) 3. - b(x) q(x) + r(x) For example, if a(x) = 1+xtx2 and b(x) = 1 ts, then q(x) = x, and r(x) = 1. (b) (5%) Verify programmatically that with your calculated q(x) and r(s) using your a(x), here you'll use your product method in QS of Division method, b(x) q(x) + r(x) midterm in class. (c) (9%) Test your code using three pairs of a(x) and b(s). Pair 1: a(x)-1+x+x2 and b(x) 1+x, Pair 2: a(x) = 1+x+x5 and b(x) = 1+x+x2 and Pair 3 a(x) a polynomial of degree 10 and b(x) a polynomial of degree 3. Division of two polynomials (2690) In midterm in class, you had done sum and product of two real polynomials ax) and bx) in Q4 and Q5 then (26%) Create a method (in your class Polynomial before) Division that (a) (12%) Calculates the quotient q(x) and remainder r(x) when a(x) is divided b(x) with a(x) 3. - b(x) q(x) + r(x) For example, if a(x) = 1+xtx2 and b(x) = 1 ts, then q(x) = x, and r(x) = 1. (b) (5%) Verify programmatically that with your calculated q(x) and r(s) using your a(x), here you'll use your product method in QS of Division method, b(x) q(x) + r(x) midterm in class. (c) (9%) Test your code using three pairs of a(x) and b(s). Pair 1: a(x)-1+x+x2 and b(x) 1+x, Pair 2: a(x) = 1+x+x5 and b(x) = 1+x+x2 and Pair 3 a(x) a polynomial of degree 10 and b(x) a polynomial of degree 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!