function a = kershawtri_inverse ( n, x )

%*****************************************************************************80
%
%% KERSHAWTRI_INVERSE returns the inverse of the KERSHAWTRI matrix.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    05 November 2007
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the order of the matrix.
%
%    Input, real X((N+1)/2), defines the diagonal of the matrix.
%
%    Output, real A(N,N), the matrix.
%
  a = zeros ( n, n );

  nh = floor ( n / 2 );

  r(1:n+1) = 0.0;

  r(1) = 1.0;
  r(2) = - x(1);
  for i = 3 : n
    if ( i - 1 <= nh )
      xim1 = x(i-1);
    else
      xim1 = x(n+1-i+1);
    end
    r(i) = - ( xim1 * r(i-1) + r(i-2) );
  end
  r(n+1) = x(1) * r(n) + r(n-1);

  a(1:n,1:n) = 0.0;

  for i = 1 : n
    for j = 1 : i - 1
      a(i,j) = r(j) * r(n+1-i) / r(n+1);
    end
    a(i,i) = r(i) * r(n+1-i) / r(n+1);
    for j = i + 1 : n
      a(i,j) = r(i) * r(n+1-j) / r(n+1);
    end 
  end

  return
end
