1.8. Further Exercises on Root-finding#
Exercise A
a)
Create a Python file (module) named rootfinding.py
, containing an updated version of your function for the bisection method with usage format
(root, errorEstimate, backwardError, functionEvaluations) =
bisection(f, a, b errorTolerance)
and add functions implementing the Newton and secant methods with usage
(root, errorEstimate, backwardError, functionEvaluations) =
newton(f, Df, x0, errorTolerance)
(root, errorEstimate, backwardError, functionEvaluations) =
secant(f, x0, x1, errorTolerance)
b) Then initially use each of this program to solve the equation
with an absolute error of no more than \(10^{-8}\), and then no more than \(10^{-15}\). Note in particular how many iterations and how many function evaluations are needed.
Do the final testing from a notebook, importing the three functions from this module.
However, initial code development and testing is sometimes most conveniently done within the module file, using the method with
if __name__ == "__main__":
We will discuss details like refinements and further test cases in class.
c) Discuss the comparisons of “speed” or “cost”, in terms of both iterations and function evaluations needed.