%% Return Hitting Probabilities
% Consider this theoretical, right-stochastic transition matrix of a stochastic process.
% P = \left[ {\begin{array}{*{20}{c}}
% 1&0&0&0\\
% {1/2}&0&{1/2}&0\\
% 0&1/2&0&1/2\\
% 0&0&0&1
% \end{array}} \right].
% Create the Markov chain that is characterized by the transition matrix P.

P = [1 0 0 0; 1/2 0 1/2 0; 0 1/2 0 1/2; 0 0 0 1];
mc = dtmc(P);

% Plot a directed graph of the Markov chain. Visually identify the communicating class to which each state belongs by using node colors.

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

% Compute the hitting probabilities for state 1, beginning from each state in the Markov chain.

hp = hitprob(mc,1)

% Because state 1 is the target, the probability of state 1 reaching itself is 1.
% State 1 is reachable from states 2 and 3. Therefore, the hitting probabilities for state 1 beginning from those states are positive.
% Because state 1 is unreachable from state 4, state 4 has a hitting probability of 0 for state 1. Therefore, state 4 is a remote state with respect to state 1.
% Copyright 2019 The MathWorks, Inc.