马尔科夫链matlab代码.docx
马尔科夫链%ThisisprogrammedforcalculatingtheMarkov-chainstatetransferprobability(Firstorder)matrice!%Thisprogramisbasedon4thresholds,thatis,thetransferprobabilitymatriceis4x4.%Followthenotestoconducttheprocessing.%CodedbyEOS%NanchangChinaclearclc%A=csvread(,widetype.csv,)j%ormanuallydefinevia"A=".A=%Aistheinformationmatrixwhichmustbeadjustedtowide-type,i(section)-j(time)%OUt=ZeroS(4,4);%InitiaIiZetheIransferingprobability(Firstorder)matricerl,r2,r3=deal(1.009,1.285,1.7256);%!Definethestatethresholdvaluemanually.flag=0;trans=zeros(4,4);sO=zeros(1,4);epro=zeros(10,4);fori=l:10ifA(i,l)<rls(l,l)=s(l,l)+l;elseifA(i,l)>=rl&&A(i,1)<r2s(l,2)=s(1,2)+1;elseifA(i,l)>=r2&&A(iJ)<r3s(l,3)=s(1,3)+1;elses(l,4)=s(1,4)+1;endendfori=l:10fort=l:14ifA(i,t)<rlepro(i,l)=epro(i,l)+l;elseifA(i,t)>=rl&&A(i,t)<r2epro(i,2)=epro(i,2)+1;elseifA(i,t)>=r2&&A(i,t)<r3epro(i,3)=epro(i,3)+1;elseepro(i,4)=epro(i,4)÷1;endendendforS=I:10fort=l:13%withinaninitialstate1ifA(SJ)<rlflag=l;ifA(s,t+l)<rltrans(flag,1)=trans(flag,1)+1;elseifA(s,t+l)>=rl&&A(s,t+l)<r2trans(flag,2)=trans(flag,2)+l;elseifA(s,t+1)>=r2&&A(s,t+l)<r3trans(flag,3)=trans(flag,3)+1;elsetrans(flag,4)=trans(flag,4)+1;end%withinaninitialstate2elseifA(s,t)>=rl&&A(s,t)<r2flag=2;ifA(s,t+l)<rltrans(flag,1)=trans(flag,1)+1;elseifA(s,t+l)>=rl&&A(s,t+l)<r2trans(flag,2)=trans(flag,2)+l;elseifA(s,t+1)>=r2&&A(s,t+l)<r3trans(flag,3)=trans(flag,3)+1;elsetrans(ag,4)=trans(ag,4)+1;end%withinaninitialstate3elseifA(s,t)>=r2&&A(s,t)<r3flag=3;ifA(s,t+l)<rltrans(flag,1)=trans(flag,1)+1;elseifA(s,t+)>=rl&&A(s,t+1)<r2trans(flag,2)=trans(flag,2)+1;elseifA(s,t+D>=r2&&A(s,t+l)<r3trans(flag,3)=trans(flag,3)+1;elsetrans(ag,4)=trans(ag,4)+1;end%withinaninitialstate4elseflag=4;ifA(s,t+l)<rltrans(flag,1)=trans(flag,1)+1;elseifA(s,t+)>=rl&&A(s,t+1)<r2trans(flag,2)=trans(flag,2)+1;elseifA(s,t+D>=r2&&A(s,t+l)<r3trans(flag,3)=trans(flag,3)+1;elsetrans(ag,4)=trans(ag,4)+1;endendendend%CalculatetheMarkovstateCransferingprobabilitymatricefori=l:4forj=1:4out(i,j)=trans(i,j)sum(trans(i);endenddisp(,MarkovstateIransferingprobabilitymatriceis:')disp(out)