Numerical methods for solving a nonlinear equation: Regula falsi method
Implementation of the regula falsi method (programming assignment)
Implement the regula falsi method in Python, that is, define the following Python function:
def regula_falsi_solve(f, a, b, tol=0.001, maxiter=100):
"""
Find the zero of a function f between a and b using the
Regula Falsi Method with tolerance tol (default: 0.001) and
maximum number of iterations equal to maxiter (default: 1000)
"""
In addition to the approximation of the zero, make sure that the function also returns the number of iterations needed. Apply the regula_falsi_solve
function to the polynomial \(x^3+2x-1\) on the interval \([0,1]\) once with the default value of the tolerance to see if everything works correctly.
Then apply the Python function to create a table of the number of iterations required for tolerance \(10^{-1}, 10^{-2}, 10^{-3},\ldots, 10^{-15}\). Verify that there is indeed a linear relationship between the number of iterations required \(i_n\) and the natural number \(n\) at a tolerance of \(10^{-n}\).
Unlock full access