Skip to content

Instantly share code, notes, and snippets.

@TRex22
Created May 12, 2015 07:49
Show Gist options
  • Save TRex22/8d9ee813575d0497fa55 to your computer and use it in GitHub Desktop.
Save TRex22/8d9ee813575d0497fa55 to your computer and use it in GitHub Desktop.
Gauss Jordan
%Guassian_Elimination with jordan method
%This is my code Jason Chalom 711985
%[r, c] = size(A);
%A = [2 -1 2 1; 1 1 2 1; 2 1 5 3];
% a has both a matrix and b vector
function [output] = Guassian_Elimination_Jordan (a, b)
%do gauss first
a= horzcat(a,b);
[r,c] = size(a);
for j = 1:r-1
for i = j+1:r
a(i,:) = a(i,:) - a(i,j)/a(j,j)*a(j,:);
end
end
%jordan
for j = r:-1 : r-1
for i = 1 : j-1
a(i,:) = a(i,:) - a(i,j)/a(j,j)*a(j,:);
end
end
%output
for i=1:r
output(i, :)=a(i,end)./a(i,i);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment