function Q=enermat(N,L,DM,k2)
% build the energy measure matrix for OSS
% 	inputs: 
% N: number of inner points
% L: domain height
% DM: differentiation matrices
% k2=alpha^+beta^2 
% 	output:
% Q: energy measure matrix for collocation points

%%%% integration weights
n=0:1:N+1;
j=0:1:N+1;
b=ones(1,N+2);
b([1 N+2])=0.5;
c=2*b;
b=b/(N+1);
S=cos(n(3:N+2)'*j*(pi/(N+1)));
IWT=L/2*diag(b.*[(2+(c(3:N+2).*((1+(-1).^n(3:N+2))./(1-n(3:N+2).^2)))*S)]);

%%%% build energy measure matrix
QvT=0.125*(DM(:,:,1)'*IWT*DM(:,:,1)/k2+IWT); % for v
QetaT=0.125* IWT/k2; % for eta
Q=[QvT(2:N+1,2:N+1),zeros(N,N);zeros(N,N),QetaT(2:N+1,2:N+1)];
