% JACOBITEST : script to test Jacobi iteration for temperature problem
%              begin with:  load roomtemp (or otherwise set A and b)

[n,n] = size(A);
d = diag(A);
D = diag(d);
C = A - D;

% Initial guess: x = 0
x = zeros(n,1);

% Iterate
niters = 20000;
resvec = zeros(1,niters);
for k = 1 : niters
    x = (b - C*x) ./ d;
    res = norm(A*x-b);
    resvec(k) = res;
%     if mod(k,100) == 0
%         surfc(reshape(x,100,100))
%         title(sprintf('Iteration %d:  residual = %g, maximum x = %g',...
%             k,res,max(x)));
%         pause(.1);
%     end
end;