Bisection Method
Bisection Method
Introduction
• Bisection Method:
• Root of a function:
• f(a) = 0
Introduction (cont.)
• 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
b = m;
The Bisection Method (cont.)
• f(0) = 02 − 3 = −3
• f(4) = 42 − 3 = 13
• Iteration 1:
• Iteration 2:
• Iteration 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;
}
System.out.println("New interval: [" + a + " .. " + b + "]");
// Print progress
}
f(x) = x3 + x - 3
// Solves: x^3 + x - 3 = 0
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 + "]");
}
y_m = f(m);
y_a = f(a);
Finding the roots of a different function (cont.)