?? generalchain.m
字號:
% generalchain.m simulates a Markov chain with a general state space given an% initial distribution and a transition matrix.% Program to simulate a Markov chain% You might want to set up another .m file that defines S, mu, and P% The program assumes that the states are labeled 1, 2, ...% Below is a sample, which you can use by uncommenting these lines% S=[0 1 2]; % state space% mu=[1 0 0]; % initial distribution% P=[[.6 .3 .1]; [.3 .3 .4]; [.4 .1 .5]]; % transition matrixn=200; % number of time steps to takex=zeros(1,n+1); % clear out any old valuest=0:n; % time indicesx(1)=rando(mu); % generate first x value (time 0, not time 1)for i=1:n, x(i+1) = rando(P(x(i),:));endplot(t, S(x));axis([0 n S(1) S(length(S))]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -