function [x] = Tri(a,d,c,b)
% Tridiagonal system solve
% Input: a = (n-1) vector, sub-diagonal;
%        d = n vector, diagonal;
%        c = (n-1) vector, super-diagonal;
%        b = n vector, RHS;
%Output: x = n vector, the solution

n=length(d);

for i = 2:n
    xmult = a(i-1)/d(i-1);
    d(i)=d(i) - xmult*c(i-1);
    b(i) = b(i) - xmult*b(i-1);
end

x(n)=b(n)/d(n);
for i=n-1:-1:1
    x(i) = (b(i)-c(i)*x(i+1))/d(i);
end