《马尔科夫链matlab代码.docx》由会员分享,可在线阅读,更多相关《马尔科夫链matlab代码.docx(3页珍藏版)》请在课桌文档上搜索。
1、马尔科夫链%ThisisprogrammedforcalculatingtheMarkov-chainstatetransferprobability(Firstorder)matrice!%Thisprogramisbasedon4thresholds,thatis,thetransferprobabilitymatriceis4x4.%Followthenotestoconducttheprocessing.%CodedbyEOS%NanchangChinaclearclc%A=csvread(,widetype.csv,)j%ormanuallydefineviaA=.A=%Aisthe
2、informationmatrixwhichmustbeadjustedtowide-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)=rl&A(i,1)=r2&A(iJ
3、)r3s(l,3)=s(1,3)+1;elses(l,4)=s(1,4)+1;endendfori=l:10fort=l:14ifA(i,t)=rl&A(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)=rl&A(s,t+l)=r2&A(s,t+l)=rl&A(s,t)r2flag=2;ifA(s,t+l)=rl&A(s,t+l)=r2&A(s,t+l)=r2&A(s,
4、t)r3flag=3;ifA(s,t+l)=rl&A(s,t+1)=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)=rl&A(s,t+1)=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)