function [T,Qt]=qr_it2(A);
% QR_IT2 Given an (n x n) matrix A.
% This function are using QR iterations in order to calculate the
% amazing block real Scur decomposition A=Q*T*Q'. 
% on output.
% [T,Q]=qr_it2(A)
% ON INPUT
% A - An (n x n) matrix with real eigenvalues
% ON OUTPUT
% T - An (n x n) diagonal or upper triangular matrix similar to A, 
% i.e. with the n-eigenvalues of A on the diagonal.
% Q - An orthogonal matrix such that A=Q*T*Q'

% Written: November 10 2011 by David Di Ruscio

n=size(A,1);
Qt=eye(n);

max_it=100;
for i=1:max_it
    [Q,R]=qr(A); 
    A=R*Q;
    Qt=Qt*Q;
end
T=A;