function [ x, dp2, p1 ] = jacobi_root ( x, n, alpha, beta, b, c )

%*****************************************************************************80
%
%% jacobi_root() improves an approximate root of a Jacobi polynomial.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 October 2005
%
%  Author:
%
%    Original FORTRAN77 version by Arthur Stroud, Don Secrest.
%    This version by John Burkardt.
%
%  Reference:
%
%    Arthur Stroud, Don Secrest,
%    Gaussian Quadrature Formulas,
%    Prentice Hall, 1966,
%    LC: QA299.4G3S7.
%
%  Input:
%
%    real X, the approximate root.
%
%    integer N, the order of the polynomial to be computed.
%
%    real ALPHA, BETA, the exponents of (1-X) and
%    (1+X) in the quadrature rule.
%
%    real B(N), C(N), the recursion coefficients.
%
%  Output:
%
%    real X, the improved approximate root.
%
%    real DP2, the value of J'(N)(X).
%
%    real P1, the value of J(N-1)(X).
%
  maxstep = 10;

  for i = 1 : maxstep

    [ p2, dp2, p1 ] = jacobi_recur ( x, n, alpha, beta, b, c );

    d = p2 / dp2;
    x = x - d;

    if ( abs ( d ) <= eps * ( abs ( x ) + 1.0 ) )
      return
    end

  end

  return
end
