Solving Nonlinear Equations with Newton's Method

Three simple codes for scalar equations illustrate the fundamental ideas well. newtsol.m, chordsol.m, and secant.m are MATLAB implementations of Newton's method, the chord method, and the secant method, respectively, for scalar equations. They have features in common with the more elaborate codes from the rest of the book. As codes for scalar equations, they do not need to pay attention to numerical linear algebra or worry about storing the iteration history.
The Newton's method code includes a line search. The secant and chord method codes do not, taking the warning in section 1.7.1 a bit too seriously.
The three codes require an initial iterate x, the function f, and relative and absolute residual tolerances tola and tolr. The output is the final result and (optionally) a history of the iteration. The history is kept in a two or four-column hist array. The first column is the iteration counter and the second the absolute value of the residual after that iteration. The third and fourth, for Newton's method only, are the number of times the line search reduced the step size and the Newton sequence { x n}. Of course, one need not keep the iteration number in the history and our codes for systems do not, but, for a simple example, doing so makes it as easy as possible to plot iteration statistics.
Each of the scalar codes has a limit of 100...