Teen Programmers Unite  
 

 

Return to forum top

Re: How does math functions work?

Posted by goetterfunken [send private reply] at July 08, 2003, 04:31:38 PM

Regarding sqrt, try the Heron-Algorithm to determine sqrt(a):
([] are to be read as indices)

s[0] = a
t[0] = 1

s[n] = (s[n-1]+t[n-1])/2
t[n] = a/s[n]

while n grows s[n] and t[n] approach at each other and sqrt[a].
Imagine a rectangle with side lengths of a and 1. We create iteratively new rectangles with area a but new side lenghts: One is the average of the side lengths of the previous rectangle, the other is clear, when the area remains a.

This rectangle gets closer and closer to be a square and so it's side lenghts to sqrt(a).

The algorithm is quite fast: About six to nine iterations for pocket calculator accuracy - and all you need is basic operations.

Regards,
Werner

Posted by goetterfunken [send private reply] at July 08, 2003, 04:33:13 PM

Whoops... that one went wrong... sorry about that... can anybody put the previous message in the right thread?

Sorry!

Posted by Psion [send private reply] at July 09, 2003, 12:14:47 AM

It's better in a new thread.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.