I guess you are looking for this:
clear all
close all
a = [4 1 -1;5 1 2;6 1 1];
b = [-2 4 6];
width = size(a,2);
height = size(a,1);
% forward elimination
for i=1 : width
for y=i+1 : height
factor = a(y,i) / a(i,i);
for x=i : width
a(y,x) = a(y,x) - a(i,x) * factor;
end
end
end
Note also that if a
is not square, i
is in {1,...,min(width,height)}
. This is going to happen when you make the same operations that you make in a
also in b
, since a=[a,b] = augumented matrix.