Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write this in Scheme Programming Language (DrRacket) A single-variable polynomial of degree n is written as a0 +a1x+a2x2 +...+anxn where an, ..., a0 are coefficients.

Write this in Scheme Programming Language (DrRacket)

A single-variable polynomial of degree n is written as a0 +a1x+a2x2 +...+anxn

where an, ..., a0 are coefficients. Suppose we represent such a polyno- mial as a list (a0,a1,a2,...,an).

In this question, you are asked to write a Scheme function polyMult that performs polynomial multiplication of two polynomials. For in- stance, when given (1 2 1) and (1 2 1), polyMult should return (1 4 6 4 1), because

(1+2x+x2)(1+2x+x2)=1+4x+6x2 +4x3 +x4

We are going to implement the polynomial multiplication by convert- ing it into a series of polynomial addition operations. For the example, the multiplication can be performed in the following way:

(1+2x+x2)(1+2x+x2)

= 1?(1+2x+x2)+2x?(1+2x+x2)+x2 ?(1+2x+x2)

= (1+2x+x2)+

(0+2x+4x2 +2x3)+

(0+0 +x2+2x3+x4)

= 1+4x+6x2 +4x3 +x4

Do the following steps to implement the above polynomial multiplica- tion procedure.

(a) Write a function nzero, which takes a number n and returns a list of n zeros. For instance, calling nzero on 3 returns (0 0 0).

(b) Write a polynomial addition function polyAdd that adds two polynomials. For instance, when given (1 2 1) and (0 2 4 2), it returns (1 4 5 2).

Write a function polyAddList, which takes a list of polynomials, and adds all of them together. It should be based on polyAdd. For instance, when given ((1 2 1) (0 2 4 2) (0 0 1 2 1)), it returns (1 4 6 4 1).

(d) Write polyMult based on polyAddList. You may follow the hint below to implement polyMult. (You

dont need to follow the hint if you can come up with another way of implementing polyMult.) Hint: Write a function polyMultHelper, which takes two lists of numbers, l1 and l2, and a number n as parameters and returns a list of lists of numbers. The first element in the result is the result of appending the list of n zeros to the list of mapping the function that multiplies the first element in l1 to l2; the second element in the result is the result of appending the list of n + 1 zeros to the list of mapping the function that multiplies the second element in l1 to l2; ... For instance,

 polyMultHelper (1 2 1) (1 2 1) 0 

should produce the result

 ((1 2 1) (0 2 4 2) (0 0 1 2 1)) 

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

4. Give partial credit for partially correct answers.

Answered: 1 week ago

Question

4. Describe cultural differences that influence perception

Answered: 1 week ago