Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Arrays Arrays are covered in chapter 8 of Deitel, but you have learned those concepts in ECE 114 already. Note the syntax of arrays in

Arrays

Arrays are covered in chapter 8 of Deitel, but you have learned those concepts in ECE 114 already. Note the syntax of arrays in C# is different from that of C (look at Figure 8.2 on page 289 for example). Even the simple 1 dimensional array and 2 dimensional arrays can be very useful (MATLAB is based on matrix, which is a special kind of 2 dimensional array).

Polynomials (59%) (as one dimensional array)

You have learned polynomials in high school, for example, the quadratic polynomial x2 5x + 4, the cubic polynomial x3 + x + 1 etc.

We will / can express x2 5x + 4 as an int array of 3 elements {4, -5, 1} starting with the constant item, and x3 + x + 1 as an int array {1, 1, 0, 1} again starting with the constant item 1. A general polynomial a n x n + a n-1 x n-1 + .. + a1x + a0 is expressed as { a0, a1, .., a n } starting from the lowest degree (constant) term a0.

(14%) Create a C# class Polynomial with two attributes, an array of real coefficients and an integer deg representing the degree of this polynomial (for simplicity, we assume we do not have polynomials of complex coefficients)

(2%) Create a class Polynomial with the array and degree. The degree of a polynomial a n x n + a n-1 x n-1 + .. + a1x + a0 is n. The degree of a constant polynomial is 0; sometimes the degree of the zero polynomial 0 is considered zero, minus infinite -, or some negative number as you feel appropriate.

(7%) Compute the derivative of the polynomial programmatically. For example, the derivative of x2 5x + 4 ({4, -5, 1}) is 2x + 5.

(5%) Define a print (or toString) method for the Polynomial. For example, x2 5x + 4 ({4, -5, 1} can be printed as x^2 -5x + 4.

Test this class (in PolynomialTest.cs) with at least two polynomials x2 5x + 4 and x3 + x + 1.

(8%) Create a method Sum that adds two polynomials. This method can be a standalone method that adds two polynomials or as a method in the class Polynomial you defined in question 3 above. Note the sum of two polynomials can have degree lower than either, for example, the sum of x2 5x + 4 and -x2 5x + 4 is -10x + 8.

Test your method with at least two pairs of polynomials, the pair x2 5x + 4 and x3 + x + 1, and the pair of x2 5x + 4 and - x2 5x + 4.

(15%) Create a method Product that calculates the products of two polynomials.

Product c(x) of two polynomials a(x) and b(x) means that for every coefficient c k of the k-th power x k, c k is the sum of a i and b k-i with i ranging from 0 to k. This one seems very obvious, however there can be some trick spot that causes you out of index exception.

For example, if a(x) = 1+x+x2 and b(x) = 1+x, then with k = 2, we are summing c[2] = a[2]b[0]+a[1]b[1] + a[0]b[2], and b[2] does not exist since b as an array has only two entries.

The way to get around is: define bnew as 1+x+0x2 ({1, 1, 0}), or 1+x+0x2+0x3 {1, 1, 0, 0} etc., which is a copy of b(x) but with a valid index at i = 2, or i = 3, etc., and define similar things for anew, and calculate c[2] = anew[2]bnew[0]+anew[1]bnew[1] + anew[0]bnew[2].

Test your method with a(x) = 1+x+x2 and b(x) = 1+x and another pair with polynomials of degree 2 and degree 3 respectively.

(12%) Newtons method (roots). Newtons method or Newton-Raphson method of calculating a function / a polynomials roots is an easy way that uses only the knowledge of ECE 114 (for loop). Write a method Newtonsmethod that calculates (or attempt to calculate) a root from an initial guess.

The Wikipedia page provides a good way to understand Newtons method. https://en.wikipedia.org/wiki/Newton%27s_method

You need f(x) and f(x) (the derivative of the polynomial). You need an initial point x0, which when not picked appropriately can cause problem

You need to stop the for loop or while loop when x n and xn+1 are close (for example, if their difference is less than 1.0x10-7. ) or when n is big, say bigger than 50, since you do not want to iterate forever. However, there is a validity check: you want to make sure f(x n) 0; it would make no sense if f(x n) = 100 and you call that a root.

Test your method with the polynomial x3 + x + 1 and the initial guess x = -1.; and also the polynomial x2 - 3x + 2 and the initial guess x = 0. We do not try to calculate complex roots here.

(10%) Horners method (evaluation). Write a C# method Hornersmethod for a polynomial.

In Wikipedia https://en.wikipedia.org/wiki/Horner%27s_method , you can see

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago

Question

1. Signs and symbols of the map Briefly by box ?

Answered: 1 week ago

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago