2 Replies - 17908 Views - Last Post: 05 October 2007 - 05:31 AM Rate Topic: -----

#1 ds4plj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 05-October 06

calculating square root problem

Posted 05 October 2006 - 02:49 PM

Hi!

I'm just totally lost with my programming homework.
I was wondering if anyone can build an outline for this particular program , so I can work thru with you help!

Thank you so much again!


Description!
Calculate Square Root

This method for calculating the square root of a number N starts by making a (non zero) guess at the square root. It then uses the original guess to calculate a new guess, according to the formula

newGuess = ((N / oldGuess) + oldGuess) / 2.0;


Have two variables oldGuess and newGuess. Initialize oldGuess to N and calculate newGuess according to the above formula. Use a while loop to iterate as long as the absolute value of the difference between the oldGuess and newGuess is greater than 1.0E-06. Do not forget to reset the value of oldGuess to the newGuess value in the while loop. Use the built-in function Math.abs().

In your program you will prompt the user to enter a positive number. You will have to use a Scanner object to read the input in as a double. If the number is negative, print an error message and ask the user to try again. For a positive number, calculate the square root using the above method. Find the difference between the square root you obtained and the value obtained from Math.sqrt(). Write out the value the user entered, the square root you computed, and the difference (your square root - Math.sqrt()). Use the type double for all your calculations.

There is a piece of trivia associated with this algorithm. Professional mathematicians are familiar with this algorithm as Newton's method. But the algorithm is much older than Newton. In first century AD, the Greek mathematician Heron of Alexandria used this method to determine the square root of 720. There is evidence that this method goes even further back, as far as the Babylonians. In the Yale University Babylonian Collection, there is a cuneiform tablet that seems to use this method to calculate the square root of 2.

Entirely Optional: You can refine the initial guess so that the method converges faster. We know that the square root of 100 is 10, so a better initial guess for the square root of any 3 or 4 digit number is 10. Likewise, we know that the square root of 10,000 is 100, so a better initial guess for the square root of any 5 or 6 digit number is 100. And so on.

This post has been edited by ds4plj: 05 October 2006 - 02:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: calculating square root problem

#2 utastn2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-October 07

Re: calculating square root problem

Posted 05 October 2007 - 12:18 AM

Hey I have the same program to create and I'm totally lost as well. Just curious..is your profesor named Mitra?

View Postds4plj, on 5 Oct, 2006 - 02:49 PM, said:

Hi!

I'm just totally lost with my programming homework.
I was wondering if anyone can build an outline for this particular program , so I can work thru with you help!

Thank you so much again!


Description!
Calculate Square Root

This method for calculating the square root of a number N starts by making a (non zero) guess at the square root. It then uses the original guess to calculate a new guess, according to the formula

newGuess = ((N / oldGuess) + oldGuess) / 2.0;


Have two variables oldGuess and newGuess. Initialize oldGuess to N and calculate newGuess according to the above formula. Use a while loop to iterate as long as the absolute value of the difference between the oldGuess and newGuess is greater than 1.0E-06. Do not forget to reset the value of oldGuess to the newGuess value in the while loop. Use the built-in function Math.abs().

In your program you will prompt the user to enter a positive number. You will have to use a Scanner object to read the input in as a double. If the number is negative, print an error message and ask the user to try again. For a positive number, calculate the square root using the above method. Find the difference between the square root you obtained and the value obtained from Math.sqrt(). Write out the value the user entered, the square root you computed, and the difference (your square root - Math.sqrt()). Use the type double for all your calculations.

There is a piece of trivia associated with this algorithm. Professional mathematicians are familiar with this algorithm as Newton's method. But the algorithm is much older than Newton. In first century AD, the Greek mathematician Heron of Alexandria used this method to determine the square root of 720. There is evidence that this method goes even further back, as far as the Babylonians. In the Yale University Babylonian Collection, there is a cuneiform tablet that seems to use this method to calculate the square root of 2.

Entirely Optional: You can refine the initial guess so that the method converges faster. We know that the square root of 100 is 10, so a better initial guess for the square root of any 3 or 4 digit number is 10. Likewise, we know that the square root of 10,000 is 100, so a better initial guess for the square root of any 5 or 6 digit number is 100. And so on.

Was This Post Helpful? 0
  • +
  • -

#3 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: calculating square root problem

Posted 05 October 2007 - 05:31 AM

You will have to make an attempt in code before we can help, there are rules in this forum, I suggest you read them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1