% Rydd opp
clc
clear
format longG

% Migrasjonsmatrise og startvektor
P = [0.7 0.4 0.3; 0.1 0.6 0.1; 0.2 0 0.6];
x = [697010; 259958; 207595];       % Startvektor Wikipedia
xinf = [621100; 232913; 310550];    % Likevekt Wikipedia (forelesning 7)

% Ny startvektor
x = sum(x)*[0; 0; 1];  % Sett inn tre ikke-negative tall med sum 1
i = 0;

fprintf('År: %.0f \n\n',i)
fprintf('Oslo: %.0f \n',round(x(1)))
fprintf('Bergen: %.0f \n',round(x(2)))
fprintf('Trondheim: %.0f \n\n\n',round(x(3)))
pause(5)

% Let's go
while norm(round(x)-xinf)>0
  i = i+1;
  fprintf('År: %.0f \n\n',i)
  x = P*x;
  fprintf('Oslo: %.0f \n',round(x(1)))
  fprintf('Bergen: %.0f \n',round(x(2)))
  fprintf('Trondheim: %.0f \n\n\n',round(x(3)))
  pause(1) 
end
