for j=1:n-1
for i=j+1:n
if abs(a(j,j))< eps; error('zero pivot encountered'); end
mult = a(i,j)/a(j,j);
for k = j+1:n
a(i,k) = a(i,k) - mult*a(j,k);
end
b(i) = b(i) - mult*b(j);
end
end
for i = n:-1:1
for j = i+1:n
b(i) = b(i) - a(i,j)*x(j);
end
x(i) = b(i)/a(i,i);
end
Define the coefficient matrix a=[2 -2 -1;4 1 -2;-2 1 -1],
b=[-2;1;-3] and apply the preceding Matlab program. The result
is \(x=[1, 1, 2]\). 1 (b) Proceed as in (a); the result of the Matlab program is \(x=[1, 1, 1]\).
1 (c) Proceed as in (a); the result is \(x=[-1, 3, 2]\).