distribution.m
来自「markov matlab code, give a detail implet」· M 代码 · 共 39 行
M
39 行
% distribution.m computes and graphs the distribution of a Markov process% over time% Simply modify the initial distribution, lambda, jump matrix Q, and% state space SN = length(S); % number of statesstep = Tmax/100; % standard time incrementT = 0:step:Tmax; % vector of timesA = diag(lambda)*(Q-eye(size(Q))); % generatorPstep = expm(A*step); % this is P(step); matrix exponentialm = mu; % distribution at each stepdist = mu; % each row of dist is distn at a timefor t=1:(length(T)-1), m = m*Pstep; % step forward one time step dist = [dist; m]; % add another row to mendfor v=1:N, subplot(N,1,N-v+1); % one plot for each state plot(T,dist(:,v)); % plot probability over time axis([0 Tmax 0 1]); ylabel(['P(X_{t} = ' num2str(S(v)) ')']);endsubplot(N,1,1);title('Probabilities of being in states 1, 2, 3, ... over time');% Now compute the invariant/limiting distributioneta = invariant(expm(A));eta2 = invariant(Q)*diag(1./lambda);eta2 = eta2/sum(eta2); % normalize
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?