(Solved) : Implement Horner S Method Calculating Polynomial Degree N Given Value X Coefficients Ai Te Q44146841 . . .
- Implement Horner’s method for calculating a polynomial ofdegree n given a value of x and all of the coefficients (theai terms) using an array of type double:
anxn +an-1xn-1 + an-2xn-2 + …+ a2x2 + a1x + a0
where n is a positive int andan ≠ 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 isb0):
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 codefor user errors. It is recommended that you use 2 arrays: one forthe ais and one for the bis. You may use arecursive algorithm or a standard loop. Display the result to theuser.
Example: f(x) = y = 2×2 –3x + 1 is a second-degree polynomial (n = 2), where a1 =2, a2 = -3, and a3 = 1. Evaluate thepolynomial at x = -1 using Horner’s 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 Horner’s 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 finalanswer.
b array
6
-5
2
0
Index
0
1
2
. . .
Expert Answer
Answer to Implement Horner’s method for calculating a polynomial of degree n given a value of x and all of the coefficients (th…
OR