Computer Science Canada Babylonian method of Square roots |
Author: | Thuged_Out_G [ Mon Oct 27, 2003 10:39 pm ] |
Post subject: | Babylonian method of Square roots |
the babylonia method for calculating square roots involves iteration. Suppose you wish to find the square root of 5. The babylonian method starts with a wild card guess which we will call x. You then use the iteration rule where the next x equals 0.5(x+n/x). For example, if we start with x=10, then the next x would be 0.5(10+5/10) or 5.25. We use that new value for x to determine the next value. This continues until x converges on a specific value. As the difference in x values becomes very small you now have an approximation for the square root of 5. The formula for any positive square root n is x0.5(x+n/x). Write a function that approximates the square root of a number using the babylonian method. You should stop iterations when the value doesnt change to 2 decimal places. i have to have this function done for comp sci class....can anyone help? thanks |
Author: | Tony [ Mon Oct 27, 2003 10:53 pm ] | ||||
Post subject: | |||||
well function is already writen for you there, you just need to put that in a continues loop ![]()
although I dont quite understand how this is suppost to find anything ![]() just use
![]() |
Author: | Thuged_Out_G [ Mon Oct 27, 2003 10:54 pm ] |
Post subject: | |
lol i would, but i have to hand this is...its the final proggy for the functions unit lol |
Author: | Dan [ Mon Oct 27, 2003 10:57 pm ] |
Post subject: | |
well if x is a guess you whould probly whont to set it to a number graeter then the one you are finding the square root for. so set x to somting like: num to find square root of + 1. then just do thous math staments in your post in a loop that stops when the number is the the rigth range. you will most likey need to use real variables for this beacuse you need the demalses. EDIT: dang tony and his fast posting |
Author: | Tony [ Mon Oct 27, 2003 10:59 pm ] | ||
Post subject: | |||
well the function seems to be messed up... actually you can try to trim the value to keep on going like
|
Author: | Thuged_Out_G [ Mon Oct 27, 2003 11:01 pm ] | ||
Post subject: | |||
thats what i have so far, and it works....but it just gets less accurate the higher the number you put...it seems towork for values up to 10,000[/code] |
Author: | Tony [ Mon Oct 27, 2003 11:08 pm ] |
Post subject: | |
that's because for values of 10,000, you need to calculate new value more then 3 times (meaning have x4). and why is there a loop in function? It NEVER gets to endloop because of result |