function x=tridiag_solve(d,e,f,rhs)
n=length(e);
m=zeros(n,1); u=zeros(n,1);
x=zeros(n,1);
u(1)=e(1);
for j=2:n
    m(j)=d(j)/u(j-1);
    u(j)=e(j)-m(j)*f(j-1);
end 
x(1)=rhs(1);
for j=2:n
    x(j)=rhs(j)-m(j)*x(j-1);
end
x(n)=x(n)/u(n);
for j=n-1:-1:1
    x(j)=(x(j)-f(j)*x(j+1))/u(j);
end