function x=emeasure(h,w)
%this calculates the energy measure with respect to the harmonic
%function h of a cell whose word is w.
A0=[1 0 0 ; 2/5 2/5 1/5 ; 2/5 1/5 2/5];
A1=[2/5 2/5 1/5; 0 1 0; 1/5 2/5 2/5];
A2=[2/5 1/5 2/5; 1/5 2/5 2/5 ; 0 0 1];
A=[A0 A1 A2];

B=[1 0 0 ; 0 1 0; 0 0 1];

for n=1:1:max(size(w))
    B=A(:,3*w(n)+1:3*w(n)+3)*B;
end

v=B*h';

x=(5/3)^(max(size(w)))*((v(1)-v(2))^2+(v(1)-v(3))^2+(v(2)-v(3))^2);
