4.5.35 · D3Linear Algebra (Full)

Worked examples — Gram-Schmidt orthogonalization — algorithm

2,039 words9 min readBack to topic

You have seen the machine in the parent note. Here we stress-test it against every kind of input it can ever meet — messy angles, degenerate (dependent) vectors, weird inner products, a real word problem, and an exam twist. Each example tells you which "cell" of the scenario table it kills.

Before we start, one reminder in plain words so nothing is assumed.


The scenario matrix

Gram–Schmidt looks like one formula, but the behaviour changes completely depending on what you feed it. Here is every case class that can occur — we will hit every single row below.

# Cell / scenario What makes it special Example
C1 Two clean 2-D vectors, positive overlap shadow points along Ex 1
C2 Negative overlap () shadow points opposite ; sign of flips Ex 2
C3 Already orthogonal input overlap , algorithm does nothing Ex 3
C4 Full 3-D, two subtractions must clear both earlier Ex 4
C5 Degenerate — dependent vector residual , cannot normalize Ex 5
C6 Order matters — same set, swapped different 's, same subspace Ex 6
C7 Non-standard inner product (weighted) changes what "perpendicular" means Ex 7
C8 Word problem — decorrelating measurements Gram–Schmidt as "remove the common trend" Ex 8
C9 Exam twist — read off the of QR decomposition coefficients ARE the answer Ex 9

Ex 1 — Cell C1: positive overlap in

Forecast (guess first!): leans a little along (both point up-right), so the leftover should point up-and-slightly-left. Try to picture it before reading on.

Figure — Gram-Schmidt orthogonalization — algorithm
  1. . Why this step? The first vector has nothing earlier to be perpendicular to, so we keep it untouched — it defines our first clean axis.

  2. Compute the overlap. , and . Why this step? These two numbers form the scalar — the "how many copies of fit inside the shadow of ".

  3. Subtract the shadow. Why this step? means the shadow (red arrow in the figure) points the same way as ; removing it drags back to the perpendicular leftover (pink arrow).

  4. Normalize. , (already unit!).

Recall Verify

✅ perpendicular. and ✅ orthonormal.


Ex 2 — Cell C2: negative overlap (opposite lean)

Forecast: points up and to the left, so it leans against . Expect the scalar to come out negative — the shadow points backward.

Figure — Gram-Schmidt orthogonalization — algorithm
  1. . Why? First vector, kept as-is; it is the positive- axis.

  2. Overlap: ; . So . Why this step? A negative is not an error — it just means the shadow points in the direction, exactly matching 's leftward lean.

  3. Subtract: . Why? Removing a backward shadow (subtracting a negative) pushes the residual up onto the -axis — visibly perpendicular to the -axis.

  4. Normalize: , so , .

Recall Verify

✅. The output is literally the standard basis — makes sense, any 2 independent 2-D vectors comb down to a rotated pair of axes, and here they align with .


Ex 3 — Cell C3: input already orthogonal

Forecast: they are already at right angles, so Gram–Schmidt should change nothing but the lengths.

  1. .
  2. Overlap: , so . Why this step matters: when the overlap is zero, the shadow is the zero vector — there is nothing to subtract. This is the degenerate-in-a-good-way case: the comb passes straight through.
  3. . Unchanged.
  4. Normalize: , .
Recall Verify

already before we touched it ✅. Gram–Schmidt is idempotent on orthogonal input — a good sanity check that the algorithm never "over-combs".


Ex 4 — Cell C4: full , two subtractions

Forecast: must be cleaned of two shadows — one on , one on . Miss either and the perpendicularity proof collapses.

Figure — Gram-Schmidt orthogonalization — algorithm
  1. . Why? Base direction.

  2. : , . Coefficient . Why this step? One earlier clean vector ⇒ one shadow removed.

  3. needs BOTH removals. Compute:

    • , ⇒ coeff .
    • , ⇒ coeff . Why this step? There are two already-orthogonal vectors, so two shadows must go — the mnemonic "Subtract the Shadows of the Settled."
  4. Simplify coordinate-by-coordinate:

Recall Verify

✅ Both zero ⇒ perpendicular to all earlier vectors, as the induction promised.


Ex 5 — Cell C5: degenerate (dependent) input → zero vector

Forecast: lies exactly along , so after removing its shadow nothing is left — the residual should be , and normalization will demand dividing by zero.

  1. .
  2. Overlap: , , so .
  3. Subtract: . Why this step? The entire vector was the shadow. Nothing sticks out perpendicular.
Recall Verify

has norm , confirming dependence. Any dependent input produces a zero residual at the offending step.


Ex 6 — Cell C6: order matters (swap the inputs)

Forecast: we should get different 's than Ex 1, yet they must span the same plane ( here) and stay orthonormal. Gram–Schmidt depends on the ordering of the inputs.

  1. . (In Ex 1 this was 's neighbourhood — now it leads.)
  2. Overlap: , , .
  3. Subtract: . Why this step? First vector fixed the axis; the second gets combed against it.
  4. Normalize: , .
Recall Verify

✅ and ✅.


Ex 7 — Cell C7: a weighted inner product

Forecast: "perpendicular" now means weighted balance, not visual right angles. The numbers change, but the exact same formula runs — this is why the parent note wrote abstractly, never "dot".

  1. .
  2. Weighted overlap: ; . So . Why this step? We plug the weighted inner product into the exact same — no new machinery needed.
  3. Subtract: .
Recall Verify

Check with the weighted product: ✅. Note: under the ordinary dot product too here — but in general weighted-orthogonal vectors need not look perpendicular on paper. Orthogonality is defined by the inner product you chose.


Forecast: B clearly contains a chunk of "flat baseline". Subtracting B's shadow on A should leave a pure rising residual that averages to zero.

  1. — the baseline direction. Why? We treat the baseline as the "settled" reference.
  2. Overlap: ; ; . Why this step? says B contains exactly one full copy of the baseline.
  3. Residual: . Why? This is B with the baseline removed — the pure day-to-day change.
Recall Verify

✅ independent of baseline. Interpretation check: the residual sums to zero ⇒ it carries no average level, only the rising trend. Exactly what "remove the common baseline" should mean. (This is the seed idea of Least squares regression: subtract the projection onto the model you already have.)


Ex 9 — Cell C9: exam twist — read off from QR decomposition

Forecast: every entry is just an inner product you already computed — no new work, that's the whole trick.

  1. . (This is .)
  2. .
  3. . (This is from Ex 1.)
  4. — always, because has no component ( came later).
Recall Verify

Reconstruct: first column ✅. Second column ✅. So exactly.


Connections