The Heron Method for approximating the square root of a number states that if x is a guess for the square root of n then a better guess x' is:

x' = [x + (n/x)] / 2

Naturally this process can be repeated using x' in place of x the next time through the loop. The loop can stop when the difference between the previous and next guesses is small enough.

A programmer wrote the following code to implement the Heron Method to locate the square root of any number:

function heronSqrt(n)
{
var DELTA = 1.0E-10;
var nextGuess;
var prevGuess = n;
do
{
nextGuess = (prevGuess + (n/prevGuess))/2.0;
prevGuess = nextGuess;
} while (nextGuess-prevGuess > DELTA)
return nextGuess;
}

However, the code does not work properly. Fix the program so that it works. Also list a set of test cases that will thoroughly exercise the Heron Method code above.

function heronSqrt(n)
{
var DELTA = 1.0E-10;
var nextGuess = n;
var prevGuess;
do
{
prevGuess = nextGuess;
nextGuess = (prevGuess + (n/prevGuess))/2.0;
} while (nextGuess-prevGuess > DELTA)
return nextGuess;
}

If assignment order in do-while loop is other way round (as in your original function definition), it always sets prevGuess and nextGuess to same value at the end ...

Solution Summary

Solution not only gives the fixed code but it also explains why the given buggy code will not work as desired. It also provides the guidance regarding how the test space can be divided into various categories to generate test cases for the given function. It is more of a guidance than ready-to-consume solution.

The NewtonsSquareRoot Class
Objectives
? Writing a class using conditionals that test double values
? Writing a class using a while loop
The project directory should include the following:
? NewtonsSquareRoot.java
? NewtonsSquareRootTest.java
Details
To approximate the square root of a positive number n using Newton

Please see the attached file for the fully formatted problems.
1. Decide all values of b in the following equations that will give one or more real number solutions.
Solve the following three quadratic equations, using what you consider to be the optimum method for each problem (factoring, square rootmethod, etc.). Why

Solve the following quadratic equations by factoring and name the techniques used
Example : completing the square, quadratic formula, square rootmethod, factoring.
See attached file for full problem description.

See the attached file.
The Newton-Raphson Method
1. Consider the function .
i) Show, graphically or otherwise, that the equation has a root in the interval (1,2). Show that .
ii) Use the secant method, with the function f(x) and starting values, 1 and 2, to find an estimate of correct to three decimal places.

1. Classify each number below as a rational number or an irrational number:
a) Square root of 64
b) 9
c) -41.4
d) 46.97
e) -3 sqaureroot 2
f) 24+9*(15-13)/6
g) -(1-23/1)2/1-4.5
2. Evaluate the expression when a=-6 and b=4 .
a-9b
3. Evaluate the expression for c=-4
c^2 + 7c - 5
4. Write an ineq

Recall that a perfect sqaure is a natural number n such that n = (k^2), for some natural number k.
Theorem.
If the natural number n is not a perfect square, then n^(1/2) is irrational.
Proof.
S(1):
Suppose n^(1/2) = r/s for some natural numbers r and s.
S(2):
We may assume that r and s have no prime factors in common,

Q
Using the bisection method, find the positive root of 2x(1 + x^2)^-1 = arctan x. Using
this root as x0; apply Newton's method to the function f(x) = arctan x: Interpret
the results you obtain.