- #1

- 986

- 9

## Main Question or Discussion Point

So I made a little application to show the steps of approximating a squareroot using the Babylonian Method:

http://jaminweb.com/squarerootCalc.html [Broken]

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 x

x

x

x

x

x

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 [Broken]

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 x

_{n+1}=(x_{n}^{2}-S)/(2x_{n}) with x_{0}=3.1 and S=25 ...x

_{1}=5.582258064516129x

_{2}=5.030366246935904x

_{3}=5.000091654256142x

_{4}=5.000000000840035x

_{5}=5Awesome.

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>";
}
```

Code:

```
function getMacheps()
{
var temp1 = 1.0, temp2, mchEps;
do {
mchEps = temp1
temp1 /= 2
temp2 = 1.0 + temp1
} while (temp2 > 1.0)
return mchEps;
}
```

Last edited by a moderator: