《用MATLAB仿真markov链程序》由会员分享,可在线阅读,更多相关《用MATLAB仿真markov链程序(2页珍藏版)》请在人人文库网上搜索。
1、用MATLAB仿真markov链程序说明:我们知道markov链由一个状态跳到下个状态的和为1,而MATLAB中,rand函数可以等概率产生区间0,1之间的数。例如从状态1跳到状态1,2,3的概率分别为0.3、0.4、0.4。所以我们可以使用rand(1)0.7来表示概率0.3、0.4、0.4。例子:假设有三个状态1、2、3,概率转移矩阵如下P=01/21/21/201/21/21/20假设初始状态为1,仿真程序如下clear allclcA=1;x=1:101;for i=1:1:100a=rand(1);if a0.5&A(i)=1A=A,3;endif a0.5&A(i)=2A=A,3;。
2、endif a0.5&A(i)=3A=A,2;endendA其中一次的结果如下A =Columns 1 through 131 2 3 1 3 1 3 1 3 2 3 1 2Columns 14 through 261 3 1 3 2 3 1 2 1 3 1 3 2Columns 27 through 393 1 2 1 3 1 3 1 2 1 2 3 2Columns 40 through 523 1 3 2 1 3 1 2 1 2 1 2 1Columns 53 through 652 3 2 1 2 1 3 1 2 3 1 2 1Columns 66 through 782 1 3 2 3 1 2 1 3 1 2 1 3Columns 79 through 912 3 1 3 1 3 1 3 1 2 3 2 1Columns 92 through 1013 2 1 2 1 2 3 2 3 2。