Solving Nonlinear Equations with Newton's Method

One can examine the data in the it_hist array to estimate the q-order in the following way. If x n ? x* with q-order p, then one might hope that
for some K > 0. If that happens, then, as n ? ?,
and so
Hence, by looking at the it_hist array, we can estimate p.
This MATLAB code uses nsold.m to do exactly that for the functions f( x) = x ? cos( x) and f( x) = arctan( x).
% QORDER a program to estimate the q-order%% Set nsold for Newton's method, tight tolerances.%x0 = 1.0; parms = [40, 1, 0]; tol = [1.d-8, 1.d-8];[x,histc] = nsold(x0,'fcos', tol,parms);lhc=length(histc(:,2));%% Estimate the q-order.%qc = log(histc(2:lhc,1))./log(histc(1:lhc-1,1));%% Try it again with f(x) = atan(x).%[x,histt] = nsold(x0,'atan',tol,parms);lht=length(histt(:,2));%% Estimate the q-order.%qt = log(histt(2:lht,1))./log(histt(1:lht-1,1));
If we examine the last few elements of the arrays qc and qt we should see a good estimate of the q-order until the iteration stagnates. The last three elements of qc are 3.8, 2.4, and 2.1, as close to the quadratic convergence q-order of 2 as we're likely to see. For f( x) = arctan( x), the residual at the end is 2 10 ?24, and the final four elements of qt are 3.7, 3.2, 3.2, and 3.1. In fact, the correct q-order for this problem is 3. Why?