Hello All,
I need help with the body of this program. Can someone give me a reference or example to look on to give me an idea. This is what I have so far. Please help. I am very frusturated at this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#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
}
double cubic( double c1 )
{
// cout << "cubic = " << c1 << "when x is 2" << endl;
//body
}
|
This is assignment.
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);
It calculates a cubic similar to the function on page 288 of your book, but the four constants should be global variables rather than function arguments.
Test your program with the cubic x3-5x2+4x+3.