Question: Problem 2: (Compute square root without using sqrt function) Write a program to locate the square root of an integer using the bisection method. Note:

 Problem 2: (Compute square root without using sqrt function) Write aprogram to locate the square root of an integer using the bisection

Problem 2: (Compute square root without using sqrt function) Write a program to locate the square root of an integer using the bisection method. Note: you are not allowed to use sqrt or any function in cmath. As n is the solution to equation x2n=0, evaluating the value of n can be converted to solving equation x2n=0 using the bisection method. See bisection on https://en.wikipedia.org/wiki/Bisection methorl. For this question, you need to implement - void mysqrt (int n, double TOL) takes in an integer and a tolerance, and prints a sequence of intervals the square root of the integer locates at. The first interval is [0,n] and the last interval has a length less than TOL. - we provide int main() to show how we plan to use mysqrt. You are not allowed to modify the int main function. - See the sample output on Page 2. Hints: use two doubles left and right to record two end points of the current interval. Use middle to record the middle point of the current interval, then the square root will locate in either [left, middle] or [middle, right]. Which interval to choose is determined by the Boolean value of (middle*middle-n>0). Write a loop to repeat the previous steps until the interval's length is less than TOL. Here are the samples when user enters 20.01 [enter] Please enter a positive integer and tolerance: 20.01 Square root of 2 is located in the interval [0,2]. Square root of 2 is located in the interval [1,2]. Square root of 2 is located in the interval [1,1.5]. Square root of 2 is located in the interval [1.25,1.5]. Square root of 2 is located in the interval [1.375,1.5]. Square root of 2 is located in the interval [1.375,1.4375]. Square root of 2 is located in the interval [1.40625,1.4375]. Square root of 2 is located in the interval [1.40625,1.42188]. Square root of 2 is located in the interval [1.41406,1.42188]. The interval length is 0.0078125. Here are the samples when user enters 160.001 [enter] Please enter a positive integer and tolerance: 160.001 Square root of 16 is located in the interval [0,16]. Square root of 16 is located in the interval [0,8] Square root of 16 is located in the interval [4,8] Square root of 16 is located in the interval [4,6]. Square root of 16 is located in the interval [4,5]. Square root of 16 is located in the interval [4,4.5] Square root of 16 is located in the interval [4,4.25]. Square root of 16 is located in the interval [4,4.125] Square root of 16 is located in the interval [4,4.0625] Square root of 16 is located in the interval [4,4.03125]. Square root of 16 is located in the interval [4,4.01562]. Square root of 16 is located in the interval [4,4.00781]. Square root of 16 is located in the interval [4,4.00391]. Square root of 16 is located in the interval [4,4.00195]. Square root of 16 is located in the interval [4,4.00098]. The interval length is 0.000976562

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!