clear all
N = 20; % number of subintervals for (0, 1)
h = 1/N;
x = linspace(0, 1, N+1); % unifrom mesh with h=1/N
S = sparse(N+1, N+1); M = sparse(N+1, N+1); % initialize sparse matrices
for it = 1:N
    localindex = [it it+1];
    Sloc = [1/h -1/h; -1/h, 1/h]; % local stiffness matrix
    S(localindex, localindex) = S(localindex, localindex) + Sloc;
    Mloc = [1/3*h 1/6*h; 1/6*h 1/3*h];
    M(localindex, localindex) = M(localindex, localindex) + Mloc;
end
eigs(S(2:N, 2:N), M(2:N, 2:N), 6, 'sm')