function [x,i]=Root(n,tol,maxit)
% Finds using the Newton method the only root x of
% F(x)=tan(x)-sqrt(x) in (n*pi,n*pi+pi/2) 
% Exit if abs. error of x does not exceed tol
% maxit is the maximal number of iterations allowed
% 
% Initial approximation for Newton: F(x0) should be positive
x=atan(sqrt((n+.5)*pi))+n*pi;
% m should be less than min(|F'(x)|) in (x,n*pi+pi/2)
% m is used for error estimation
m=n*pi;  if n==0, m=.25;end
% Newton iterations
for i=1:maxit
    F=tan(x)-sqrt(x); % remains positive
    if F/m < tol, return; end
    dF=1/cos(x)^2-1/(2*sqrt(x));
    x=x-F/dF;
end
% should never come here
error('No convergence!')
