Вы находитесь на странице: 1из 3

Leonard Angelo N.

Sabellina III September 25, 2017

11416556

Meeting 2

A = [12 3 -5 ; 1 5 3 ; 3 7 13];% coefficients matrix

C = [1 ; 28 ; 76];% constants vector

n = length(C);

X = zeros(n,1);

Error_eval = ones(n,1);

%% Check if the matrix A is diagonally dominant

for i = 1:n

j = 1:n;

j(i) = [];

B = abs(A(i,j));

Check(i) = abs(A(i,i)) - sum(B); % Is the diagonal value greater than the remaining row values
combined?

if Check(i) < 0

fprintf('The matrix is not strictly diagonally dominant at row %2i\n\n',i)

end

end

%% 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

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

GaussSeidelTable = [1:iteration;Xsolution]'

MaTrIx = [A X C]

GaussSeidelTable =

1.0000 0.0833 5.5833 2.8205

2.0000 -0.1373 3.9351 3.7589

3.0000 0.6658 3.2115 3.9632

4.0000 0.9318 3.0357 3.9965

5.0000 0.9896 3.0042 4.0002

6.0000 0.9990 3.0001 4.0002

7.0000 1.0000 2.9999 4.0000


8.0000 1.0000 3.0000 4.0000

MaTrIx =

12.0000 3.0000 -5.0000 1.0000 1.0000

1.0000 5.0000 3.0000 3.0000 28.0000

3.0000 7.0000 13.0000 4.0000 76.0000

Вам также может понравиться