function x = dif2_eigenvectors ( n )

%*****************************************************************************80
%
%% DIF2_EIGENVECTORS returns eigenvectors of the second difference matrix.
%
%  Discussion:
%
%    The eigenvalues are
%
%      LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))
%                = 4 SIN**2(I*PI/(2*N+2))
%
%    The corresponding eigenvector X(I) has entries
%
%       X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 June 2011
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Robert Gregory, David Karney,
%    Example 3.18,
%    A Collection of Matrices for Testing Computational Algorithms,
%    Wiley, New York, 1969, page 45, 
%    LC: QA263.G68.
%
%    Morris Newman, John Todd,
%    Example A8,
%    The evaluation of matrix inversion programs,
%    Journal of the Society for Industrial and Applied Mathematics,
%    Volume 6, Number 4, pages 466-476, 1958.
%
%    John Todd,
%    Example A8,
%    Basic Numerical Mathematics,
%    Volume 2: Numerical Algebra,
%    Academic Press, 1977, page 1.
%
%    Joan Westlake,
%    Test Matrix A15,
%    A Handbook of Numerical Matrix Inversion and Solution of Linear Equations,
%    John Wiley, 1968.
%
%  Input:
%
%    integer N, the order of the matrix.
%
%  Output:
%
%    real X(N,N), the eigenvectors of the matrix.
%
  x = zeros ( n, n );

  for i = 1 : n
    for j = 1 : n
      x(i,j) = sin ( ( i * j * pi ) / ( n + 1 ) );
    end
  end

  x(1:n,1:n) = x(1:n,1:n) * sqrt ( 2 / ( n + 1 ) );

  return
end
