Re:AllRoots
- To: mathgroup <mathgroup at yoda.physics.unc.edu>
- Subject: Re:AllRoots
- From: HAY at leicester.ac.uk
- Date: Sat, 10 OCT 92 00:39:22 GMT
RE the recent note from akyildiz at vax.oxford.ac.uk A more functional form of the code is lefthalf[RealInterval[{x_, y_}]] := RealInterval[{x,(x+y)/2.}]; righthalf[RealInterval[{x_, y_}]] := RealInterval[{(x+y)/2.,y}]; containszero[RealInterval[{x_,y_}]] := (x <= 0 <= y); bisect[int_RealInterval] := {lefthalf[int],righthalf[int]}; step[f_][{ints__RealInterval}] := Select[(bisect/@{ints})//Flatten, containszero[f[#]]&]; intbisecF[f_Function, a_, b_, tol_] := Nest[step[f], {RealInterval[{a,b}]}, Ceiling[Log[2,(b-a)/tol]]]; It might be better style to combine the last two functions: intbisecF[f_Function, a_, b_, tol_] := With[ {step = Select[(bisect/@#)//Flatten, containszero[f[#]]&]& }, Nest[step, {RealInterval[{a,b}]}, Ceiling[Log[2,(b-a)/tol]]] ]; These seem to take about 75% of the time: the second form is marginally quicker than the first From Allan Hayes Department of Mathematics The University Leicester LE1 7RH U.K. hay at leicester.ac.uk