Question: Create a package named newton_sqrt and write a program to use the Newton's method for computing a square root. Newton's method for calculating the square
Create a package named newton_sqrt and write a program to use the "Newton's method" for computing a square root. Newton's method for calculating the square root of N starts by making a guess at the square root. I would recommend starting with an initial guess of N/2 It then computes a better guess, according to the following formula: new-guess = ((N/last-guess) + last guess)/2; You will want to use a while loop for this algorigthm. Each time you do the calculation you will get a more accurate answer. Have your while loop continue executing until the accuracy is .000001 It can be shown that the accuracy of your "new guess" is: absolute_value of (new guess-last guess) If you are unfamiliar with absolute value, then we would say that for some variable x accuracy double x, absolute_value of x 1 .x gets a value somehow if (x- 0) absolutevalueofx = x; - - - else absolute value ofx -x; - Print the "Newton_sqrt" answer for computing a square root at the end of your while loop. Compare it with the Java Math function: Math.sqrt(N); sample output might look like: Enter in N for Newton: 200 Newton (200.0)-14.142135623730955 Math.sqrt -14.142135623730951
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
