The Bisection Method
The Bisection Method
html
Introduction
Bisection Method:
Root of a function:
f(a) = 0
Example:
Function: f(x) = x2 - 4
Roots: x = -2, x = 2
Because:
f(-2) = (-2)2 - 4 = 4 - 4 = 0
f(2) = (2)2 - 4 = 4 - 4 = 0
A Mathematical Property
If a function f(x) is continuous on the interval [a..b] and sign of f(a) ≠ sign of f(b), then:
Example:
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 1/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
The Bisection Method is a successive approximation method that narrows down an interval that contains a root of
the function f(x)
The Bisection Method is given an initial interval [a..b] that contains a root
(We can use the property sign of f(a) ≠ sign of f(b) to find such an initial interval)
The Bisection Method will cut the interval into 2 halves and check which half interval contains a root of the function
The Bisection Method will keep cut the interval in halves until the resulting interval is extremely small
The root is then approximately equal to any value in the final (very small) interval.
Example:
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 2/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
We cut the interval [a..b] in the middle: m = (a+b)/2
Because sign of f(m) ≠ sign of f(a) , we proceed with the search in the new interval [a..b]:
b = m;
In the above example, we have changed the end point b to obtain a smaller interval that still contains a root
In other cases, we may need to changed the end point b to obtain a smaller interval that still contains a root
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 3/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
After cutting the interval in half, the root is contained in the right-half, so we have to change the end
point a:
f(0) = 02 − 5 = −5
f(4) = 42 − 5 = 11
Start:
a = 0; f(a) = -5
b = 4; f(b) = 11
Iteration 1:
m = (a + b)/2 = 2
f(m) = 22 − 5 = -1
a = 2; f(a) = -1
b = 4; f(b) = 11
Iteration 2:
m = (a + b)/2 = 3
f(m) = 32 − 5 = 4
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 4/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
a = 2; f(a) = -1
b = 3; f(b) = 4
Iteration 3:
m = (a + b)/2 = 2.5
a = 2; f(a) = -1
b = 2.5; f(b) = 1.25
And so on....
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 5/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
Approximate root = (a+b)/2; (any point between [a..b] will do
because the interval [a..b] is very small)
Example execution:
We will use a simple function to illustrate the execution of the Bisection Method
Function used:
f(x) = x2 - 3
f(0) = 02 − 3 = −3
f(4) = 42 − 3 = 13
The interval [0..4] contains a root because: sign of f(0) ≠ sign of f(4)
Iteration 1:
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 6/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
Iteration 2:
Iteration 3:
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 7/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
And so on !!
Result:
When the interval is smaller than 0.000001, the while-loop will exit
At that moment, the end points of the interval will be very close to root √3
Java program:
a = 0; b = 4;
if ( (y_m > 0 && y_a < 0) || (y_m < 0 && y_a > 0) )
{ // f(a) and f(m) have different signs: move b
b = m;
}
else
{ // f(a) and f(m) have same signs: move a
a = m;
}
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 8/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
System.out.println("New interval: [" + a + " .. " + b + "]");
// Print progress
}
Output:
f(x) = x3 + x - 3
// Solves: x^3 + x - 3 = 0
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 9/10
17/02/2020 www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html
{
final double epsilon = 0.00001;
double a, b, m, y_m, y_a;
a = 0; b = 4;
if ( (y_m > 0 && y_a < 0) || (y_m < 0 && y_a > 0) )
{ // f(a) and f(m) have different signs: move b
b = m;
}
else
{ // f(a) and f(m) have same signs: move a
a = m;
}
System.out.println("New interval: [" + a + " .. " + b + "]");
}
We had to change the body of the Java program to find the root of a different function
y_m = f(m);
y_a = f(a);
When we solve a different function, we make changes to the function definition f()
www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html 10/10