% TENTANROOTS  Use Newton to find 10 distinct solutions to  x = tan(x)

roots = [0];    % record the obvious root

% the function and its derivative
f  = @(x) x - tan(x);
df = @(x) 1 - sec(x).^2;

% loop over which one we are finding
for k=1:9
  x = (2*k+1 - 0.01) * pi/2;    % starting point just left of (odd)*pi/2
  % loop to do Newton iteration
  for j=1:10
    x = x - f(x) / df(x);
  end
  roots = [roots x];
end

roots = roots'
residuals = abs(f(roots))
