- #1
Jamin2112
- 986
- 12
So I made a little application to show the steps of approximating a squareroot using the Babylonian Method:
http://jaminweb.com/squarerootCalc.html
It's not working all the time.
When I do the squareroot of 25 starting with an initial guess of 3.1, it works:
Applying xn+1=(xn2-S)/(2xn) with x0=3.1 and S=25 ...
x1=5.582258064516129
x2=5.030366246935904
x3=5.000091654256142
x4=5.000000000840035
x5=5
Awesome.
Then the page crashes when I try 128371923 and 19. So there's something wrong.
Here's the loop I use to generate the output:
In the above code, eps is gotten by the function
Are there any glaring fallacies?
http://jaminweb.com/squarerootCalc.html
It's not working all the time.
When I do the squareroot of 25 starting with an initial guess of 3.1, it works:
Applying xn+1=(xn2-S)/(2xn) with x0=3.1 and S=25 ...
x1=5.582258064516129
x2=5.030366246935904
x3=5.000091654256142
x4=5.000000000840035
x5=5
Awesome.
Then the page crashes when I try 128371923 and 19. So there's something wrong.
Here's the loop I use to generate the output:
Code:
for (var i = 1, xi = x0; Math.abs(Math.pow(xi,2) - S) >= eps; ++i)
{
xi = xi - (Math.pow(xi,2) - S)/(2*xi);
thisStr += "<p>x<sub>" + i + "</sub>=<b>" + xi + "</b></p>";
}
In the above code, eps is gotten by the function
Code:
function getMacheps()
{
var temp1 = 1.0, temp2, mchEps;
do {
mchEps = temp1
temp1 /= 2
temp2 = 1.0 + temp1
} while (temp2 > 1.0)
return mchEps;
}
Are there any glaring fallacies?
Last edited by a moderator: