- Asked 3/13
- 2073 Magh · 6 marks
- 2069 Poush · 4 marks
- 2068 Bhadra · 4 marks
Bisection method pseudo-code
Short answer
Bisection repeatedly halves an interval where f(a)f(b) < 0, using midpoint c = (a+b)/2. If f(c)=0 or interval half-width below tolerance, c is the root; otherwise replace a or b with c keeping a sign change, then repeat.
Write a pseudo-code (algorithm) to find a real root of a non-linear equation using the Bisection method.
Bisection method repeatedly halves an interval [a, b] in which f(a)·f(b) < 0 and keeps the half that still contains the root.
Pseudo-code
Algorithm: Bisection method
Input : function f(x), interval ends a and b,
tolerance e, maximum iterations N
Output: approximate root
1. Read a, b, e, N
2. If f(a) * f(b) >= 0 then
print "Root is not bracketed; choose other a, b"
stop
3. Set i = 1
4. Repeat steps 5 to 9 while i <= N
5. c = (a + b) / 2
6. If f(c) = 0 or (b - a)/2 < e then
print "Root =", c, "after", i, "iterations"
stop
7. If f(a) * f(c) < 0 then
b = c
else
a = c
8. i = i + 1
9. End repeat
10. Print "Method did not converge in N iterations"
11. Stop
Notes
- The number of iterations needed for tolerance e is n ≥ log((b − a)/e) / log 2.
- The method always converges, but slowly (error is halved each step).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- False position pseudo-code · Numerical Method, chapter 2 · asked 2×
- Gauss-Jordan pseudo-code · Numerical Method, chapter 3 · asked 4×
- Bisection method working principle · Numerical Method, chapter 2
- Secant method algorithm · Numerical Method, chapter 2 · asked 2×
- Power method pseudo-code · Numerical Method, chapter 3 · asked 2×
- Simpson 3/8 pseudo-code · Numerical Method, chapter 5
- Algorithm/pseudo-code for software PID · Embedded System, chapter 7 · asked 3×
- Algorithm versus pseudo-code · Computer Programming, chapter 2
- Real and pseudo-parallelism · Microprocessor, chapter 6
- Preemptive vs non-preemptive; real-time scheduling · Operating System, chapter 2