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

Q11 · Write a Python function `simple_iteration(g, x0, tol=1e-6, max_iter=100)` that…

Root Finding: Simple Iteration 🟡 Intermediate Coding
Question

Write a Python function simple_iteration(g, x0, tol=1e-6, max_iter=100) that implements the Simple Iteration Method:

  • g is the rearranged function (e.g., lambda x: (3 + cos(x)) / 2)
  • x0 is the initial guess
  • Stop when $|x_{new} - x_{old}| < tol$ or after max_iter iterations
  • Print each iteration: iteration number, $x$ value, and current error

Test it on $2x - 3 = \cos(x)$ with $x_0 = 1.5$.

🔒

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…