Question: Please fill the code for C++ ---------------------------------------------------------------------------------------------- #include #include #include // for time #include // for fabs() and other functions in f() using namespace std;

Please fill the code for C++ ---------------------------------------------------------------------------------------------- #include  #include  #include  // for time #include  // for fabs() and other functions in f() using namespace std; // FILL IN THE CODE for the prototype of the bisection function. Make the last two parameters have the default value of 1E-5 and 100, respectively int main() { double a,b; // endpoints double tol; int n0; cout << "Enter endpoints a and b surrounding solution: "; cin >> a >> b; if(a>b){ cout << "Error: invalid endpoints "; return 1; } cout << "Enter tolerance: "; cin >> tol; if(tol<=0){ cout << "Error: invalid tolerance "; return 1; } cout << "Enter maximum number of iterations: "; cin >> n0; if(n0<=0){ cout << "Error: invalid number of iterations "; return 1; } // Call Bisection function double p = bisection(a, b, tol, n0); // Output results cout << "A zero was found at p = "< of return type void. // The function takes and integer called  and four double precision // parameters called , , 

, and . { // FILL IN THE CODE that defines a static boolean variable called // initialized to true. if (first){ // print header only if first time first = false; cout << " i a b p fp "; // FILL IN THE CODE to set the output of cout to print real numbers // always in decimal notation with 5 decimal places return; } cout << setw(3) << i << " "; cout << setw(9) << a << " "; cout << setw(9) << b << " "; cout << setw(9) << p << " "; cout << setw(9) << fp<< " "; } // FILL IN THE CODE that defines a double precision returning function // called with one double precision argument called . // The function evaluates a mathematical function in and returns // the value of this evaluation (use the function in the provided example) // FILL IN THE CODE TO perform the following algorithm as part of a // function called : // The Bisection Algorithm // PURPOSE: Given a function f(x) defined elsewhere, find solution p such that f(p)=0 // INPUT: real numbers i, a, b, tol and integer N0. // OUTPUT: solution p or failure message. // 1. Check that if f(a)*f(b) > 0 then print error message and exit program (see output example for message) // 32 For i = 1, ..., N0-1 do steps a-d // a. Set p = (a + b) /2 // b. call printpars with a,b,p,f(p) arguments (prints calculation progress) // c. if |f(p)| < tol or (b-a)/2 < tol then return

. // Note that || denotes the absolute value function. // d. if f(a)*f(p) > 0 then set a = p, otherwise set b = p // 3. Print method failed message // 4. Exit the program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!