Question

public static int newtonCount​(double x, double err) Determines the number of iterations of Newton's method required...

 
public static int newtonCount​(double x, double err)

Determines the number of iterations of Newton's method required to approximate the square root of x within the given bound. Newton's method starts out by setting the initial approximate answer to x. Then in each iteration, answer is replaced by the quantity (answer + x / answer) / 2.0. The process stops when the difference between x and (answer * answer) is strictly less than the given bound err. The method returns the number of iterations required. The given value x must be non-negative.

For example, given x = 10 the first three iterations of Newton's method produce the approximate values 5.5, 3.66, and 3.20. Those three values squared are 30.29, 13.39, and 10.21, respectively. Therefore newtonCount(10, 1.0) returns 3, since it takes 3 iterations to get the result 10.21 that is within 1.0 of x. On the other hand, newtonCount(10, 200) returns 0, since 10 * 10 = 100 is already within 200 units of x = 10.

Parameters:

x - value whose square root is to be approximated

err - given bound for the approximation

Returns:

number of iterations required to get an approximation whose square is within the given bound of x

Homework Answers

Answer #1

/*Function to determines the number of iterations of Newton's method required to approximate the square root of x within the given bound.*/

public static int newtonCount(double x,double err){
    int iteration_counter=0;                      /*To determines the number of iterations*/
    double answer=x;
    while((answer*answer)-x>=err){               /*To ensure the difference between x and (answer * answer) is strictly less than the given bound err*/
      iteration_counter++;                       /*Iteration counter increment*/
      answer=(answer+ (x/answer))/2.0;           /*updated answer*/
    }
    return iteration_counter;
  }

//Have any doubt ask in comment box .

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
3.8/3.9 5. Use Newton's Method to approximate the zero(s) of the function. Continue the iterations until...
3.8/3.9 5. Use Newton's Method to approximate the zero(s) of the function. Continue the iterations until two successive approximations differ by less than 0.001. Then find the zero(s) to three decimal places using a graphing utility and compare the results. f(x) = 3 − x + sin(x) Newton's Method: x= Graphing Utility: x= 6. Find the tangent line approximation T to the graph of f at the given point. Then complete the table. (Round your answer to four decimal places.)...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most competitive in Thailand. With a large number of players ranging from restaurants in five-star hotels, global fast-food chains to small stalls along the streets and everything in between, the Thais are spoiled for choice. In addition, as the world becomes globalized, consumers are familiar with international dishes and would not hesitate to try new offerings from the other side of the globe. As a...