% % evec.m % % compute and display the first K eigenvectors of the % the N-by-N second difference matrix for a cell of length ell % function evec(ell,N,K) dx = ell/N; x = dx/2:dx:ell-dx/2; S = (2*eye(N)-diag(ones(N-1,1),1)-diag(ones(N-1,1),-1))/dx/dx; S(1,1) = 1/dx/dx; S(N,N) = 1/dx/dx; [Q,Z] = eig(S); z = diag(Z); z(1:K) stairs(x,Q(:,1:K)) a = axis; xlabel('x (cm)','fontsize',16) ylabel('eigenvector','fontsize',16) axis([0 pi a(3) a(4)])