Bisection Method: Enter First Initial Approx Enter The Second Approx
Bisection Method: Enter First Initial Approx Enter The Second Approx
wxm
1 / 1
bisection method
(%i1) block([x0,x1,Nmax,i:0],f(x):=x^2-2,loop1,
x0:read("enter first initial approx"),
x1:read("enter the second approx"),
if(f(x0)*f(x1)<0)then print("initial app are ok")else go(loop1),
Nmax:read("enter the max number of iteration"),loop2,i:i+1,
mid:((x0+x1)/2),if(f(x0)*f(mid)<0)then x1:mid else x0:mid,
print("x0= ",x0,"x1= ",x1,"app root after ",i,"iterations= ",((x0+x1)/2)
if(i<=Nmax)then go(loop2)else return(alldone));
enter first initial approx 1.0;
enter the second approx 2.0;
initial app are ok
enter the max number of iteration 10;
x0= 1.0 x1= 1.5 app root after 1 iterations= 1.25
x0= 1.25 x1= 1.5 app root after 2 iterations= 1.375
x0= 1.375 x1= 1.5 app root after 3 iterations= 1.4375
x0= 1.375 x1= 1.4375 app root after 4 iterations= 1.40625
x0= 1.40625 x1= 1.4375 app root after 5 iterations= 1.421875
x0= 1.40625 x1= 1.421875 app root after 6 iterations= 1.4140625
x0= 1.4140625 x1= 1.421875 app root after 7 iterations= 1.41796875
x0= 1.4140625 x1= 1.41796875 app root after 8 iterations= 1.416015625
x0= 1.4140625 x1= 1.416015625 app root after 9 iterations= 1.4150390625
x0= 1.4140625 x1= 1.4150390625 app root after 10 iterations=
1.41455078125
x0= 1.4140625 x1= 1.41455078125 app root after 11 iterations=
1.414306640625
(%o1) alldone