function x = tri_solve(T,b)

% function x = tri_solve(T,b)
% solution of a triangular system 
% T(i,:) * x(i-1:i+1) = b(i) 
% with Givens transformations

n = size(T,1);
for i = 1:n-1;
   I = [i:i+1];
   W = [[T(i,2:3), 0; T(i+1,:)], b(I)];
   W = g_trf(W);
   T(I,:) = W(:,1:3); b(I) = W(:,4);
end;
T(n,1) = T(n,2);

x = zeros(n+2,1);
for i = n:-1:1; 
   x(i) = (b(i) - T(i,2:3)*x(i+1:i+2)) / T(i,1);
end;
x = x(1:n);


