clear;clc format short %% Read or Input any square Matrix A = [10 2 0 1; 5 10 1 0; 0 1 4 1; 0 0 -1 6]% coefficients matrix C = [10; 2; 8; 3];% constants vector n = length(C); X = zeros(n,1); beta=zeros(n,1); Error_eval = ones(n,1); %% Verificar se a matrix A satisfaz o critério de Sassenfeld for i=1:n for j=1:i-1 beta(i)=beta(i)+abs(A(i,j))/abs(A(i,i))*beta(j); end for j=i+1:n beta(i)=beta(i)+abs(A(i,j))/abs(A(i,i)); end Check = max(beta(:)); if Check > 1 error('A matrix não satisfaz o Critério de Sassenfeld') end end %% Start the Iterative method iteration = 0; while max(Error_eval) > 0.0001 iteration = iteration + 1; Z = X; % save current values to calculate error later for i = 1:n j = 1:n; % define an array of the coefficients' elements j(i) = []; % eliminate the unknow's coefficient from the remaining coefficients Xtemp = X; % copy the unknows to a new variable Xtemp(i) = []; % eliminate the unknown under question from the set of values X(i) = (C(i) - sum(A(i,j) * Xtemp)) / A(i,i); end Xsolution(:,iteration) = X; Error_eval = sqrt((X - Z).^2); end %% Display Results GaussSeidel = [1:iteration;Xsolution]' %MaTrIx = [A X C]