Question
// in C++ : in the following code : #include #include using namespace std; const double eps = 1.0; double f(double x) { return 4
// in C++ : in the following code :
#include #include using namespace std; const double eps = 1.0; double f(double x) { return 4 * pow(x, 3) - 6 * pow(x, 2) + 7 * x - 2.3; } double bisect(double xl, double xu) { double iter = 0; double xr = 0; double xrold = 0; double error = 0; do { xrold = xr; xr = (xl + xu) / 2; error = abs((xr - xrold) / xr) * 100;
cout _getch();
if (f(xl) * f(xr) > 0) { xl = xr; } else { xu = xr;
} iter++;
} while (error > eps);
return xr; } int main() {
double xl, xu, root; cout cin >> xl; cout cin >> xu; if (f(xl) * f(xu) { root = bisect(xl, xu); cout }
else
{ cout
_getch();
return 0; } }
The Question is :
1 - Re Write this code in recursive way
2- Re write the code to make the output of the code in the first line don't contain Error ( first line only )
3- add line/s : if f(xl)*f(xr) = 0 get out from the function and say last xr you arrived to it is the ( answer )
Please put the 3 requirements in the same Code .
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