%ex04

% a)
  % A - A
  pAA = 0.4^2;
  % A - B
  pAB = (1-0.4)^2;
  % A - C
  pAC = 0.4*(1-0.4);
  % A - D
  pAD = 0.4*(1-0.4);


  % B - A
  pBA = 0;
  % B - B
  pBB = 0;
  % B - C
  pBC = 0;
  % B - D
  pBD = 1;

  % C - A
  pCA = 0;
  % C - B
  pCB = 0;
  % C - C
  pCC = 0;
  % C - D
  pCD = 1;

  % D - A
  pDA = 0.6^2;
  % D - B
  pDB = 0.6*(1-0.6);
  % D - C
  pDC = 0.6*(1-0.6);
  % D - D
  pDD = (1-0.6)^2;


  T = [pAA pBA pCA pDA ; pAB pBB pCB pDB ; pAC pBC pCC pDC ; pAD pBD pCD pDD]

  %b

 x0 = [1 ; 0 ; 0 ; 0];

 x5 = T^5*x0;

  fprintf("Probabilidade de, comecando em A, apos 5 transicoes, chegar a: \n " + ...
      "A= %f\n B= %f\n C= %f\n D= %f\n",x5(1),x5(2),x5(3),x5(4))

