Velocity Reviews > Square root of a number.

# Square root of a number.

priyam.trivedi@gmail.com
Guest
Posts: n/a

 03-01-2006
Hi!

Could anyone tell me how to find the square root of a number without
using the sqrt function. I did it by using Newton's Formula. How can it
be done by using the Binomial Theorem/Taylor Series? Is there any other
way of doing it rather than using series?

Thank you,

Priyam

Keith Thompson
Guest
Posts: n/a

 03-01-2006
"(E-Mail Removed)" <(E-Mail Removed)> writes:
> Could anyone tell me how to find the square root of a number without
> using the sqrt function.

Why? Is there something wrong with the sqrt function?

In any case, I don't think your question is particularly about C.
You might try comp.programming or one of the math.* groups.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

osmium
Guest
Posts: n/a

 03-01-2006
<(E-Mail Removed)> wrote:

> Could anyone tell me how to find the square root of a number without
> using the sqrt function. I did it by using Newton's Formula. How can it
> be done by using the Binomial Theorem/Taylor Series? Is there any other
> way of doing it rather than using series?

You can do it the way that used to be taught in elementary school.

Christian Bau
Guest
Posts: n/a

 03-01-2006
In article <(E-Mail Removed). com>,
"(E-Mail Removed)" <(E-Mail Removed)> wrote:

> Hi!
>
> Could anyone tell me how to find the square root of a number without
> using the sqrt function. I did it by using Newton's Formula. How can it
> be done by using the Binomial Theorem/Taylor Series? Is there any other
> way of doing it rather than using series?

The usual method is to calculate sqrt (1 / x) first using Newton
iteration, because it can be done in a form that doesn't need any slow
divisions; then multiply the result by x,

On a computer without floating point unit, a reasonable approach is to
find a square root similar to performing a division: sqrt (x) = x / sqrt
(x), only modifying the remainder and the divisor after each digit of
the result is found.

websnarf@gmail.com
Guest
Posts: n/a

 03-01-2006
(E-Mail Removed) wrote:
> Could anyone tell me how to find the square root of a number without
> using the sqrt function. I did it by using Newton's Formula. How can it
> be done by using the Binomial Theorem/Taylor Series? Is there any other
> way of doing it rather than using series?

Everything you ever wanted to know about square roots but were afraid

http://www.pobox.com/~qed/sqroot.html

I never thought of using the Binomial Theorem. I guess you would
normalize the exponent so that you could try to expand:

(1 + x) ^ 0.5 = 1 + Choose(0.5,1) * x + Choose(0.5,2) * x^2 + ...

were Choose(r,i) = r*(r-1)*(r-2)* ... * (r-i+1) / i!

This works directly for 1 <= r < 2. If we have 2 <= r < 4 then you can
compute the square root of the reciprocal and reciprocate it again at
the end.

But in general Taylor series like expansions are going to be slower
than the other calculating methods. Even the digit by digit methods
use fewer resources per digit.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Malcolm
Guest
Posts: n/a

 03-01-2006
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi!
>
> Could anyone tell me how to find the square root of a number without
> using the sqrt function. I did it by using Newton's Formula. How can it
> be done by using the Binomial Theorem/Taylor Series? Is there any other
> way of doing it rather than using series?
>
>

You are passed a positive real number.
You know that the square root cannot be less than zero, and cannot be
greater than the number itself.
Take the number halfway between (half the number you are passed) and
multiply it by itself. If it is equal to the number, you have your answer.
If it is too low, you have a new minimum, if it is too high, you have a new
maximum.
Repeat with these limits, until you either get the answer or hit the
floating point accuracy of the machine - this will happen quite quickly even
for huge arguments.

This isn't the most sophisticated algorithm, but it will work.
>

--
Buy my book 12 Common Atheist Arguments (refuted)

Richard Heathfield
Guest
Posts: n/a

 03-01-2006
Malcolm said:

> You are passed a positive real number.
> You know that the square root cannot be less than zero, and cannot be
> greater than the number itself.

double root = malcolmsqrt(0.25);

Oops.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

pete
Guest
Posts: n/a

 03-01-2006
Richard Heathfield wrote:
>
> Malcolm said:
>
> > You are passed a positive real number.
> > You know that the square root cannot be
> > less than zero, and cannot be
> > greater than the number itself.

>
> double root = malcolmsqrt(0.25);

The square root of N
Is in between N and one
Except for zero

--
pete

Ben Pfaff
Guest
Posts: n/a

 03-01-2006
pete <(E-Mail Removed)> writes:

> The square root of N
> Is in between N and one
> Except for zero

A math haiku. Bravo!
--
--Richard Heathfield

Richard Heathfield
Guest
Posts: n/a

 03-01-2006
pete said:

> Richard Heathfield wrote:
>>
>> Malcolm said:
>>
>> > You are passed a positive real number.
>> > You know that the square root cannot be
>> > less than zero, and cannot be
>> > greater than the number itself.

>>
>> double root = malcolmsqrt(0.25);

>
> The square root of N
> Is in between N and one
> Except for zero

If N and one are included in the range, then it works for zero too. And if
they're not, it doesn't work for one.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)