Computer Science/Numerical Methods/ Bisection method example

Computer Science/Numerical Methods/ Bisection method example



play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00

Bisection Method – Numerical Methods (Computer Science)

The Bisection Method is a root-finding technique that applies to continuous functions where the root lies between two given points. It is a simple and reliable method based on the Intermediate Value Theorem.

 Algorithm of Bisection Method

 Select two points a and b such that f(a)f(a) and f(b)f(b) have opposite signs (i.e., f(a)×f(b)<0f(a) \times f(b) < 0), ensuring a root exists in between.
 Compute the midpoint cc:

c=a+b2c = \frac{a + b}{2}

 Check f(c)f(c):

  • If f(c)=0f(c) = 0, then cc is the root.

  • If f(a)×f(c)<0f(a) \times f(c) < 0, then the root lies in [a, c], set b=cb = c.

  • Else, the root lies in [c, b], set a=ca = c.
     Repeat the process until the error tolerance is met:

∣b−a∣<tolerance|b – a| < \text{tolerance}

 Example: Find the root of f(x)=x3−x−2f(x) = x^3 – x – 2 in [1, 2]

Step 1: Check function values

f(1)=13−1−2=−2f(1) = 1^3 – 1 – 2 = -2
f(2)=23−2−2=4f(2) = 2^3 – 2 – 2 = 4
Since f(1)×f(2)<0f(1) \times f(2) < 0, a root exists between 1 and 2.

Step 2: Iterations

Iteration aa bb c=a+b2c = \frac{a+b}{2} f(c)f(c) Interval Change
1 1 2 1.5 -0.875 [1.5,2][1.5, 2]
2 1.5 2 1.75 1.609 [1.5,1.75][1.5, 1.75]
3 1.5 1.75 1.625 0.666 [1.5,1.625][1.5, 1.625]
4 1.5 1.625 1.5625 -0.271 [1.5625,1.625][1.5625, 1.625]
5 1.5625 1.625 1.5938 0.184 [1.5625,1.5938][1.5625, 1.5938]

The root is approximately 1.5938 with a small error.

Python Code for Bisection Method

def f(x):
return x**3 - x - 2 # Define the function

def bisection(a, b, tol=1e-6):
if f(a) * f(b) >= 0:
print("Incorrect initial guesses.")
return None

while abs(b - a) > tol:
c = (a + b) / 2
if f(c) == 0:
return c # Exact root found
elif f(a) * f(c) < 0:
b = c
else:
a = c
return (a + b) / 2

root = bisection(1, 2)
print("Root is:", root)

 Applications of Bisection Method

Solving non-linear equations in engineering & science
Finding zero crossings in signal processing
Used in numerical simulations & modeling

 Conclusion:

The Bisection Method is a simple, robust but slow root-finding method. It is best suited for cases where guaranteed convergence is needed.

Computer Science/Numerical Methods/ Bisection method example

Numerical Methods – Australian Mathematical Sciences Institute

Solutions of Equations in One Variable The Bisection Method

Solution of Algebraic and Transcendental Equations



Leave a Reply

Your email address will not be published. Required fields are marked *

error: