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

Q16 · Write a Python function `newton_raphson(f, df, x0, tol=1e-6, max_iter=50)` implementing…

Root Finding: Newton-Raphson Method 🟡 Intermediate Coding
Question

Write a Python function newton_raphson(f, df, x0, tol=1e-6, max_iter=50) implementing the Newton-Raphson Method.

  • f is the function, df is its derivative
  • At each step print: iteration, $x$, $f(x)$, error
  • Stop when $|f(x)| < tol$

Apply it to $f(x) = x - \cos(x)$, $f'(x) = 1 + \sin(x)$, starting at $x_0 = 0.5$.

Then apply it to $f(x) = x^3 - x - 2$, $f'(x) = 3x^2 - 1$, starting at $x_0 = 1.5$.

Compare the number of iterations needed for each.

🔒

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…