function [E] = Energy(Matrix)
%The input Matrix is a Laplacian matrix and the output is a vector E where
%each entry corresponds to an energy of some eigenfunction of the input matrix.
[V,D]=eig(Matrix);
[m,n]=size(Matrix);
%The column vectors of matrix V are the eigenfunctions of the input matrix.
%The matrix D is the diagonal matrix of the eigenvalues of the input
%matrix.
%From left to right, the columns of D contain the spectra of the
%input matrix in increasing order.
%Each column of V is the eigenfunction of the eigenvalue in the
%corresponding column of D.
E=zeros(m,1);
%This vector will store the energies of the eigenfunctions in the order
%they are listed in V.
%This block of code calculates the energies.
for i=1:m
for j=1:m-1
for k = j+1:m
if Matrix(j,k)==0;
E(i)=E(i);
else
E(i) = E(i) + (V(k,i)-V(j,i))^2;
end
end
end
end
end