%% subroutine of backward substitution (solving Tridiagonal System) %%
function [x] = solvet(u,d,l,b)
 
n = length(d);
x = (1:n);
y = (1:n);

%Solve Tridiagonal system LUx=b;

% Step 1 : Solve Ly=b for y
y(1) = b(1);
for i=2:n
    y(i) = b(i) - l(i-1)*y(i-1);
end
 
% Step 2 : Solve Ux=y for x
x(n) = y(n)/d(n);  
for i=(n-1):-1:1
    x(i) = (y(i)-u(i)*x(i+1))/d(i);
end


