function QR= triang(An,nn)
%
% The periodic sequence A(i), i=1...nn, is triangularized.
% Sequences U(i) of orthogonal matrices and R(i) of upper triangular
% matrices are computed such that U(i+1)R(i) = A(i)U(i) holds up
% to rounding errors. 
% (It is assumed that the sequence A(i) is hyperbolic).
%
% input:  An(2,2,nn)		sequence of 2x2-matrices
%	  nn 			period
% output: QR			is a structure
%	  QR.o(2,2,nn+1)	sequence of orthogonal 2x2-matrices U(i)
%				QR.o(:,:,nn+1)=QR.o(:,:,1)
%				QR.o is an interval variable
%	  QR.t(2,2,nn)		sequence of triangular 2x2-matrices R(i)
%				QR.t is a point variable

  An=cat(3,An,An(:,:,1));
  stop=1;
  U1=eye(2);
  while stop>1e-15,
    Un=U1;
    Rn=[];
    for i=1:nn,
      [U1,R1]=qr(An(:,:,i)*Un(:,:,i));
      Un=cat(3,Un,U1);
      Rn=cat(3,Rn(:,:,1:i-1),R1);
    end
    I1=Un(:,:,1)'*U1;
    I2=abs(I1)-eye(2);
    stop=sum(sum(I2.*I2))^0.5;
  end
  QR.o=intval(Un(:,:,[1:nn,1]));
  QR.t=Rn;

%
% written   05/20/99   D.Stoffer
%
