add lec04.js 01.01.04 readme

This commit is contained in:
Eric Douglas 2014-06-07 19:21:41 -03:00
parent cc0defed0f
commit 778e2d7a96

View File

@ -0,0 +1,16 @@
var x = 0.5;
var epsilon = 0.01;
var low = 0;
var high = x;
var ans = ( high + low ) / 2;
while ( Math.abs( Math.pow( ans, 2 ) ) >= epsilon && ans <= x ) {
console.log( 'ans = ' + ans + ' low = ' + low + ' high = ' + high );
if ( Math.pow( ans, 2 ) < x )
low = ans;
else
high = ans;
}
console.log( ans + ' is close to square root of ' + x );