You are on page 1of 1

function [a] = Assignment_2_numerical_method (a)

% Gaussian Elimination code


% a=[1 1 1 0 0 0; 0 -1 0 1 -1 0; -1 0 0 0 0 1; 0 0 0 0 1 -1; -20 5 0 0 -5
-2; 0 -0.025 0.05 0 -0.125 0];
N = length (a);
tol = 1e-6;

% For each pivot along the diagonal


for ii = 1:N-1
% for each row under the pivot
for jj =ii+1:N
if abs (a(jj,ii))> tol
% factor is ratio pivot velue
% and entry below pivot in row jj
fac=a(ii,ii)/a(jj,ii);
% row replacment operation
a(jj,:) = fac*a(jj,:)-a(ii,:);
end
end
end

You might also like