process.m

来自「markov matlab code, give a detail implet」· M 代码 · 共 28 行

M
28
字号
% process.m simulates a Markov process on a state space S, using initial% distribution mu, sojourn parameters lambda, and jump matrix Q.clear T;clear x;             % clear out previous valuesT(1) = 0;            % start times at 0x(1) = rando(mu);    % generate first x value (time 0, not time 1)i    = 1;while T(i) < Tmax,  T(i+1) = T(i)  - log(rand)/lambda(x(i));  % generate exponential rv                                % occasionally causes errors; ignore them  x(i+1) = rando(Q(x(i),:));    % use Q to make state transitions  i=i+1;endcla;hold onfor i=1:(length(T)-1),  plot([T(i) T(i+1)], [S(x(i)) S(x(i))]);end%stairs(T,S(x));                 % sometime this is more appropriateaxis([0 Tmax 0 (length(mu)+1)]);xlabel('Time');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?