Pencarian Akar Persamaan dengan Metode Bi-Section
<html>
<head>
<script language=”javascript”>
var x;
var fungsixy;
var xkiri;
var xkanan;
var deltax;
var xmin;
var xmax;
var xtengah;
var xtengah2;
var xm;
var y1;
var y2;xkiri=-7;
xkanan=6;
</script>
</head>
<body><script language=javascript>
document.write(“<b>xkiri      y      xkanan      y</b><br>”);
x=xkiri;
y=Math.pow(x,4)-x+1;
document.write(x+”   “+y+”   “);x=xkanan;
y=Math.pow(x,4)-x+1;
y1=Math.pow((x-1),4)-(x-1)+1;
document.write(x+”   “+y+”   <br>”);document.write(“— <br>”);
xtengah=(xkiri+xkanan)/2;
x=xtengah;
y=Math.pow(x,4)-x+1;
y1=Math.pow((x-1),4)-(x-1)+1;
y2=Math.pow((x+1),4)-(x+1)+1;
document.write(x+”   “+y+”   “+y1+”   “+y2+”<br>”);while (Math.abs(y)>0.1)
{
if (Math.abs(y1)>=Math.abs(y2))
{
xkiri=xtengah;
xtengah=(xkiri+xkanan)/2;
x=xtengah;
y=Math.pow(x,4)-x+1;
y1=Math.pow((x-1),4)-(x-1)+1;
y2=Math.pow((x+1),4)-(x+1)+1;
document.write(x+”   “+y+”   “+y1+”   “+y2+”<br>”);
}
else if (Math.abs(y1)<Math.abs(y2))
{
xkanan=xtengah;
xtengah=(xkiri+xkanan)/2;
x=xtengah;
y=Math.pow(x,4)-x+1;
y1=Math.pow((x-1),4)-(x-1)+1;
y2=Math.pow((x+1),4)-(x+1)+1;
document.write(x+”   “+y+”   “+y1+”   “+y2+”<br>”);
}
}
/*while (y>=-0.0001,y<=0.0001)
{
if (y1>y)
{
xtengah=xkiri+xkanan;
xkiri=xtengah/2;
}
else
{
xtengah=xkiri+xkanan;
xkanan=xtengah/2;
}
y=Math.pow(x,3)-x+1;
y1=Math.pow((x-1),3)-(x-1)+1;
document.write(x+”   “+y+”   “+y1+”<br>”);
}*/
</script>
</body>
</html>