(a) Write a C++ function with the following header double polyval(std::vector coeff, double x) which evaluates any specified real polynomial at a given point. The parameter coeff stores the coefficients of the polynomial from the lowest term to the highest and the parameter x stores the point at which the polynomial is to be evaluated. For instance, the expression polyval({-4,2,7,-8,8,4}, 1.5) evaluates to 58.625, i.e. the value of P(x) 4r +8r-8r + 7 +2r - 4 at z=1.5 (5 marks) (b) Write a C++ program that allows the user to enter (the coefficients of) a real polynomial and compute the real zero (if it exists and is unique) within a specified interval using the bisection method. You may use the code from part (a). For instance, if the user would like to find the real zero of the polynomial p(x) = 4r + 8r - 8z + 7z + 2r - 4 within the interval l-3,-1], then the following should be the output of the program: what is the degree of the polynomial? 5 Enter the coefficients from the lowest term to the highest: -4 27 -8 8 4 Enter the endpoints of the interval: -3 -1 Enter the tolerance: 1E-8 The zero of the polynomial -2.87255 Also, if the user tries to look for a real zero of the same polynomial within the interval 2. 5). then the program should issue a message indicating the failure of the method: what is the degree of the polynomial? 5

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
(a) Write a C++ function with the following header
double polyval(std::vectorcdouble> coeff, double x)
which evaluates any specified real polynomial at a given point. The parameter coeff
stores the coefficients of the polynomial from the lowest term to the highest and the
parameter x stores the point at which the polynomial is to be evaluated. For instance,
the expression
polyval({-4,2,7,-8,8,4}, 1.5)
evaluates to 58.625, i.e. the value of P(r) = 4r + 8r - 8r+ 7r + 2r
I = 1.5
4 at
(5 marks)
(b) Write a C+ program that allows the user to enter (the coefficients of) a real polynomial
and compute the real zero (if it exists and is unique) within a specified interval using the
bisection method. You may use the code from part (a). For instance, if the user would
like to find the real zero of the polynomial p(r) = 4r + 8r* - 8z + 7 + 2r - 4
within the interval l-3, -1], then the following should be the output of the program:
What is the degree of the polynomial? 5
Enter the coefficients from the lowest term to the highest:
-4 27 -8 8 4
Enter the endpoints of the interval:
-3 -1
Enter the tolerance:
1E-8
The zero of the polynomial - -2.87255
Also, if the user tries to look for a real zero of the same polynomial within the interval
2. 51. then the program should issue a message indicating the failure of the method:
What is the degree of the polynomial? 5
Transcribed Image Text:(a) Write a C++ function with the following header double polyval(std::vectorcdouble> coeff, double x) which evaluates any specified real polynomial at a given point. The parameter coeff stores the coefficients of the polynomial from the lowest term to the highest and the parameter x stores the point at which the polynomial is to be evaluated. For instance, the expression polyval({-4,2,7,-8,8,4}, 1.5) evaluates to 58.625, i.e. the value of P(r) = 4r + 8r - 8r+ 7r + 2r I = 1.5 4 at (5 marks) (b) Write a C+ program that allows the user to enter (the coefficients of) a real polynomial and compute the real zero (if it exists and is unique) within a specified interval using the bisection method. You may use the code from part (a). For instance, if the user would like to find the real zero of the polynomial p(r) = 4r + 8r* - 8z + 7 + 2r - 4 within the interval l-3, -1], then the following should be the output of the program: What is the degree of the polynomial? 5 Enter the coefficients from the lowest term to the highest: -4 27 -8 8 4 Enter the endpoints of the interval: -3 -1 Enter the tolerance: 1E-8 The zero of the polynomial - -2.87255 Also, if the user tries to look for a real zero of the same polynomial within the interval 2. 51. then the program should issue a message indicating the failure of the method: What is the degree of the polynomial? 5
Enter the coefficients from the lowest term to the highest:
-4 2 7 -8 8 4
Enter the endpoints of the interval:
25
Enter the tolerance:
1E-8
Unable to determine whether a root exists.
Transcribed Image Text:Enter the coefficients from the lowest term to the highest: -4 2 7 -8 8 4 Enter the endpoints of the interval: 25 Enter the tolerance: 1E-8 Unable to determine whether a root exists.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education