%naive gaussian elimination for a tridiagonal matrix

A = [1,6,0,0,0,14;10,2,7,0,0,15;0,11,3,8,0,16;0,0,12,4,9,17;0,0,0,13,5,18]

n = min(size(A));

%forward elimination

for i=1:n-1
    r = A(i+1,i)/A(i,i);
    A(i+1,i) = 0;
    A(i+1,i+1) = A(i+1,i+1)-r*A(i,i+1);
    A(i+1,n+1) = A(i+1,n+1)-r*A(i,n+1);    %update far right column
end

%backward elimination

for i=n:-1:2
    r = A(i-1,i)/A(i,i);
    A(i-1,i) = 0;
    A(i-1,n+1) = A(i-1,n+1)-r*A(i,n+1);   %update far right column
end

%scale rows

for i=1:n
    r = A(i,i);
    A(i,i) = 1;
    A(i,n+1) = A(i,n+1)/r;
end

disp('the rref of A is...')
A