1.A nonlinear algebraic equation f (x) = 0 may be solved in many different ways, and we have met some of these in this chapter. Another, very useful, solution approach is to first re-write the equation into x = φ(x) (this re-write is not unique), and then formulate the iteration xn+1 = φ(xn), n = 0, 1,… , with some starting value x0. If φ(x) is continuous, and if φ(xn) approaches α as xn approaches α (i.e., we get α = φ(α) as n → ∞), the iteration is called a fixed point iteration and α is referred to as a fixed point of the mapping x → φ(x). Clearly, if a fixed point α is found, α will also be a solution to the original equation f (x) = 0. In this exercise, we will briefly explore the fixed point iteration method by solving x3 + 2x = e−x, x ∈ [−2, 2] . For comparison, however, you will first be asked to solve the equation by Newton’s method (which, in fact, can be seen as fixed point iteration8).
a) Write a program that solves this equation by Newton’s method. Use x = 1 as your starting value. To better judge the printed answer found by Newton’s method, let the code also plot the relevant function on the given interval.
b) The given equation may be rewritten as x = e−x−x3 2 . Extend your program with a function fixed_point_iteration, which takes appropriate parameters, and uses fixed point iteration to find and return a solution (if found), as well as the number of iterations required. Use x = 1 as starting value.When the program is executed, the original equation should be solved both with Newton’s method and via fixed point iterations (as just described). Compare the output from the two methods.