ΣνΜDr. Sharon's Math PlatformSyvara Learning
Question Bank › 📘 Undergraduate › Numerical Method with Python (Math & Eng) › Q13

Q13 · Write a Python function `bisection(f, a, b, tol=1e-6)` that implements the Bisection…

Root Finding: Bisection Method 🟡 Intermediate Coding
Question

Write a Python function bisection(f, a, b, tol=1e-6) that implements the Bisection Method:

  • Raise a ValueError if $f(a)$ and $f(b)$ have the same sign (no root guaranteed)
  • At each iteration print: iteration number, $a$, $b$, midpoint $c$, $f(c)$
  • Stop when $|b - a| < tol$

Apply it to $f(x) = x - \cos(x)$ on $[0, 1]$ with tolerance $10^{-6}$. Report the root and how many iterations were needed.

🔒

Log in to see the worked solution

Enter your email to get started. Your first free solutions in every course unlock as soon as you verify.

Log in or sign up with email
← Previous Next →
Working…