ZestCalc

Gram-Schmidt and QR Calculator

Turn any vectors into perpendicular ones, exactly. Follow each projection as it's subtracted, then read off the orthonormal basis and the QR factors.

Vectors

Enter up to 8 vectors of the same length, or start from an example.

Entries3
v1=v_{1} =
v2=v_{2} =
v3=v_{3} =

Result

Updates as you type.

Every vector adds a new direction, so the result has 3 perpendicular vectors.

Orthogonal basis

w1=(1, 1, 0)w_{1} = \left(1,\ 1,\ 0\right)
w2=(12, −12, 1)w_{2} = \left(\frac{1}{2},\ -\frac{1}{2},\ 1\right)
w3=(−23, 23, 23)w_{3} = \left(-\frac{2}{3},\ \frac{2}{3},\ \frac{2}{3}\right)

Orthonormal basis

q1=(22, 22, 0)q_{1} = \left(\frac{\sqrt{2}}{2},\ \frac{\sqrt{2}}{2},\ 0\right)
q2=(66, −66, 63)q_{2} = \left(\frac{\sqrt{6}}{6},\ -\frac{\sqrt{6}}{6},\ \frac{\sqrt{6}}{3}\right)
q3=(−33, 33, 33)q_{3} = \left(-\frac{\sqrt{3}}{3},\ \frac{\sqrt{3}}{3},\ \frac{\sqrt{3}}{3}\right)

QR factors

With your vectors as the columns of A, Q holds the orthonormal basis and R is upper triangular.

Q=[2266−3322−663306333]Q = \begin{bmatrix} \frac{\sqrt{2}}{2} & \frac{\sqrt{6}}{6} & -\frac{\sqrt{3}}{3} \\ \frac{\sqrt{2}}{2} & -\frac{\sqrt{6}}{6} & \frac{\sqrt{3}}{3} \\ 0 & \frac{\sqrt{6}}{3} & \frac{\sqrt{3}}{3} \end{bmatrix}
R=[222220626600233]R = \begin{bmatrix} \sqrt{2} & \frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2} \\ 0 & \frac{\sqrt{6}}{2} & \frac{\sqrt{6}}{6} \\ 0 & 0 & \frac{2\sqrt{3}}{3} \end{bmatrix}

One projection at a time

Take the vectors in order. From each one, remove its part along every finished vector, and what's left is perpendicular to all of them.

Step 0 of 7

What the Gram-Schmidt process does

The Gram-Schmidt process takes a set of vectors and returns perpendicular vectors with the same span. It works through them in order. From each vector, it removes the part along every vector already finished:

wk=vk−∑j<kvk⋅wjwj⋅wj wjw_k = v_k - \sum_{j < k} \frac{v_k \cdot w_j}{w_j \cdot w_j}\, w_j

Each fraction times wjw_j is a projection, which you can explore on its own with the Vector Projection Calculator. What remains has no part left along any earlier vector, so it's perpendicular to all of them. If nothing remains, that vector was already a combination of the earlier ones, which the Linear Independence and Span Calculator looks at directly.

Orthogonal, then orthonormal

Perpendicular vectors form an orthogonal basis. Dividing each one by its length gives an orthonormal basis, whose vectors all have length 1:

qk=wk∣wk∣q_k = \frac{w_k}{|w_k|}

The orthogonal vectors stay plain fractions, because they only use addition, multiplication, and division. Square roots appear only at this last step, which is why this calculator can keep every value exact.

QR factorization

Place your vectors as the columns of a matrix AA, and the process factors it as:

A=QRA = QR

QQ holds the orthonormal vectors as its columns, so QTQ=IQ^T Q = I. RR is upper triangular, and its entries record the process: the diagonal holds the lengths ∣wk∣|w_k|, and the entries above it hold qj⋅vkq_j \cdot v_k.

QR is useful because solving with it is stable and simple. To solve Ax=bAx = b or a Least Squares Calculator problem, you can solve Rx=QTbRx = Q^T b, which only needs back substitution. Computer programs usually use a more stable variant of this process because they round numbers, but exact arithmetic has no such concern.