Question
create a java program Listing 1: Default Constructor Creates the polynomial 0 public Polynomial ( ) Listing 2: Parameterized Constructor Creates a polynomial by allocating
create a java program
Listing 1: Default Constructor
Creates the polynomial 0
public Polynomial ( )
Listing 2: Parameterized Constructor
Creates a polynomial by allocating its coefficient array and then copying the content so of the specified array into it. @param c an array containing the coefficients in order of descending powers
@throws Illegal Argument Exception when c[0] is 0 and the length of c is greater than 1
public Polynomial (double [ ] c ) throws Illegal A rgument Exception
The PolynomialDemo Class The main method will perform the following tasks:
1. It prompts the user for the degrees and coefficients for the two polynomials and creates them, and displays their degrees and evaluates them at the values entered by the user by invoking the relevant functions from the class. The interactivity should be as shown in the sample run.
2. Next, your program will generate 10 polynomials of degrees 1,000, 2,000, , 10,000 with randomly generated coefficients in the range (0,5]. For each polynomial, your program will generate a random number in the range [0.5,1.2] and evaluate the polynomial using the Horners and naive polyomial evalution methods. Your program will display the execution times for each evaluation as shown in the table in the sample run.
sample run
Enter the degree of the first polynomial -> 6
Enter its coefficients in order of descending powers -> 4 5 0 2 3 5 0
f(x) = 4x^6 + 5x^5 + 2x^3 + 3x^2 + 5x deg f(x) := ...
Enter the value of x at which the polynomial is to be evaluated -> -> 3
Using Horners method, f(3) = .....
Using naive method, f(3) = .....
Enter the degree of the second polynomial ->
5 Enter its coefficients in order of descending powers -> 12.5 0 0 -1 7.2 -9.5 g(x) = 12.5x^5 - x^2 + 7.2x - 9.5 deg g(x) := ...
Enter the value of x at which the polynomial is to be evaluated -> -7.25
Using Horners method, g(-7.25) = .... Using naive method, g(-7.25) = ....
Empirical Analysis of Naive vs Horners Methods on 10 Polynomials with Random Coefficients
================================================
Degree Naive Time (ns) Horners Time(ns)
------------------------------------------------
1000 ......... .........
2000 ......... .........
3000 ......... .........
4000 ......... .........
5000 ......... .........
6000 ......... .........
7000 ......... .........
8000 ......... .........
9000 ......... .........
10000 ......... .........
------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started