function cpb8_3_1d ( )
%
%  Reference:
%
%    Ward Cheney & David Kincaid
%    Numerical Mathematics and Computing, Fifth Edition
%    Brooks/Cole Publishing Company, 2003.
%
% Purpose: to test the eigenvalue command in Matlab
% on the family of tridiagonal matrices that come up in PDE,

% create a n x n matrix with tridiagonal
% structure and elements -1 2 -1 in each row. 
% We know a formula for the eigenvalues (NA3, p. 621). 
% Specifically, they are 2 -2 cos(j*pi/21). 
%
  fprintf ( '' )
  fprintf ( 'cpb8_3_1d' )

  n=5
  for i=1:n
    for j=1:n
      if abs(i-j)==0
        A(i,j)=2;
      elseif  abs(i-j)==1 
        A(i,j)=-1;
      else 
        A(i,j)=0;
      end
    end
  end

  A
  eig(A)
  for j=1:n
    lam(j)=2-2*cos(j*pi/(n+1))
  end

  return
end

