function a = r8gb_dif2 ( m, n, ml, mu )

%*****************************************************************************80
%
%% R8GB_DIF2 sets up an R8GB second difference matrix.
%
%  Discussion:
%
%    The R8GB storage format is for an M by N banded matrix, with lower 
%    bandwidth ML and upper bandwidth MU.  Storage includes room for ML 
%    extra superdiagonals, which may be required to store nonzero entries 
%    generated during Gaussian elimination.
%
%    The original M by N matrix is "collapsed" downward, so that diagonals
%    become rows of the storage array, while columns are preserved.  The
%    collapsed array is logically 2*ML+MU+1 by N.  
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 June 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, the number of rows of the matrix.
%    M must be positive.
%
%    Input, integer N, the number of columns of the matrix.
%    N must be positive.
%
%    Input, integer ML, MU, the lower and upper bandwidths.
%    ML and MU must be nonnegative, and no greater than min(M,N)-1.
%
%    Output, real A(2*ML+MU+1,N), the R8GB matrix.
%
  a = zeros ( 2 * ml + mu + 1, n );

  for j = 1 : n

    for diag = 1 : 2 * ml + mu + 1

      i = diag + j - ml - mu - 1;

      if ( i == j )
        a(diag,j) = 2.0;
      elseif ( i == j - 1 || i == j + 1 )
        a(diag,j) = -1.0;
      end

    end
  end

  return
end
