Home

Bio
My Articles
Blog
Photo albums
Contact me

IT news
Articles


Simple algorithm for calculating square roots (part 1)

27 Jan 2007, 1823 read(s)
Tags:


Pages: 1 2 3 4

Do you know how the integrated SQRT function in each programming language work? Probably it is a complicated code full of formulas and complex expressions. Actually I haven't stuck into this code... However, I was inspired to write my own SQRT function that really calculates square roots.

Square roots calculation methods

There are a number of ways to calculate square roots without a calculator. I won't present or explain them all. I will just devote you to a simple way of calculating sqaure roots. The algorithm presented is written by me and the idea of this calculation is also mine. I don't plead that I'm the initial author if this idea as the method of calculation is quite simple, but I should say that I figured out everything alone without using any sources of information.

The simple way

To identify the correct value of the square root of a given number, we will first have to determine the bounds of this value and progressively to shrink that bound until we find that exact value. Let us denote the number, whose square root we will be looking for, with N. The square root of N is somewhere between 1 and N. Then we get the middle number between these two numbers: (N-1)/2+1 (example: N is 5, the middle number is (5-1)/2+1 = 4/2+1=2+1=3).

When we have the middle number we multipy this number by itself to see if we get the exact value of N. 3*3 = 9. That's more than 5, so ... this tells us that the value that we are looking for is between 1 and 3. We have new bounds. If the value was less than 5 we would have changed the bottom bound to the number: the middle number of (1,3) is 2. 2*2 = 4; 4 < 5, so ... the new bound is (2,3). The value is somewhere between these two. We continue repeating these steps until finding the exact value.


Pages: 1 2 3 4

Comments

vas: mnoo hitro algoritym4e, bravo a vyv principno dokolkoto znam v pove4eto programni ezici kvadratite se iz4islqvat po edna funkciq ot visha matematika - Analiz 2 izvestna kato Red na McLorrein ili neshto takova. ako imash jelanie mogesh da q razgledash, dokolkoto znam iz4islqva korenite dosta dobre samo deto ne znam kak to4no shte q opishesh na C, tyi kato sa nabytkani edni faktorieli i proizvodni ot pyrvi, vtori i po visok red... kolkoto pove4e se razvie reda, tolkova po to4en rezultat shte ti dade funkciqta ako imash jelanie, derzai...
Martin Tsarev: Ами ще се позанимавам, но малко по-нататък. Радвам се поне, че този алгоритъм сам съм го измислил и реализирал. Има доста начини за изчисляване на корени и избирането на най-оптималния много зависи. Ще ми отнеме доста време, ако се задълбоча ...
vas: e vse pak, bravo za ideqta, ne vseki se zanimava sam da si izmislq algoritmite, koeto si e dosta tejka rabota, a prosto krade ne4ii 4ujd pohvalno si e 4e si se zadylbo4il do tolkova, evala derzai
Anonymous:

Add comment...