The babylonian algorithm for square root approximation


Lab Project: The Babylonian Algorithm (Java Loops)

The Babylonian Algorithm for Square Root Approximation

Perhaps the first algorithm used for approximating the square root of S is known as the "Babylonian method", named after the Babylonians, or "Heron's method", named after the first-century Greek mathematician Heron of Alexandria who gave the first explicit description of the method. It can be derived from (but predates by 16 centuries) Newton's method.

The basic idea is that if x is an overestimate to the square root of a non-negative real number S then S/x will be an underestimate and so the average of these two numbers may reasonably be expected to provide a better approximation.

More precisely, assuming S is a positive number:

1. Make a guess at the answer (you can pick S/2 as your initial guess).
2. Compute r = S / guess.
3. Set new guess = (guess + r) / 2
4. Go back to step 2 until the last two guess values are within 1% of each other1.

To complete this lab project:

1. Create a new NetBeans project named CPS150_Lab19.

2. Delete the auto-generated CPS150_Lab19.java source file in the new project.

3. Download and import the replacement CPS150_Lab19.java source file into your project.

If needed, refer to the online instructions on importing a Java source file into a NetBeans project.

4. Add your section number in the top comment block:

/*
* CPS 150
* Algorithms & Programming I
*
* Section *** enter your section number here ***

* Spring 2017
*/

5. Add your name in the comment block after the @author tag:

/**
* Lab Project 19
* The Babylonian Algorithm
*
* @author
*/

6. Complete the method definitions for the following methods in CPS150_Lab19.java:

o static double getInput(double min)
o static double sqrt(double S)

Notes

1. See Section 5.8 (Floating-point comparison) in Chapter 5 (Java Branches) of the course zyBook.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: The babylonian algorithm for square root approximation
Reference No:- TGS02245500

Now Priced at $30 (50% Discount)

Recommended (98%)

Rated (4.3/5)