Question: Create a class Polynomial that is used to evaluate a polynomial function of x: The coefficients a are floating-point numbers, the exponents of x are
Create a class Polynomial that is used to evaluate a polynomial function of x:
![]()
The coefficients a are floating-point numbers, the exponents of x are integers, and the largest exponent n—called the degree of the polynomial—is greater than or equal to 0. The class has the attributes
- degree—the value of the largest exponent n
coefficients—an array of the coefficients a
and the following methods:
- Polynomial(max)—a constructor that creates a polynomial of degree max whose coefficients are all 0
- setConstant(i, value)—sets the coefficient a to value
- evaluate(x)—returns the value of the polynomial for the given value x
For example, the polynomial
P ( x ) = 3 + 5x + 2x3
is of degree 3 and has coefficients a0 = 3, a1 = 5, a2 = 0, and a3 = 2. The invocation evaluate(7) computes 3 + 5 × 7 + 0 × 7 + 2 = 73, which is 3 + 35 + 0 + 686, and returns the result 724.
P (x) = ao+ax +a2x + ** +an 1X +anx
Step by Step Solution
3.46 Rating (162 Votes )
There are 3 Steps involved in it
public class Polynomial private double coefficients privat... View full answer
Get step-by-step solutions from verified subject matter experts
