function x=crout6_7(A,b);
%% function x=crout6_7(A);
%% Crout reduction for a tri-diagonal system  Ax=b
%%    
%% INPUT:
%%   A - tridiagonal matrix
%%   b - right hand side as a column vector
%% OUTPUT:
%%   x - solution as a column vector

%%Determine the size of the system
n=length(A(:,1));
flag=0;

L(1,1)=A(1,1);
U(1,2)=A(1,2)/L(1,1);

for i=2:n-1
     L(i,i-1)=A(i, i-1);
     L(i,i)=A(i,i)-L(i,i-1)*U(i-1,i);
     U(i,i+1)=A(i,i+1)/L(i,i);
end;

L(n,n-1)=A(n,n-1);
L(n,n)=A(n,n)-L(n,n-1)*U(n-1,n);

%%%%Solve Lz=b
    z(1,1)=b(1)/L(1,1);
for j=2:n
      z(j,1)=(b(j)-L(j,j-1)*z(j-1,1))/L(j,j);
end;

%%Solve Ux=z
x(n,1)=z(n,1);
for i=n-1:-1:1;
   x(i,1)=z(i,1)-x(i+1,1)*U(i,i+1); 
end;
