Answer:
The MATLAB code will be:
close all;
clc;
clear all;
a = [20, 1, -2; 3, 20, -1; 2,-3, 20];
b = [17; -18; 25];
tol = 1e-6;
[M,N] = size(a);
if M~=N
error('A is not a square Matrix');
end
x = [0,0,0];
xx(1,:) = x;
n = 100;
error = 0.00001;
for k = 2:n
for i = 1:N
s = 0;
for j = 1:N
if j ~= i
s = s + a(i,j) * x(j);
end
end
x(i) = (1/a(i,i)*(b(i) - s));
end
xx(k,:) = x;kk = k;
Error = abs(max(xx(kk,:)- xx(k-1,:)))
if Error<error
break;
end
end
fprintf ('The roots of equation are: ')
x
fprintf ('The number of iterations are: ')
k
fprintf ('The error is: ')
Error
Step-by-step explanation: