markov chain matlab,Plot Markov chain simulations

Consider this theoretical, right-stochastic transition matrix of a stochastic process.

P=[001/21/41/400001/302/300000001/32/3000001/21/2000003/41/41/21/2000001/43/400000].

Create the Markov chain that is characterized by the transition matrix P.

P = [ 0 0 1/2 1/4 1/4 0 0 ;

0 0 1/3 0 2/3 0 0 ;

0 0 0 0 0 1/3 2/3;

0 0 0 0 0 1/2 1/2;

0 0 0 0 0 3/4 1/4;

1/2 1/2 0 0 0 0 0 ;

1/4 3/4 0 0 0 0 0 ];

mc = dtmc(P);

Generate 100 20-step random walks starting from state 1.

rng(1); % For reproducibility

numSteps = 20;

X0 = zeros(mc.NumStates,1);

X0(1) = 100; % 100 random walks starting from state 1 only

X = simulate(mc,numSteps,'X0',X0);

X is a 21-by-100 matrix.

Visualize the proportion of times that states transition to other states for all random walks by using a heatmap.

figure;

simplot(mc,X,'Type','transitions');

a2c06cd21feffdc0851c6e99feab1bbb.png

Rows and columns of the heatmap correspond to state numbers.

Compare the realized transition matrix to the theoretical transition matrix by using a heatmap.

figure;

imagesc(mc.P);

colormap(jet);

axis square;

colorbar;

e89bd6853b874d9daa04f1c2c9a8369d.png

The realized and theoretical transition matrices are similar.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值