QR Decomposition

Manipulate[SeedRandom[sr];
With[{a=Round[RandomReal[{0,max},{n,n}],.1]},
Pane[Text@Grid[{{Style["A",Large], "", Style["Q",Large], Style["R",Large]},{}, {If[intQ,Round[a],a]//MatrixForm,Style[" = ",Large], Round[Transpose[QRDecomposition[If[intQ,Round[a],a]][[1]]],.1]//MatrixForm, Round[QRDecomposition[If[intQ,Round[a],a]][[2]],.1]//MatrixForm}}],{600,150}, Alignment->Center]],
{{n,4,"size of matrix"}, 2,6,1,Appearance->"Labeled"},
{{max,5,"maximum entry abs value"},1,9,Appearance->"Labeled"},
{{sr,123,"random seed"}, 1,12345,1},
{{intQ, False, "integer entries"}, {False, True}}]

The QR decomposition of a square matrix A factors A as the product of an orthogonal matrix Q and an upper triangular matrix R.  An orthogonal matrix is a matrix whose columns are mutually orthogonal unit vectors and so satisfies (Q^T)Q=I, where I is an identity matrix, and an upper triangular matrix is a matrix whose entries below the main diagonal are all zero. The matrix Q is the result of performing the Gram-Schmidt process on the columns of A. The Mathematica function QRDecomposition[a] accomplishes this factorization, producing the list {(Q^T),R}.

Contributed by: Chris Boucher