# Section 2.1: Example 1(p.53, ex.3(a));

                  Math 354/ Mast 334

                  by Dr. M. Mei

                  # (p.53, ex.3(a))Use the Bisection method to find solutions accurate to

                  # within 0.01 for x^3-7*x^2+14*x-6=0 on [0,1].

                   

> a:=0; b:=1; f:=x->evalf(x^3-7*x^2+14*x-6); maxstep:=7; er:=100; tolerance:=0.01;

> for i from 1 to maxstep while er>tolerance do p:=(a+b)/2;

> if evalf(f(a)*f(p))<0 then b:=p else a:=p end if;

> ans:=(a+b)/2; er:=abs((a-b)/2); print("(",a,b,")",

answer= ",ans, " error= ", evalf(er));

> end do;

> evalf(ans);

>