% Matlab program generating the Markov chain for sunny and cloudy days % % It also computes the answer to the problem % P = [.7 .3 .5 .5]; % Transition probability matrix % P3 = P^3; % Three-step transition probability matrix P3(1,1) % Answer to the exercise % % Generate this Markov chain % % X=0 is a cloudy day, X=1 is a sunny day % % Let's generate 100 days starting with a cloudy day % n=1; X(1) = 0; for day=2:100; U=rand; if X(n-1)==1; X(n)=(U < .7)*1 + (U >= .7)*0; else X(n)=(U < .5)*1 + (U >= .5)*0; end; end; X plot(X);