function a = pascal2_matrix ( n )

%*****************************************************************************80
%
%% pascal2_matrix() returns the PASCAL2 matrix.
%
%  Formula:
%
%    If ( I = 1 or J = 1 )
%      A(I,J) = 1
%    else
%      A(I,J) = A(I-1,J) + A(I,J-1)
%
%  Example:
%
%    N = 5
%
%    1 1  1  1  1
%    1 2  3  4  5
%    1 3  6 10 15
%    1 4 10 20 35
%    1 5 15 35 70
%
%  Properties:
%
%    A is a "chunk" of the Pascal binomial combinatorial triangle.
%
%    A is positive definite.
%
%    A is symmetric: A' = A.
%
%    A is symmetric positive definite.
%
%    Because A is symmetric, it is normal.
%
%    Because A is normal, it is diagonalizable.
%
%    A is integral, therefore det ( A ) is integral, and 
%    det ( A ) * inverse ( A ) is integral.
%
%    A is nonsingular.
%
%    A is not diagonally dominant.
%
%    det ( A ) = 1.
%
%    A is unimodular.
%
%    Eigenvalues of A occur in reciprocal pairs.
%
%    The condition number of A is approximately 16^N / ( N*PI ).
%
%    The elements of the inverse of A are integers.
%
%    A(I,J) = (I+J-2)! / ( (I-1)! * (J-1)! )
%
%    The Cholesky factor of A is a lower triangular matrix R,
%    such that A = R * R'.  The matrix R is a Pascal
%    matrix of the type generated by subroutine PASCAL.  In other
%    words, PASCAL2 = PASCAL * PASCAL'.
%
%    If the (N,N) entry of A is decreased by 1, the matrix is singular.
%
%    Gregory and Karney consider a generalization of this matrix as
%    their test matrix 3.7, in which every element is multiplied by a
%    nonzero constant K.  They point out that if K is the reciprocal of
%    an integer, then the inverse matrix has all integer entries.
%
%    The family of matrices is nested as a function of N.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 October 2007
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Robert Brawer, Magnus Pirovino,
%    The linear algebra of the Pascal matrix,
%    Linear Algebra and Applications,
%    Volume 174, 1992, pages 13-23.
%
%    Robert Gregory, David Karney,
%    Example 3.7,
%    A Collection of Matrices for Testing Computational Algorithms,
%    Wiley, 1969, page 32, 
%    LC: QA263.G68.
%
%    Nicholas Higham,
%    Accuracy and Stability of Numerical Algorithms,
%    Society for Industrial and Applied Mathematics,
%    Philadelphia, PA, USA, 1996; section 26.4.
%
%    Sam Karlin,
%    Total Positivity, Volume 1,
%    Stanford University Press, 1968.
%
%    Morris Newman, John Todd,
%    The evaluation of matrix inversion programs,
%    Journal of the Society for Industrial and Applied Mathematics,
%    Volume 6, Number 4, pages 466-476, 1958.
%
%    Heinz Rutishauser,
%    On test matrices,
%    Programmation en Mathematiques Numeriques,
%    Centre National de la Recherche Scientifique,
%    1966, pages 349-365.
%
%    John Todd,
%    Basic Numerical Mathematics, Vol. 2: Numerical Algebra,
%    Academic Press, 1977, page 172.
%
%    HW Turnbull,
%    The Theory of Determinants, Matrices, and Invariants,
%    Blackie, 1929.
%
%  Input:
%
%    integer N, the order of A.
%
%  Output:
%
%    real A(N,N), the matrix.
%
  a = zeros ( n, n );

  for i = 1 : n
    for j = 1 : n

      if ( i == 1 )
        a(i,j) = 1.0;
      elseif ( j == 1 )
        a(i,j) = 1.0;
      else
        a(i,j) = a(i,j-1) + a(i-1,j);
      end

    end
  end

  return
end
