Select Page

Step 1. Place your order

Fill in the order form and provide all details of your assignment.

Step 2. Make Payment

Choose the payment system that suits you most.

Step 3. Receive your paper

Once your paper is ready, we will email it to you.

., p[1] = c1, and p[0] = c0.

by | Nov 11, 2022 | Python | 0 comments

Get Help With Your Essay

"Place your order now for a similar assignment and have exceptional work written by our team of experts, guaranteeing you A results."

For This or a Similar Paper Click To Order Now

 

In this problem, you are asked to implement polynomials
using a list. A polynomial is an expression of the form
c0 + c1x + c2x2 + c3x3 + . . . + cnxn
where c0, c1, . . . , cn are real numbers. Each of cixi is called a term of the polynomial, and ci
is called the coefficient of the term with exponent i. Note that c0 is simply the coefficient of
the term with exponent 0. The maximum exponent with a non-zero coefficient is called the
degree of the polynomial. For example, 6×14 + 9×11 −12×3 + 42 is a polynomial of degree 14.
The polynomial −12×6 + 5×5 −20×4 + 8×2 −12x + 9 has degree 6. The following are some
standard operations on polynomials:
3
Scaling a polynomial: Given a polynomial p(x) = cnxn+cn−1xn−1+. . .+c1x+c0 and a real
value s, scaling p(x) by s gives the polynomial s ·p(x) obtained by scaling the coefficient
of every term in p(x) by the factor s. For example, if p(x) = 6×14 + 9×11 −12×3 + 42,
then 2p(x) = 12×14 + 18×11 −24×3 + 84.
Sum of two polynomials: The sum of two polynomials p1(x) and p2(x), denoted by p1(x)+
p2(x), is the polynomial obtained by adding the terms of p1(x) and p2(x). For example,
if p1(x) = 6×14 + 9×11 −12×3 + 42 and p2(x) = −12×6 + 5×5 −20×4 + 8×2 −12x + 9, then
p1(x) + p2(x) = 6×14 + 9×11 −12×6 + 5×5 −20×4 −12×3 + 8×2 −12x + 51.
Difference of two polynomials: The difference of two polynomials p1(x) and p2(x) is the
polynomial obtained by subtracting one from the other. Therefore, p1(x) −p2(x) is the
polynomial obtained by subtracting the terms of p2(x) from p1(x).
For example, if p1 and
p2 are as above, then p1(x)−p2(x) = 6×14+9×11+12×6−5×5+20×4−12×3−8×2+12x+33.
Product of two polynomials: The product of two polynomials p1(x) and p2(x), denoted
by p1(x) ·p2(x), is the polynomial obtained by the pair-wise multiplication of terms in
p1(x) and p2(x). For example, if p1(x) = x4 + 4×3 + 4×2 and p2(x) = 2x −1, then
p1(x) ·p2(x) = 2×5 + 7×4 + 4×3 −4×2. This is obtained as follows: (x4 + 4×3 + 4×2)(2x) +
(x4 + 4×3 + 4×2)(−1) = 2×5 + 8×4 + 8×3 −x4 −4×3 −4×2 = 2×5 + 7×4 + 4×3 −4×2.
In this program, you will store a polynomial as a list of real values. The length of the list will
be equal to one more than the degree of the polynomial. The item at index i of the list will
be equal to the coefficient of the term with exponent i in the polynomial. In other words,
polynomial p(x) = cnxn + cn−1xn−1 + . . . + c1x + c0 is stored in a list p of length n + 1, such
that p[n] = cn, p[n-1] = cn−1, . . ., p[1] = c1, and p[0] = c0. For example, the polynomial
6×14 + 9×11 −12×3 + 42 is stored as the following list: [42, 0, 0, -12, 0, 0, 0, 0, 0,
0, 0, 9, 0, 0, 6]. Note that the length of the list is 15.
You are asked to implement the following functions to manipulate polynomials:
1. A function called make poly with a single parameter called termlist, which
is a list of 2-tuples, where each 2-tuple in the list is an (exponent, coefficient) pair
representing a term in the polynomial. The exponent is an integer and the coefficient
is a real number. This function will create a list to store the polynomial (as described
above) and return the list. Note that the 2-tuples in termlist may appear in any order
(that is, do not assume that the terms will appear in increasing or decreasing order of
exponents in termlist). For example, after the following assignment statement
term_list_1 = [(14, 6), (11, 9), (0, 42), (3, -12)]
p1 = make_poly(term_list_1)
p1 should be the list [42, 0, 0, -12, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 6].
2. function called print poly with a single parameter: a polynomial p. Keep
in mind that p is a list. This function prints out the polynomial. The polynomial must be
printed “nicely”. This means that only terms with non-zero coefficients must be printed
out and the terms must be printed from largest exponent to the smallest. Furthermore, if
the coefficient of a term is negative, the – (minus sign) must be embedded in the printed
polynomial. For example, if the polynomial is −12×6 + 5×5 −20×4 + 8×2 −12x + 9, it
should be printed as
-12x^6 + 5x^5 – 20x^4 + 8x^2 – 12x + 9
4
and not as
-12x^6 + 5x^5 + -20x^4 + 0x^3 + 8x^2 + -12x^1 + 9x^0
3. A function called eval poly with two parameters: a polynomial p and a real
number r. The function should evaluate p at x = r and return the result. For example,
if p is the polynomial −12×6 + 5×5 −20×4 + 8×2 −12x + 9, then eval poly(p, 2) should
return -911 (which we obtain by plugging in 2 as the value of x).
4. A function called scale poly with two parameters: a polynomial p and a real
non-zero value s. The function should return the polynomial sp, that is, the polynomial
obtained by scaling p by s. Keep in mind that you are returning a new polynomial (that
is, this function should not modify p).
5. A function called sum poly with two parameters: a polynomial p1 and a
polynomial p2. The function should return the sum polynomial p1 + p2. Make sure
that the length of the sum polynomial list is exactly equal to its degree plus one. Also,
the function should not modify p1 and p2.
6. A function called diff poly with two parameters: a polynomial p1 and a
polynomial p2. The function should return the difference polynomial p1 – p2. Again,
make sure that the length of the difference polynomial list is exactly equal to its degree
plus one and the function does not modify p1 and p2.
7. A function called mult poly with two parameters: a polynomial p1 and a
polynomial p2. The function should return the product polynomial p1 * p2. Make sure
that the length of the product polynomial list is exactly equal to its degree plus one and
the function does not modify p1 and p2.
8. A function called test polys without any parameters. This function has been writ-
ten for you in a file called hw4problem2.py, available for download on Canvas.
This function is simply a driver function that makes calls to all of the above functions,
thus allowing you to test them. You will insert your implementations of all the above
functions into this module.

For This or a Similar Paper Click To Order Now

Affordable

Only pay once! Clear pricing system with no hidden fees, direct line to your writer, 24/7 customer support.

Quality

Our reputation is built on delivering top-quality papers. No matter how small the task, we give customers our best.

Timely

Missed due dates can result in a serious loss of marks. We strive to finish everything with time to spare.