Lesson 2 of 15
Gram-Schmidt Orthogonalization
Gram-Schmidt Orthogonalization
Given a set of linearly independent vectors, Gram-Schmidt produces an orthonormal basis — a set of vectors that are mutually perpendicular and each have unit length.
Algorithm
For each vector v in turn:
- Subtract its projection onto every previously found basis vector
- Normalize the result
For :
Since each is already normalized (length 1), the projection coefficient simplifies to just .
Example
Input vectors: [1,1,0], [1,0,1], [0,1,1]
| Step | Result |
|---|---|
| [0.7071, 0.7071, 0.0000] | |
| from [1,0,1] | [0.4082, -0.4082, 0.8165] |
| from [0,1,1] | [-0.5774, 0.5774, 0.5774] |
Your Task
Implement gram_schmidt(vecs) that takes a list of linearly independent vectors and returns an orthonormal basis.
Python runtime loading...
Loading...
Click "Run" to execute your code.