Gauss Jordan Method Octave
Gauss Jordan Method Octave
A = [1 -3 1;
2 -8 8;
-6 3 -15];
[m,n] = size(Ab);
% Performing pivoting
for j =1:m-1
for z =2:m
if Ab(j,j) == 0
t = Ab(1,:); %
Ab(1,:) = Ab(z,:); %
Ab(z,:) = t;
end
end
% Convert the element below the pivot to zero
for i = j+1:m
Ab(i,:) = Ab(i,:) - Ab(j,:)*(Ab(i,j)/Ab(j,j));
Ab
end
end
for j = m:-1:2
for i = j-1:-1:1
Ab(i,:) = Ab(i,:) - Ab(j,:)*(Ab(i,j)/Ab(j,j));
end
end
disp(' ')
disp(' Compare with symbolic solution')
x2 = A\b
disp(' ')
disp(' Using row -reduced echelon command')
solution =rref(Ab)