function out=find_chain1(text,length,alphabet)

out=zeros(29);

for i=1:(length-1)
    l1=text(i);
    l2=text(i+1);
    
    il1=0;
    il2=0;
    for j=1:29
        if l1==alphabet{j}
            il1=j;
        end
        if l2==alphabet{j}
            il2=j;
        end
    end
    if il1==0
        il1=randi([1,29]);
    end
    if il2==0
        il2=randi([1,29]);
    end
    
    out(il1,il2)=out(il1,il2)+1;
end

for k=1:29
    rsum=sum(out(k,:));
    if rsum>0
    out(k,:)=out(k,:)/rsum;
    end
end

    
        