function A=MatEhrenfest(d)
    A=zeros(d+1,d+1)
    A(1,2)=1;
    for i=2:d
        A(i,i-1) = (i-1)/d;
        A(i,i+1) = 1-A(i,i-1);
    end
    A(d+1,d) = 1;
endfunction