Skip to content

Instantly share code, notes, and snippets.

@pureexe
Created October 19, 2017 15:05
Show Gist options
  • Select an option

  • Save pureexe/57d9478718867e70931aa568e2d78050 to your computer and use it in GitHub Desktop.

Select an option

Save pureexe/57d9478718867e70931aa568e2d78050 to your computer and use it in GitHub Desktop.
my gaussian_elimination
function X = gaussian_elimination(A,B)
N = length(A);
R = [A B];
for i = 1:N
[val,pos] = max(abs(R(i:N,i)));
R([pos+i-1 i],:) = R([i pos+i-1],:);
R(i,:) = R(i,:) / R(i,i);
for j = i+1:N
m = R(j,i)/R(i,i);
R(j,:) = R(j,:) - (m*R(i,:));
end
end
% backward subsitution
for i = N:-1:1
for j = i-1:-1:1
m = R(j,i)/R(i,i);
R(j,:) = R(j,:) - (m*R(i,:));
end
end
X = R(:,N+1);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment