Answered step by step
Verified Expert Solution
Question
1 Approved Answer
One of the oldest methods for computing the square root Links to an external site. of a number is the Babylonian Method Links to an
One of the oldest methods for computing the square root
Links to an external site. of a number is the Babylonian Method
Links to an external site.
The Babylonian Method uses an iterative algorithm to make successively more accurate estimates of a number's square root. The algorithm stops iterating when the estimate shows no further sign of improvement, or when the estimate is within some acceptable margin of error. The acceptable margin of error is often called an epsilon.
Assuming that you need to solve for the square root of x the algorithm works as follows.
Choose an epsilon value that determines how close your solution should be to the actual square root value before you decide it is "good enough." Because this assignment asks you to solve for the square root to three decimal places, we can safely set the epsilon value to four decimal places This guarantees that our solution will be accurate to the precision we need to display to the screen.
Choose an initial estimate e for the square root of x An easy and perfectly valid approach is to set the initial estimate ex For example, you could set the first estimate for the square root of to be
Evaluate the estimate by dividing the value x by your estimate e and comparing the result of that division to the current estimate e If your estimate e were to be exactly equal to the square root, then you would find that xee In practice, unless you are lucky, there will typically be some difference between these two values xe and e even after many iterations of the algorithm.
Determine if the estimate is "good enough" to stop. A smaller difference between xe and e reflects a more accurate estimate. If the difference is smaller than your epsilon value, then you've found the answer! If notif the difference is greater than the epsilon valuethen you need to proceed to step below.
Note that you'll want to look at the absolute value of the difference between xe and e This is because e may be too large or too small. To test for the absolute value, you could use ifelse logic to see which term xe or e is smaller. You could then subtract the smaller value from the larger one. Alternatively, you could use the Python's builtin function abs
Revise the estimate if needed based on Step by setting e to the average of the fraction xe and your old estimate e Using this new estimate, go back to Step
For this assignment, you need to write a Python program that solves for square roots using the algorithm outlined above. See the requirements sections below for more detailed instructions.
Please Note that you are not allowed to use any builtin functions for this assignment while Python has its own way of calculating square roots. Instead, you must implement your own solution to this classic mathematical problem. To be clear, you should NOT use any predefined Python square root function anywhere in your assignment solution.
Step by Step Solution
★★★★★
3.55 Rating (166 Votes )
There are 3 Steps involved in it
Step: 1
To solve for the square root using the Babylonian Method in Python without using any builtin functio...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