## Author: M. Turhan ÇOBAN
## Created: 2021-06-13

function retval = thomas(a,r)
    n=length(a);
    f=zeros(1,n);
    e=zeros(1,n);
    g=zeros(1,n);
    x=zeros(1,n);
    for i=1:n 
      f(i)=a(i,i);
    endfor
    for i=1:n-1 
      g(i)=a(i,i+1);
    endfor
    for i=1:n-1 
      e(i+1)=a(i+1,i);              
    endfor
    for k=2:n 
      e(k)=e(k)/f(k-1);
      f(k)=f(k)-e(k)*g(k-1);             
    endfor
    for k=2:n
      r(k)=r(k)-e(k)*r(k-1);
    endfor
    x(n)=r(n)/f(n);
    for k=n-1:-1:1
      x(k)=(r(k)-g(k)*x(k+1))/f(k);
    endfor
    retval=x;
endfunction
