function a = rectangle_adj_matrix ( row_num, col_num, n )

%*****************************************************************************80
%
%% rectangle_adj_matrix returns the RECTANGLE_ADJ matrix.
%
%  Discussion:
%
%    This is the adjacency matrix for a set of points arranged in
%    a ROW_NUM by COL_NUM grid.
%
%  Diagram:
%
%     1---5---9
%     |   |   |
%     2---6--10
%     |   |   |
%     3---7--11
%     |   |   |
%     4---8--12
%
%  Example:
%
%    ROW_NUM = 4
%    COL_NUM = 3
%
%    0  1  0  0    1  0  0  0    0  0  0  0
%    1  0  1  0    0  1  0  0    0  0  0  0
%    0  1  0  1    0  0  1  0    0  0  0  0
%    0  0  1  0    1  0  0  1    0  0  0  0
%
%    1  0  0  0    0  1  0  0    1  0  0  0
%    0  1  0  0    1  0  1  0    0  1  0  0
%    0  0  1  0    0  1  0  1    0  0  1  0
%    0  0  0  1    0  0  1  0    0  0  0  1
%
%    0  0  0  0    1  0  0  0    0  1  0  0
%    0  0  0  0    0  1  0  0    1  0  1  0
%    0  0  0  0    0  0  1  0    0  1  0  1
%    0  0  0  0    0  0  0  1    0  0  1  0
%
%  Properties:
%
%    A is integral, therefore det ( A ) is integral, and 
%    det ( A ) * inverse ( A ) is integral.
%
%    A is a zero/one matrix.
%
%    A is block tridiagonal.
%
%    A is an adjacency matrix.
%
%    A is related to the "LIGHTS_OUT" matrix.
%
%    A is symmetric: A' = A.
%
%    Because A is symmetric, it is normal.
%
%    Because A is normal, it is diagonalizable.
%
%    A is not diagonally dominant.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 July 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer ROW_NUM, COL_NUM, the number of rows and 
%    columns in the rectangle.
%
%    integer N, the order of A.
%
%  Output:
%
%    real A(N,N), the matrix.
%
  a = zeros ( n, n );

  for j_block = 1 : col_num

    j = ( j_block - 1 ) * row_num + 1;

    for i_block = 1 : col_num

      i = ( i_block - 1 ) * row_num + 1;

      if ( j_block == i_block )
        a(i:i+row_num-1,j:j+row_num-1) = line_adj_matrix ( row_num );
      elseif ( abs ( j_block - i_block ) == 1 )
        a(i:i+row_num-1,j:j+row_num-1) = eye ( row_num );
      else
        a(i:i+row_num-1,j:j+row_num-1) = zeros ( row_num, row_num );
      end

    end
  end

  return
end
