Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the implementation of the method shown in Listing S without the use of

ID: 3575742 • Letter: C

Question

Complete the implementation of the method shown in Listing S without the use of any standard Java Math class method. Definition: A univariate polynomial is a mathematical expression involving a sum of powers in one variable multiplied by coefficients. A polynomial in one variable with constant coefficients is given by the expression c_nx^n + c_n - 1x^n - 1 + c_1x + c_0, where the c_i's are numeric values representing the coefficients. The polynomial is said to be an n-degree polynomial if its highest power is n. For example, 3x^4 - 2x^3 + x^2 - 1 is a fourth-degree polynomial. To evaluate a univariate polynomial, given a numeric value, the value is substituted for the variable and the expression is evaluated. For example, given the polynomial p(x) = 3x^4 - 2x^3 + x^2 - 1, p(-2) = 67 since 3 x (-2)^4 - 2 x (-2)^3 -f (-2)^2 - 1 = 67. Observe that p(0) = c_0 and p(1) is equal to the sum of the coefficients for a univariate polynomial. Also, observe that even powers of -1 are equal to 1 and odd powers of -1 are equal -1. Use these facts in your implementation to enhance the efficiency of your code. A univariate polynomial, can be represented as an array of its coefficients in descending powers. For example, the polynomials 3x^4 -2x^3 + x^2 - 1 and 3x^2 + 2x - 5 are represented as [3, -2, 1, 0, -1] and [3, 2, -5], respectively. Listing 3: Polynomial Evaluation Method/** * Evaluates the polynomial at the specified value. * param coefs the coefficients of a * univariate polynomial in descending powers. * param x the value at which the polynomial * is to be evaluated. * return the value of a polynomial evaluated at x */public static double polyVal (double [] coefs, double x) {//Implement this method.

Explanation / Answer

public static double polyVal(double[] coefs, double x) {
int n = coefs.length - 1;
double y = coefs[n];
for (int i = n - 1; i >= 0; i--) {
y = coefs[i] + (x * y);
}
return y;
}