Question: X = The divide and average method, an old - time method for approximating the square root of any positive number a , can be

X = The "divide and average" method, an old-time method for approximating the square root of any positive number a, can be formulated as x + alx 2 Write a well-structured python function using the while loop structure to implement this algorithm. At each step estimate the approximate error in your approximation as hew = xold xhew Repeat the loop until e is less than or equal to a specified error tolerance. Take x = a/2 as the initial value of x to start the while loop. Design your program so that it returns the result if a >0 but shows an error message if a <0. The function should be able to return 0 when a =0. The function should return the approximated root along with the number of iterations it takes to reach the solution and the approximate error. 1. Test your program by evaluating a =0,2,10 and -4 for the error tolerance of 10-22. For a =10, calculate the true value (i.e., X; = Va) and the true error e in percentage. # Q6 answer def squareRoot(a .....): inputs a: the number to find its square root outputs: X: the approximated square root ea: approximate error iter: number of iterations to reach the approximated square root x = a /2.0 ea =100 iter =0 #initial x value #initial approximate error #initial number of iterations return x, iter, ea

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 Programming Questions!