80.5k views
4 votes
There is a more efficient algorithm (in terms of the number of multiplications and additions used) for evaluating polynomials than the conventional algorithm. It is called Horner's method. This pseudocode shows how to use this method to find the value of anxn + an – 1xn − 1 + ⋅⋅⋅ + a1x + a0 at x = c.

procedure Horner(c, a0, a1, . . . , an: real numbers)
y := an
for i := 1 to n
y := y * c + an − i
return y{y = ancn + an − 1cn − 1 + ⋅⋅⋅ + a1c + a0}
Find the values of A, B, C, D, and E by evaluating 3x2 + x + 1 at x = 2 based on the given algorithm. Working through each step of the algorithm is shown below:
Initially : y = A
Step 1: i = B
y = C
Step 2 : i = D
y = E
A = , B = , C = , D = , and E =

User Patkil
by
7.9k points

1 Answer

3 votes

To evaluate the polynomial 3x^2 + x + 1 at x = 2 using Horner's method, let's go through each step of the algorithm:

Initially: y = A (A is the value of the polynomial at x = 2, which we need to find)

Step 1: i = B (B is the loop variable)

In this step, we set y = C, where C is the coefficient of the highest power term of the polynomial (in this case, C = 3).

Step 2: i = D (D is the loop variable)

In this step, we update y as y = y * c + an - i. Here, c is the value of x at which we want to evaluate the polynomial (in this case, c = 2), and an - i is the coefficient of the current term being evaluated.

Now, let's substitute the values into the algorithm and work through each step:

Initially: y = A

Step 1: i = B

y = C = 3

Step 2: i = D

y = y * c + an - i = 3 * 2 + 1 = 7

So, A = 7

In this case, since there is only one term in the polynomial with a coefficient other than zero, we only needed to go through one iteration of the algorithm.

Therefore, A = 7, B = 1, C = 3, D = 2, and E is not applicable in this case.

The value of 3x^2 + x + 1 at x = 2 is 7.

User Drew McGhie
by
8.2k points

Related questions