function []=hw6_2_12(n) E=zeros(n); for i=1:n for j=1:n if (i==j) E(i,j)=i*(n-i+1); elseif (j>i) E(i,j)=E(i,j-1)-i; else E(i,j)=E(j,i); end end end E=1/(n+1)*E; evals=sort(eig(E)); % avoid a for loop by making k a vector, the only catch is that you have % to make a vector of ones the same size then divide the two vectors element by % element using the ./ operator k=[1:n]'; lambda=sort(ones(n,1)./(2-2*cos(pi*k/(n+1)))); disp(' approx exact') disp([evals,lambda]) disp('distance between') disp(norm(lambda-evals))