factnawer.blogg.se

Wolfram mathematica 7 mathid
Wolfram mathematica 7 mathid






Notice that the Babylonian method produces essentially the same numerical value as the built-in SQRT function in SAS. Proc print label label BabySqrt = "Babylonian Sqrt" run Input S = BabylonianSqrt (S ) /* Babylonian algorithm */ Sqrt = sqrt (S ) /* modern computation */ĭiff = abs (BabySqrt - Sqrt ) /* compare values */ Compare Babylonian algorithm to modern SQRT function */ options cmplib=work.funcs /* define location of functions */ data Compare X = (xPrev + S/xPrev )/ 2 /* iterate to improve guess */ end L = length (strip (str ) ) /* count how many digits */ĭ = ceil (L/ 2 ) /* about half as many digits (round up) */ * Rule of 2s and 7s: Count the number of digits in S.Ĭhoose initial guess to have half as many digitsįunction BabylonianGuess (S ) /* provide initial guess */ You can implement the algorithm directly as a DATA step program, but I chose to use PROC FCMP to define new DATA step functions. In tribute to all students who ever struggled to perform this algorithm by hand, I implemented the Babylonian square-root algorithm in SAS. Implement the Babylonian square-root algorithm in SAS The Rule of Twos and Sevens chooses an initial guess from among the candidates and then use the corresponding integer in the range as an initial guess. I invented a strategy for finding a good guess, which I call "The Rule of Twos and Sevens." I discovered that if you choose a good guess, then you have to compute only a few iterations. However, when I was a kid I used to race my friends to see who could find the square root the fastest. You can choose any positive value as an initial guess. Click To Tweet How do you choose an initial guess? The Babylonians and Greeks could estimate square roots by hand. The next iterations areīecause x 3 and x 4 agree to two decimal places, the algorithm ends after four iterations. The number 6 is a better approximation to sqrt(20). Let's use this algorithm to compute the square root of S = 20 to at least two decimal places. Convergence is achieved when the digits of x n+1 and x n agree to as many decimal places as you desire. The number x 1 is a better approximation to sqrt(S). Apply the formula x 1 = ( x 0 + S / x 0) / 2. To find the square root of S, do the following: Suppose you are given any positive number S. It was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. The iterative method is called the Babylonian method for finding square roots, or sometimes Hero's method. The magic formula improved my guess and estimated the square root that I sought. I then applied a "magic formula" a few times. The algorithm required that I make an initial guess for the square root. It was the first time that I thought math is magical. I still remember being amazed when I first saw the iterative square root algorithm. Scientific calculators with a square root key were not yet widely available, so I and previous generations of children suffered through learning to calculate square roots by hand. When I was in the sixth grade, I learned an iterative procedure for computing square roots by hand.








Wolfram mathematica 7 mathid