Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

square root iterative

Status
Not open for further replies.

onlyuros

Programmer
Sep 17, 2010
2
RS
Aloha,

what would be the way to calculate the square root of a number e.g. A with precision E with formula X(0)=(A+1)/2, X(i)=(X(i-1) + A/X(i-1))/2, i=1,2,... ? Tnx!
 
You should have written :
X(0)=(1+A/1)/2,
X(i)=(X(i-1) + A/X(i-1))/2.
It is easier to see the recursion.
 
Ah yes, sorry. I have no idea how to do it since I'm quite new to prolog.
 
You can do it with a predicate of 4 arguments my_square_root/4 .
arg 1 : the number you're looking for the square_root.
arg 2 : epsilon
arg 3 : the current computed value of the square root
arg 3 : the final result

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top