Fnding Roots by half-interval- method
The half interval method is the most basic method to find roots of an equation i.e to find x such that f(x) = 0 , where f is a continuos function. Now the idea is if we have two points a and b such that f(a) < 0 < f(b) then f must have atleast one zero between a and b. So to locate a zero we’ll take average of a and b and compute f(x) where x is average of a and b.If f(x) > 0,then f must have zero between a and x.If f(x) < 0 , then f must have zero between x and b.So we continue this way to identify smaller and smaller intervals on which f must have a zero.Therefore when we reach a point where interval is small enough the process stops. Since we are calculating average at each level and decreasing our level of uncertainity by half , the number of steps required grows as O (log (L/T)) ,where L is the length of original interval i.e difference of a and b and T is the error tolereance (size of interval we consider small enough).
(define (search f neg-point pos-point)
(let ((midpoint (average neg-point pos-point)))
(if (close-enough? neg-point pos-point)
midpoint
(let ((test-value (f midpoint)))
(cond ((positive? test-value)
(search f neg-point midpoint))
((negative? test-value)
(search f midpoint pos-point))
(else midpoint))))))
Above pseudo-code is taken from Structure And Interpretation of Computer Programs.Now the close-enough? used above which is breaking condition for the recursive function will be :
(define (close-enough? x y)
(< (abs (- x y)) 0.001))
close-enough? function will decide how much accurate will be our answer.
To summarise we are getting roots of the equation in O(log (L/T)) by half-interval method.