7.7 Exercises
199
3. x 0 = 1 and x 1 = 2.3
4. x 0 = 1 and x 1 = 2.4
Filename: secant_failure.*.
Exercise 7.3: Understand Why the Bisection Method Cannot Fail
Solve the same problem as in Exercise 7.1, using the bisection method, but let the
initial interval be [−5, 3]. Report how the interval containing the solution evolves
during the iterations.
Filename: bisection_nonfailure.*.
Exercise 7.4: Combine the Bisection Method with Newton’s Method
An attractive idea is to combine the reliability of the bisection method with the speed
of Newton’s method. Such a combination is implemented by running the bisection
method until we have a narrow interval, and then switch to Newton’s method for
speed.
Write a function that implements this idea. Start with an interval [a, b] and switch
to Newton’s method when the current interval in the bisection method is a fraction s
of the initial interval (i.e., when the interval has length s(b−a)). Potential divergence
of Newton’s method is still an issue, so if the approximate root jumps out of the
narrowed interval (where the solution is known to lie), one can switch back to the
bisection method. The value of s must be given as an argument to the function, but
it may have a default value of 0.1.
Try the new method on tanh(x) = 0 with an initial interval [−10, 15].
Filename: bisection_Newton.py.
Exercise 7.5: Write a Test Function for Newton’s Method
The purpose of this function is to verify the implementation of Newton’s method
in the Newton function in the file nonlinear_solvers.py. Construct an algebraic
equation and perform two iterations of Newton’s method by hand or with the aid of
SymPy. Find the corresponding size of |f (x)| and use this as value for eps when
calling Newton. The function should then also perform two iterations and return the
same approximation to the root as you calculated manually. Implement this idea for
a unit test as a test function test_Newton().
Filename: test_Newton.py.
Exercise 7.6: Halley’s Method and the Decimal Module
A nonlinear algebraic equation f (x) = 0 may also be solved by Halley’s method, 7
given as:
x n+1 = x n −
2f (x n )f (x n )
2f (x n ) 2 − f (x n )f (x n )
, n = 0, 1, . . . ,
with some starting value x 0 .
7 http://mathworld.wolfram.com/HalleysMethod.html.
Précédent

- 220/350

Suivant