function A = dif2 ( n ) % % function A = dif2 ( n ) % % Discussion: % % DIF2 sets up the second difference matrix. % % Example: % % N = 5 % % A = [ -2 1 0 0 0; % 1 -2 1 0 0; % 0 1 -2 1 0; % 0 0 1 -2 1; % 0 0 0 1 -2 ] % % Modified: % % 14 February 2000 % % Author: % % John Burkardt % % Parameters: % % Input, integer N, the order of the matrix. N should be at least 2. % % Output, real A(N,N), the second difference matrix. % A = diag ( ones ( n-1, 1 ), -1 ) ... - 2.0 * diag ( ones ( n, 1 ), 0 ) ... + diag ( ones ( n-1, 1 ), +1 );