Effacer les filtres
Effacer les filtres

Need help in making a Markov Probability Matrix

2 vues (au cours des 30 derniers jours)
Ashwin Chettiar
Ashwin Chettiar le 28 Août 2020
Consider a new particle, located on an 8 × 8 grid. The particle begins in the bottom left-hand corner, which is given the label square 1. The particle can move horizontally or vertically randomly. This system has 64 different states, corresponding to the particle being in each of the 64 squares. Use for loops in Matlab to efficiently create the Markov transition matrix (you are not expected to create a 64 × 64 matrix by hand!).
So far, I have been able to create the state vector and a blank probability matrix. The problem that I am having is that I do not understand how to use for loops to generate a Markov matrix with the constraints that I have been given.
My code so far:
%Create a state vector s with 64 different states
s = zeros(1,64);
s(1,1) = 1;
%Create a blank 64x64 probability matrix P
P = zeros(64,64);
%Use for loops to create the Markov Probability Matrix

Réponse acceptée

Pratyush Roy
Pratyush Roy le 31 Août 2020
Assuming random values for the Markov probability matrix, the following snippet might be helpful for defining a Markov Probability Matrix using for loops:
%Create a state vector s with 64 different states
s = zeros(1,64);
s(1,1) = 1;
%Create a blank 64x64 probability matrix P
P = zeros(64,64);
%Use for loops to create the Markov probability Matrix.
for i=1:64
for j=1:64
P(i,j)=rand; %Generates a random number from a uniform distribution in range(0,1)
end
P(i,:) = P(i,:)/sum(P(i,:)); % This forces the sum across columns to be unity
end
You can also refer to the following documentation for defining a Markov Probability Matrix without using for loops:
  3 commentaires
Jeremy Jenkins
Jeremy Jenkins le 5 Sep 2020
Hi Ashwin, I was wondering how you varied your method to account for the specific probabilities?
Ashwin Chettiar
Ashwin Chettiar le 6 Sep 2020
Modifié(e) : Ashwin Chettiar le 6 Sep 2020
By making a very specific probability matrix using for loops.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by