You may notice that the Gram Schmidt process is pretty tedious but routine. Therefore, it is not surprising that it can be automated using MATLAB. One way to do it would be to use what is known as the QR factorization. Given a real m × n matrix A which has linearly independent columns, you can always write it in the form A = QR where Q is an orthogonal matrix and R is an upper triangular matrix in the sense that all entries are 0 below the main diagonal. Actually, the computer algebra system doesn’t use the Gram Schmidt process. It uses something called Householder reflections, but one obtains the same essentials although sometimes a different set of vectors, the columns of Q being an orthonormal set. The span of these columns will coincide with the span of the columns of A and in fact, the span of the first k columns of A will be the span of the first k columns of Q just as in the Gram Schmidt process. Here is the syntax:
Then press enter and you get the following.
If you want to see something horrible, replace qr(A) with qr(sym(A)). This way it gives the exact values. You can check your work by >>Q*Q’ and press enter. The Q’ means the conjugate transpose in MATLAB. Since everything is real here, this is just the transpose.
There is so much more that could be discussed about the QR factorization, but this will suffice here.
As to plotting data with a curve as in the least squares example, use the following syntax.
In MATLAB, you press shift enter to get to a new line and you press enter to get it to do something.