creating a specific markov probability matrix

1 次查看(过去 30 天)
I am trying to consider a particle located on an 8x8 grid that start at the bottom left (at 1) with 64 being at the top right. It moves upwards or sideways (cannot move diagonally).
So the system has 64 states it can be in but i'm not sure how to construct a 64 by 64 matrix with probabilities for this specific grid.
Script Window:
%Creating a state vector s with 64 different states
s = zeros(1,64);
s(1,1) = 1;
%Creating a blank 64x64 probability matrix P
P = zeros(64,64);
%Use for loops to create a Markov probability Matrix.
for i=1:64
for j=1:64
P(i,j)=rand;
%I can only think of putting rand which generates numbers from a uniform distrubuion. I am not sure how to alter it to generate a matix specific to my 8x8 grid.
end
% making the sum for rows = to 1
P(i,:) = P(i,:)/sum(P(i,:));

采纳的回答

David Hill
David Hill 2020-9-26
If you use linear indexing (iaw Matlab), then the bottom left vertix of your graph is 8 and the top right vertix is 57. Then the probability matrix should be:
a=zeros(64);
for k=2:56
a(k,[k-1,k+8])=.5;
end
for k=58:64
a(k,k-1)=1;
end
for k=9:8:49
a(k,k-1)=0;
a(k,k+8)=1;
end
a(1,9)=1;
  3 个评论
David Hill
David Hill 2020-9-26
Going from the top left to the bottom right is the same thing mathematically. That would align with the linear indexing of the matrix (1 to 64).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Markov Chain Models 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by