% testam metoda lui Jacobi pe matrici de dimensiune 3x3
% 
% ISA 2018-2019
% Referinte: exemplu din K. Atkinson, "An introduction to numerical analysis", 2nd edition.

A   = [10 3 1;2 -10 3;1 3 10];
b   = [14; -5; 14];
x0  = [0;0;0];
xstar = A\b; % valoarea exacta

% printam valorile pentru numerele de conditionare
fprintf('---------------------------------------------------\n');
fprintf(' k  | x1          | x2           | x3         | Raport   \n');
fprintf('---------------------------------------------------\n');

fprintf('0   |%8.6f     |%8.6f      | %8.6f   |           \n', x0(1),x0(2),x0(3));
nrIteratii = 6;
for i = 1:nrIteratii
  %xk = iteratie_Jacobi(A,b,x0);
  xk = iteratie_Jacobi_sol(A,b,x0);
  raport = norm(xstar-xk,inf)/norm(xstar-x0,inf);
  fprintf('%d   |%8.6f     |%8.6f      | %8.6f   | %8.6f        \n', i, xk(1),xk(2),xk(3),raport);
  x0 = xk;
end;