MATLAB: An error occured in the description of the QR algorithm in the help file of R2016a

MATLABmatrix decompositionqr algorithm

[Q,R] = qr(A), where A is m-by-n, produces an m-by-n upper triangular matrix R and an m-by-m unitary matrix Q so that A = Q*R. This should be modified as: [Q,R] = qr(A), where A is m-by-n, produces an m-by-n unitary matrix Q and an m-by-m upper triangular matrix R so that A = Q*R.

Best Answer

Sorry, but you are wrong. The QR help is correct.
For an mxn matrix A, qr(A) computes:
Q is mxm orthogonal.
R is mxn, rectangular matrix containing an upper triangular part.
For example:
[Q,R] = qr(rand(5,3))
Q =
-0.26103 0.030403 -0.51279 -0.63445 -0.51524
-0.42538 -0.62597 0.58317 -0.29215 -0.042081
-0.51598 -0.22508 -0.29015 0.70147 -0.32688
-0.48149 0.7454 0.43751 -0.0017593 -0.14535
-0.50283 0.030976 -0.34837 -0.14163 0.77767
R =
-1.8539 -0.58027 -1.3508
0 -0.36777 -0.15026
0 0 -0.7475
0 0 0
0 0 0
So here Q is 5x5, R is 5x3, EXACTLY as they should be.
Your claim is that R should be a square matrix, of size mxm, and that Q should be rectangular. That is absolutely wrong, since then Q*R would not conform for multiplication. You cannot multiply a mxn matrix times a mxm matrix. The inner matrix dimensions will not match.
Note: if I had to guess, your confusion stems from the fact that in the help for qr, the dimensions of R were given first, then they stated the dimensions for Q. Since the matrices are returned in the order Q,R, you became confused, rather than reading the help carefully.