%transition matrix Q of reduced first order chain of a higher order chain
%P is m-th order, n-dimensional transition tensor
function Q=rcmat(P)
s=size(P);
n=s(1);
m=length(s);
N1=n^(m-1);
N2=N1/n;
G=zeros(N2,N1);
for i=1:n
    j=(i-1)*N2+1:i*N2;
    G(:,j)=eye(N2);
end
Q=krprod(G,t2mat(P));
