########## # Find the roots of a nonlinear # equation using the bisection method ########## # Set the function to be used in f(x)=0. f:= x-> x^5-3*x^4+2*x^2-4: # Plot f(x) # plotsetup(x11); # plot(f(x),x=-1..3); # Choose initial interval [a,b] a:= 2.: b:=3.: eps:=1.0; x1:=a: x2:=b: for i from 1 while eps > 0.01 do x3:= (x1+x2)/2.; if (f(x3)*f(x1)<0.) then x2:=x3 else x1:=x3 end if; eps:= abs(f(x3)); end do;