Bisection method

In mathematics, the bisection method is a root-finding method that applies to any continuous function for which one knows two values with opposite signs. The method consists of repeatedly bisecting the interval defined by these values, then selecting the subinterval in which the function changes sign, which therefore must contain a root. It is a very simple and robust method, but it is also relatively slow. Because of this, it is often used to obtain a rough approximation to a solution which is then used as a starting point for more rapidly converging methods.[1] The method is also called the interval halving method,[2] the binary search method,[3] or the dichotomy method.[4]
For polynomials, more elaborate methods exist for testing the existence of a root in an interval (Descartes' rule of signs, Sturm's theorem, Budan's theorem). They allow extending the bisection method into efficient algorithms for finding all real roots of a polynomial; see Real-root isolation.
The method
The method is applicable for numerically solving the equation for the real variable , where is a continuous function defined on an interval and where and have opposite signs. In this case and are said to bracket a root since, by the intermediate value theorem, the continuous function must have at least one root in the interval .
At each step the method divides the interval in two parts/halves by computing the midpoint of the interval and the value of the function at that point. If itself is a root then the process has succeeded and stops. Otherwise, there are now only two possibilities: either and have opposite signs and bracket a root, or and have opposite signs and bracket a root.[5] The method selects the subinterval that is guaranteed to be a bracket as the new interval to be used in the next step. In this way an interval that contains a zero of is reduced in width by 50% at each step. The process is continued until the interval is sufficiently small.
Explicitly, if then may be taken as the solution and the process stops.
Otherwise, if and have the same signs,
- then the method sets ,
- else the method sets .
In both cases, the new and have opposite signs, so the method may be applied to this smaller interval.[6]
Once the process starts, the signs at the left and right ends of the interval remain the same for all iterations.
Stopping conditions
In order to determine when the iteration should stop, it is necessary to consider various possible stopping conditions with respect to a tolerance (). Burden & Faires state:[7]
we can select a tolerance and generate p1, ..., pN until one of the following conditions is met:
(2.1) or (2.2) (2.3) Unfortunately, difficulties can arise using any of these stopping criteria ... Without additional knowledge about or , Inequality (2.2) is the best stopping criterion to apply because it comes closest to testing relative error.
The objective is to find an approximation, within the tolerance, to the root.
The following shows that (2.3) does not give such an approximation unless .
If is a root of , then and .
This means that (2.3) can be written as
.
Suppose, for the purpose of illustration, the tolerance is . Now take the case in which so that the approximate value is in the interval
The problem is that, for small (i.e. the slope near the root is small), the interval can be quite large - for example, if , the approximation to 0 could be in
Hence, unless the magniitude of the slope near the root is , this condition will not give a useful result - and the slope is unknown until the root is known.
In fact, using involves a logical fallacy. It is obvious that if is sufficiently close to the root that will become less than . That does not mean that, if , is close to the root!
The other two possibilities represent different concepts - for example, the absolute difference says that c and a are the same to decimal places, while the relative difference says that c and a are the same to significant digits[8].
Note the use of for the tolerance. If 2 numbers differ by this amount then, depending on whether absolute differences or relative differences are being used, the numbers have either decimal places or digits in common. The use of a tolerance such as provides no better information.
Iteration process
The input for the method is a continuous function and an interval , such that the function values and are of opposite sign (there is at least one zero crossing within the interval). Each iteration performs these steps:
- Calculate , the midpoint of the interval, ;
- Calculate the function value at the midpoint, ;
- If , return c;
- If convergence is satisfactory (that is, is sufficiently small), return ;
- Examine the sign of and replace either or with so that there is a zero crossing within the new interval.
Algorithm
import numpy as np
def bisect(f, a, b, tol):
if a > b: # Check that the user has the correct order for endpoints.
a, b = b, a
fa = f(a)
fb = f(b)
i = 0
if np.sign(fa) == np.sign(fb): # Check for opposite signs.
return float("NAN"), i, b - a, "Same sign"
while True:
i += 1
c = (b + a) / 2
fc = f(c)
if b - a <= 5e-324: # Check for min. interval width.
return 5e-324, i, b - a, "Min sub"
if fc == 0: # Return if f(c) evaluates to 0.
return c, i, b - a, "f(c)=0"
if b - a <= abs(c) * tol: # Test for convergence.
return c, i, b - a, "Tol"
if np.sign(fa) == np.sign(fc):
a = c
else:
b = c
if i > 2100: # See example 3.
return c, i, b - a, "Max iter"
Note that there is only one function evaluation per iteration.
If the algorithm returns before tolerance is reached, it is possible to determine the number of significant figures that are returned.
If, after iterations, is satisfied, then digits have been returned.
So can be solved - from which is the number of digits returned.
def compute_sig_digits(width, c):
if width == 0 or c == 0:
return 0
ratio = (5 * abs(c)) / width
return max(0, int(math.floor(math.log10(ratio))))
Testing
1) Test to see if and have same sign:
bisect(lambda x: (x - 1.234567890), 0, 1, tol=5e-15)
Root = nan | Iters = 0
b - a = 1.0000000000000000e+00 Cause = Same sign
compute_sig_digits(b-a, c) = 0
2) Test to see what happens if user has entered the endpoints correctly:
bisect(lambda x: (x - 1.2345678901234567890), 2, 1, tol=5e-15)
Root = 1.2345678901234560243e+00 | Iters = 49
b - a = 3.5527136788005009e-15 Cause = Tol
compute_sig_digits(b-a, c) = 15
3) Determine the maximum number of iterations likely to be needed:
bisect(lambda x: (x - 1.2345678901234567890e-308), 1e-308, 1.1e308, tol=5e-15)
Root = 1.2345678901234546944e-308 | Iters = 2095
b - a = 4.9406564584124654e-323 Cause = Tol
compute_sig_digits(b-a, c) = 15
4) Test behavior for a very large root:
bisect(lambda x: (x - 1.2345678901234567890e307), 0, 2e307, tol=5e-15)
Root = 1.2345678901234559937e+307 | Iters = 50
b - a = 3.4927205416857597e+292 Cause = Tol
compute_sig_digits(b-a, c) = 15
5) Test behavior for a large root:
bisect(lambda x: (x - 1.2345678901234567890e50), 0, 2e50, tol=5e-15)
Root = 1.2345678901234562507e+50 | Iters = 50
b - a = 3.5307618638036828e+35 Cause = Tol
compute_sig_digits(b-a, c) = 15
6) Test behavior for a polynomial:
bisect(lambda x: (x**3 - x - 2), 0, 10, tol=5e-15)
Root = 1.5213797068045686878e+00 | Iters = 52
b - a = 4.4408920985006262e-15 Cause = Tol
compute_sig_digits(b-a, c) = 15
7) Test behavior multiple roots I:
bisect(lambda x: (math.sin(x)), 0.01, 10, tol=5e-15)
Root = 3.1415926535897922278e+00 | Iters = 51
b - a = 8.8817841970012523e-15 Cause = Tol
compute_sig_digits(b-a, c) = 15
8) Test behavior multiple roots II:
bisect(lambda x: (math.sin(x)), 7, 10, tol=5e-15)
Root = 9.4247779607693829007e+00 | Iters = 47
b - a = 4.2632564145606011e-14 Cause = Tol
compute_sig_digits(b-a, c) = 15
The root found depends on the initial interval.
9) Test behavior for higher order root:
bisect(lambda x: (x - 1.23456789012345e-100)**3, 0, 1, 5e-15)
Root = 1.2345678980942787685e-100 | Iters = 357
b - a = 6.8127357440130412e-108 Cause = f(c)=0
compute_sig_digits(b-a, c) = 7
This test shows, for the first time, a situation in which the cause of termination was even though is not the exact root.
This occurs because, using computer arithmetic, a function can evaluate to zero even if it is not identically zero -
This number is less than the minimum subnormal and hence equates to 0.
The iteration stopped for , but the algorithm returned a result with 7 significant digits.
10) Test for a small root:
bisect(lambda x: (x - 1.2345678901234567890e-10), 0, 1, tol=5e-15)
Root = 1.2345678901234560005e-10 | Iters = 82
b - a = 4.1359030627651384e-25 Cause = Tol
Significant digits = 15
11) Test for really small root:
bisect(lambda x: (x - 1.2345678901234567890e-308), 0, 1, tol=5e-15)
Root = 1.2345678901234551885e-308 | Iters = 1072
b - a = 3.9525251667299724e-323 Cause = Tol
Significant digits = 15
This is close to the minimum normal. The final interval width is close to the minimum subnormal
12) Test for a root that is less than the minimum normal:
bisect(lambda x: (x - 1.2345678901234567890e-315), 0, 1, tol=5e-15)
Root = 1.2345678910036845193e-315 | Iters = 1074
b - a = 9.8813129168249309e-324 Cause = f(c)=0
Significant digits = 8
Notice that the cause of the return was .
Even though the root is less than the minimum normal, 8 significant figures are obtained
It is often stated that the Bisection method is 'slow but sure'.The slowness refers to the fact that it is linear in its convergence and its sureness comes from the fact that the root is always contained within an interval which is decreasing in width. As has been seen, this sureness depends on the stopping condition with the relative error performing best.
Popular alternatives to the bisection method, are Newton-Raphson method, Secant method, Ridders' method, or Brent's method. These typically exhibit a better order of convergence to the root. While these alternatives may have a better order of convergence they may also require more function evaluations and/or may fail to converge
An improvement to the bisection method can be achieved with a higher order of convergence without trading-off worst case performance with the rather new ITP Method.[9]
Beware that most of the implementations of these algorithms use the absolute error as a stopping condition. Before using any algorithm, test to ensure that it produces correct results for small roots.
Generalization to higher dimensions
The bisection method has been generalized to multi-dimensional functions. Such methods are called generalized bisection methods.[10][11]
Methods based on degree computation
Some of these methods are based on computing the topological degree.[12]
Characteristic bisection method
The characteristic bisection method uses only the signs of a function in different points. Lef f be a function from Rd to Rd, for some integer d ≥ 2. A characteristic polyhedron[13] (also called an admissible polygon)[14] of f is a polyhedron in Rd, having 2d vertices, such that in each vertex v, the combination of signs of f(v) is unique. For example, for d=2, a characteristic polyhedron of f is a quadrilateral with vertices (say) A,B,C,D, such that:
- Sign f(A) = (-,-), that is, f1(A)<0, f2(A)<0.
- Sign f(B) = (-,+), that is, f1(B)<0, f2(B)>0.
- Sign f(C) = (+,-), that is, f1(C)>0, f2(C)<0.
- Sign f(D) = (+,+), that is, f1(D)>0, f2(D)>0.
A proper edge of a characteristic polygon is a edge between a pair of vertices, such that the sign vector differs by only a single sign. In the above example, the proper edges of the characteristic quadrilateral are AB, AC, BD and CD. A diagonal is a pair of vertices, such that the sign vector differs by all d signs. In the above example, the diagonals are AD and BC.
At each iteration, the algorithm picks a proper edge of the polyhedron (say, A--B), and computes the signs of f in its mid-point (say, M). Then it proceeds as follows:
- If Sign f(M) = Sign(A), then A is replaced by M, and we get a smaller characteristic polyhedron.
- If Sign f(M) = Sign(B), then B is replaced by M, and we get a smaller characteristic polyhedron.
- Else, we pick a new proper edge and try again.
Suppose the diameter (= length of longest proper edge) of the original characteristic polyhedron is . Then, at least bisections of edges are required so that the diameter of the remaining polygon will be at most .[14]: 11, Lemma.4.7
See also
- Binary search algorithm
- Lehmer–Schur algorithm, generalization of the bisection method in the complex plane
- Nested intervals
References
- ^ Burden & Faires 2016, p. 51
- ^ "Interval Halving (Bisection)". Archived from the original on 2013-05-19. Retrieved 2013-11-07.
- ^ Burden & Faires 2016, p. 48
- ^ "Dichotomy method - Encyclopedia of Mathematics". www.encyclopediaofmath.org. Retrieved 2015-12-21.
- ^ If the function has the same sign at the endpoints of an interval, the endpoints may or may not bracket roots of the function.
- ^ Burden & Faires 2016, p. 48
- ^ Burden & Faires 2016, p. 50
- ^ Burden & Faires 2016, p. 18
- ^ Ivo, Oliveira (2020-12-14). "An Improved Bisection Method".
- ^ Mourrain, B.; Vrahatis, M. N.; Yakoubsohn, J. C. (2002-06-01). "On the Complexity of Isolating Real Roots and Computing with Certainty the Topological Degree". Journal of Complexity. 18 (2): 612–640. doi:10.1006/jcom.2001.0636. ISSN 0885-064X.
- ^ Vrahatis, Michael N. (2020). Sergeyev, Yaroslav D.; Kvasov, Dmitri E. (eds.). "Generalizations of the Intermediate Value Theorem for Approximating Fixed Points and Zeros of Continuous Functions". Numerical Computations: Theory and Algorithms. Cham: Springer International Publishing: 223–238. doi:10.1007/978-3-030-40616-5_17. ISBN 978-3-030-40616-5.
- ^ Kearfott, Baker (1979-06-01). "An efficient degree-computation method for a generalized method of bisection". Numerische Mathematik. 32 (2): 109–127. doi:10.1007/BF01404868. ISSN 0945-3245.
- ^ Vrahatis, Michael N. (1995-06-01). "An Efficient Method for Locating and Computing Periodic Orbits of Nonlinear Mappings". Journal of Computational Physics. 119 (1): 105–119. doi:10.1006/jcph.1995.1119. ISSN 0021-9991.
- ^ a b Vrahatis, M. N.; Iordanidis, K. I. (1986-03-01). "A rapid Generalized Method of Bisection for solving Systems of Non-linear Equations". Numerische Mathematik. 49 (2): 123–138. doi:10.1007/BF01389620. ISSN 0945-3245.
- Burden, Richard L.; Faires, J. Douglas (2016), "2.1 The Bisection Algorithm", Numerical Analysis (10th ed.), Cenage Learning, ISBN 978-1-305-25366-7
Further reading
- Corliss, George (1977), "Which root does the bisection algorithm find?", SIAM Review, 19 (2): 325–327, doi:10.1137/1019044, ISSN 1095-7200
- Kaw, Autar; Kalu, Egwu (2008), Numerical Methods with Applications (1st ed.), archived from the original on 2009-04-13
External links
- Bisection Method Notes, PPT, Mathcad, Maple, Matlab, Mathematica from Holistic Numerical Methods Institute
⊤