Write a program that uses two functions to find one real zero of a polynomial. T
ID: 1858793 • Letter: W
Question
Write a program that uses two functions to find one real zero of a polynomial. The main program will send a left and right limit value to the first function. The first function’s prototype should be something like:
bool isolate_zero(double left, double right, double &zero);
This function returns true if it discovered a zero and false otherwise. If the y value of the cubic is positive at both limits, or negative at both limits, then the function returns false. If the y value of the cubic is positive at one of the limits and negative at the other, then the function will find the real zero that must lie between those two limits. It should use a midpoint approach by repeatedly finding the y value at the midpoint, deciding which side of the midpoint contains the zero, and then replacing one of the limits with the midpoint. To decide whether it has found a zero or not, the function should use a tolerance of 1e-12. That value should be a global constant.
The second function has the prototype:
double cubic(double x);
Explanation / Answer
#include <iostream> #include <cstdlib> #include <ctime> #include <string> using namespace std; bool isolate_zero( double left, double right, double &zero); double cubic( double x ); int main( int argc, char* argv[] ) { std::cin.get(); return ( 0 ); } // Definition of isolate_zero bool isolate_zero( double left, double right, double &zero) { // body } // Definition of cubic double cubic( double x ) { // body } #include <iostream> #include <cstdlib> #include <ctime> #include <string> using namespace std; bool isolate_zero( double left, double right, double &zero); double cubic( double x ); int main( int argc, char* argv[] ) { std::cin.get(); return ( 0 ); } // Definition of isolate_zero bool isolate_zero( double left, double right, double &zero) { // body } // Definition of cubic double cubic( double x ) { // body } You have to fill in the bodies of the functions.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.