function a = r8ncf_dif2 ( m, n, nz_num, rowcol )

%*****************************************************************************80
%
%% R8NCF_DIF2 sets up an R8NCF second difference matrix.
%
%  Discussion:
%
%    The R8NCF storage format stores NZ_NUM, the number of nonzeros, 
%    a real array containing the nonzero values, a 2 by NZ_NUM integer 
%    array storing the row and column of each nonzero entry.
%
%    The R8NCF format is used by NSPCG.  NSPCG requires that the information
%    for the diagonal entries of the matrix must come first.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    20 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, N, the number of rows and columns in
%    the matrix.
%
%    Input, integer NZ_NUM, the number of nonzero entries.
%
%    Input, integer ROWCOL(2,NZ_NUM), the coordinates of 
%    the nonzero entries.
%
%    Output, real A(NZ_NUM), the matrix.
%
  a = zeros ( nz_num, 1 );

  for k = 1 : nz_num
    i = rowcol(1,k);
    j = rowcol(2,k);
    if ( j == i - 1 )
      a(k) = -1.0;
    elseif ( j == i )
      a(k) = 2.0;
    elseif ( j == i + 1 )
      a(k) = -1.0;
    end
  end

  return
end

