# This worksheet contains the Maple commands from Chapter 10 of # Introduction to Scientific Programming by Joseph L. Zachary. # # This is the implementation of the bisection function from Figure 9.9. # > bisection := proc (function, positive, negative) > > local f, avg, pos, neg; > > f := function; > pos := positive; > neg := negative; > > if (f(pos) < 0) then > print(`Positive bound to bisection is bad`); > RETURN(); > fi; > > if (f(neg) > 0) then > print(`Negative bound to bisection is bad`); > RETURN(); > fi; > > avg := pos; > > while (avg <> (pos+neg)/2.0) do > avg := (pos + neg) / 2.0; > if (f(avg) >= 0) then > pos := avg; > else > neg := avg; > fi; > od; > > RETURN(avg); > > end; # # This is the cow function from Chapter 9. # > cow := (theta) -> sin(theta) - theta*cos(theta) - evalf(Pi/2); # # (10.1) An example of the use of the bisection procedure. # > bisection(cow, 2.5, 1.5); >