clear;clc format compact %% Read or Input any square Matrix A = [10 5 3 1;2 10 -4 -3; 1 3 -10 5; -5 1 3 10];% coefficients matrix C = [6; 5; 2; 3];% constants vector n = length(C); X = zeros(n,1); Error_eval = ones(n,1); alpha=zeros(n,1); %% Verificar se a matrix A satisfaz o critério de linhas for i=1:n j = 1:n; j(i) = []; B = abs(A(i,j))/abs(A(i,i)); alpha(i) = sum(B); Check = max(alpha(:)); if Check > 1 error('A matrix não satisfaz o Critério de Linhas') end end Alpha = max(alpha(i)) %% Start the Iterative method iteration = 0; while max(Error_eval) > 0.001 iteration = iteration + 1; Z = X; % save current values to calculate error later for i = 1:n for j = 1:n; % define an array of the coefficients' elements X(j) = (C(j) - A(j,1:j-1)*Z(1:j-1)-A(j,j+1:n)*Z(j+1:n)) / A(j,j); end end Xsolution(:,iteration) = X; Error_eval = sqrt((X - Z).^2); end %% Display Results GaussJacobi = [1:iteration;Xsolution]' %MaTrIx = [A X C]