   Chapter 11.3, Problem 36ES ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193

#### Solutions

Chapter
Section ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193
Textbook Problem
1 views

# Exercises 36—39 refer to the following algorithm to compute the value of a real polynomial. Algorithm 11.3.3 Term-by-Term Polynomial Evaluation[This algorithm computes the value of a polynomial a [ n ] x n + a [ n − 1 ] x n − 1 + ⋯ + a [ 2 ] x 2 + a [ 1 ] x + a [ 0 ] by computing each term separately, starting with a [ 0 ] , and adding it to an accumulating sum.]Input: n [a nonnegative inreger], a [ 0 ] ,   a [ 1 ] ,   a [ 2 ] ,   … a [ n ] [an array of real numbers], x [a real number]Algorithm Body: p o l y v a l   : = a [ 0 ] for i : = 1 to n t e r m   : = a [ i ] for j : = 1 to i t e r m : = t e r m ⋅ x next j p o l y v a l : = p o l y v a l + t e r m next i [ A t   t h i s   p o i n t   p o l y v a l = a [ n ] x n + a [ n − 1 ] x n − 1 + ⋯ + a [ 2 ] x 2 + a [ 1 ] x + a [ 0 ] . ] Output: polyval [a real number] 36. Trace Algorithm 11.3.3 for the input x = 2 , and x = 2 .

To determine

Trace stated algorithm for the input n=3, a=2,a=1,a=1,a=3, and x=2.

Explanation

Given information:

n=3, a=2,a=1,a=1,a=3, and x=2

Calculation:

The tracing is tabulated below.

 n 3 a 2 a 1 a -1 a 3 x 2 polyval 2 4 0 24 i 1 2 3 term 1 2 -1 -2 -4 3 6 12 24 j 1 1 2 1 2 3

Complete the first column,

n is given as 3

a=2,a=1,a=1,a=3 is given. x is given as 2.

polyval=a, this is given therefore polyval=2

i goes from 1 to n, therefore at the start i=1

term=a[i], is given. Therefore when i=1, term=1.

j goes from 1 to i, at the start i=1. Therefore j=1.

Completing column 2,

Then we substitute j=1 ,

term=termx

term=12=2 (because term=1 and x=2), Thus we update the second column, term=2

Completing column 3,

When term=2, polyval=polyval+term. Now we substitute values to this equation.

polyval=2+2=4 (because polyval=2 and term=2), We update the 3rd column as polyval=4

Now the j loop is over and we move on to the next i, i=2, we update that on the 3rd column

### Still sussing out bartleby?

Check out a sample textbook solution.

See a sample solution

#### The Solution to Your Study Problems

Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!

Get Started 