A = [9 1 2 3; 1 7 2 3; 1 5 10 2; 1 2 3 9] B = [1;2;3;4]n = size(B,1);Tolerance = 10^-15;x = zeros([n,1]); %Initialization vector defaultly set as zero for ease of operation.
Norm_Values = []; % Storing first norm values.
K = 10;for k = 1:K T = x; % Storing previous x vector
for i = 1:n x(i) = (B(i) - A(i,[1:i-1 i+1:n])*x([1:i-1 i+1:n]))/A(i,i); endif (norm((x-T),1) < Tolerance) % Checking for convergence.
fprintf('GaussSeidel has converged in %d iterations.\n',k) breakelseif (k == K) K = K + 10 %Extending for loop
endend
Could somebody please help me with this problem?
If the norm does not go below tolerance within K iterations, I want to increase the number of iterations. But it is not working. It is only going up to 10 iterations.
(Above is just parts of the whole code.)
I don't want to use 'while' here because I would then have to do the 1st iteration outside the loop.
Help will be appreiciated.
Thanks in anticipation.
Best Answer