%% Fix Specific Transition Probabilities
% Generate a Markov chain characterized by a partially random transition matrix. Also, decrease the number of feasible transitions.
% Generate a 4-by-4 matrix of missing (NaN) values, which represents the transition matrix.

P = NaN(4);

%
% Specify that state 1 transitions to state 2 with probability 0.5, and that state 2 transitions to state 1 with the same probability.

P(1,2) = 0.5;
P(2,1) = 0.5;

%
% Create a Markov chain characterized by the partially known transition matrix. For the remaining unknown transition probabilities,  specify that five transitions are infeasible for 5 random transitions.  An infeasible transition is a transition whose probability of occurring is zero.

rng(1); % For reproducibility
mc = mcmix(4,'Fix',P,'Zeros',5);

% mc is a dtmc object. With the exception of the fixed elements (1,2) and (2,1) of the transition matrix, mcmix places five zeros in random locations and generates random probabilities for the remaining nine locations. The probabilities in a particular row sum to 1.
%
% Display the transition matrix and plot a digraph of the Markov chain. In the plot, indicate transition probabilities by specifying edge colors.

P = mc.P

figure;
graphplot(mc,'ColorEdges',true);

% Copyright 2012 The MathWorks, Inc.