%% Thomas Algorithm

display('Thomas Algorithm');

A1=[0; 1.*ones(6,1)];
A2=-2.25.*ones(7,1);
A3=[1.*ones(6,1); 0];
b=[zeros(6,1); -100];
[A1 A2 A3 b]
n=size(b,1);
x=zeros(n,1);

%Elimination
for i=2:n
    em=A1(i)/A2(i-1);
    A2(i)=A2(i)-em*A3(i-1);
    b(i)=b(i)-em*b(i-1);
end;

%Back-Substitution
x(n)=b(n)/A2(n);
for i=n-1:-1:1
    x(i)=(b(i)-A3(i)*x(i+1))/A2(i);
end;

%Show results... 
[A1 A2 A3 b]
x