function y=plotder(w)

% given a word w, this will compute the derivative measures with the
% derivative matrices. (See more comments below).

A0=[1 2/9 2/9 ; 0 2/9 -1/9; 0 -1/9 2/9];
A1=[2/9 0 -1/9; 2/9 1 2/9; -1/9 0 2/9];
A2=[2/9 -1/9 0 ; -1/9 2/9 0; 2/9 2/9 1];
A=[A0 A1 A2];


x=[1 0 0 ; 0 1 0; 0 0 1];
for m=1:1:w
    x1=[];
    for n=1:1:max(size(x))/3
        x1=[x1 ; A0*x(3*n-2:3*n,:)];
    end
    x2=[];
    for n=1:1:max(size(x))/3
        x2=[x2 ; A1*x(3*n-2:3*n,:)];
    end
    x3=[];
    for n=1:1:max(size(x))/3
        x3=[x3 ; A2*x(3*n-2:3*n,:)];
    end
    x=[x1 ; x2 ; x3];
end

y=[];
for n=1:1:max(size(x))/3
    y=[y ; [1 0 0]*x(3*n-2:3*n,:)*[1 ; 1 ; 1]];
    %note that you can change the above vector from [1 0 0] to [0 1 0] or
    %[0 0 1] to get the other two measures, being the derivatives of the
    %edges of the Y graph after restricting from a level |w| graph after
    %perturbing a cell w by t (see PDF file on homepage about this).
    %Putting [1 1 1] in gives the sum of these measures, which is 2/3 of
    %the Kusuoka measure (again, see the PDF file).
end
y=(3/5)^w*y;

q0=[1/2 1]; q1=[0 0]; q2=[1 0];
v=[1/2 1/2];
for i=1:1:w
    v=[wordm(v,q0); wordm(v,q1); wordm(v,q2)];
end

hold off
plot3(v(:,1),v(:,2),y, '.')
hold on
%{
sg=SG(w);
for m=1:1:3^(w)
    hold on
    plot3([sg(3*m-2:3*m,1); sg(3*m-2,1)],[sg(3*m-2:3*m,2) ;sg(3*m-2,2)],[0 0 0 0], 'color','y')
end
%}

%{
M=wordmatrix(m);
x=[];
for j=1:1:3^m
    x=[x ; [1 1 1]*derword(M(j,:),[1 1 1])];
end

v=net(m);



y=SG(m);

hold off
plot3(v(:,1),v(:,2),x,'.')
%}
