Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement Horners method for calculating a polynomial of degree n given a value of x and all of the coefficients (the a i terms) using

  1. Implement Horners method for calculating a polynomial of degree n given a value of x and all of the coefficients (the ai terms) using an array of type double:

anxn + an-1xn-1 + an-2xn-2 + + a2x2 + a1x + a0

where n is a positive int and an 0.

Prompt the user: 1) for the degree n (a positive int), 2) for the n+1 coefficients (of type double, beginning with an and ending with a0), and 3) for the value of x (of type double). The algorithm is as follows (the final value of the polynomial evaluated at x is b0):

bn = an;

bn-1 = an-1 + bnx;

bn-2 = an-2 + bn-1x;

b1 = a1 + b2x;

b0 = a0 + b1x;

You do not have to defensively code for user errors. It is recommended that you use 2 arrays: one for the ais and one for the bis. You may use a recursive algorithm or a standard loop. Display the result to the user.

Example: f(x) = y = 2x2 3x + 1 is a second-degree polynomial (n = 2), where a1 = 2, a2 = -3, and a3 = 1. Evaluate the polynomial at x = -1 using Horners method; note that f(-1) =

2 *( -1)2 +( -3) *( -1) + 1 = 2 + 3 + 1 = 6. The array of ais is:

The a array

1

-3

2

0

Index

0

1

2

. . .

Using Horners algorithm, we get:

b2 = a2 = 2

The b array

0

0

2

0

Index

0

1

2

. . .

b1 = a1 + b2 * x = -3 + 2 * -1 = -3 + -2 = -5

b array

0

-5

2

0

Index

0

1

2

. . .

b0 = a0 + b1 * x = 1 + -5 * -1 = 1 + 5 = 6, and 6 is the final answer.

b array

6

-5

2

0

Index

0

1

2

. . .

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

Cite five factors that may lead to scatter in fatigue life data.

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago