A=[5 -3 2;6 -4 4;4 -4 5];[Q,R]=qr(A); while 1 R1=R; [Q,R]=qr(R*Q); if sum(sum((R-R1).^2))<0.0001 break; end end diag(R)