0% found this document useful (0 votes)
549 views

Gauss Jordan Method Octave

This document performs Gaussian elimination on a system of linear equations represented by the matrix A and vector b. It augments A and b into the matrix Ab, performs row operations to put Ab into reduced row echelon form, and then back-substitutes to solve for the unknown vector x. It compares the solution to those obtained using matrix division and the rref command.

Uploaded by

aqim azaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
549 views

Gauss Jordan Method Octave

This document performs Gaussian elimination on a system of linear equations represented by the matrix A and vector b. It augments A and b into the matrix Ab, performs row operations to put Ab into reduced row echelon form, and then back-substitutes to solve for the unknown vector x. It compares the solution to those obtained using matrix division and the rref command.

Uploaded by

aqim azaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

clc; clear; close;

A = [1 -3 1;
2 -8 8;
-6 3 -15];

b = [4; -2; 9];

% Augmenting matrix A and b to Ab


Ab = [ A b];

[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

% Back substitution to obtain the unknown


for s =1:m
Ab(s,:) = Ab(s,:)/Ab(s,s);
x(s) = Ab(s,n);
end

disp('Gauss Jordan Method')


Ab
x'

disp(' ')
disp(' Compare with symbolic solution')
x2 = A\b

disp(' ')
disp(' Using row -reduced echelon command')

solution =rref(Ab)

You might also like