function[x]= eliminate(A, b)

[n jaredthisisunused] = size(A);

if (n ~= jaredthisisunused)
    disp('The matrix A is not square.')
    return;
end

if (n ~= size(b))
    disp('The vector b does not match the size of matrix A.')
    return;
end

if (det(A) == 0)
    disp('The matrix A is singular.')
    return;
end


for k=1:n-1
    for i=k+1:n
        fac = (A(i,k)) / (A(k,k));
        for j=k+1:n
            A(i,j) = A(i,j) - fac * (A(k,j));
        end
        b(i) = b(i) - fac*(b(k));
    end
end

x(n) = ((b(n)) / (A(n,n)));

for i=n-1:-1:1
    sum = b(i);
    for j=i+1:n
        sum = sum - (A(i,j))*x(j);
    end
    x(i) = sum / (A(i,i));
end

end
    