Question
Write a Python function newton_raphson(f, df, x0, tol=1e-6, max_iter=50) implementing the Newton-Raphson Method.
fis the function,dfis 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.