Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-078

Orthogonal Projection Matrix

Problem

Build the orthogonal projection matrix onto the subspace spanned by basis, a list of one or two vectors in R^2:

P = A * inv(A^T A) * A^T

where A has the basis vectors as columns. Return None if the basis is empty or linearly dependent.

Hint

P is symmetric and idempotent; projecting onto a full basis gives the identity.

Test cases

case 1
in: [[[1,1]]]
expected: [[0.5,0.5],[0.5,0.5]]
case 2
in: [[[1,0]]]
expected: [[1,0],[0,0]]
case 3
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 4
in: [[[2,0]]]
expected: [[1,0],[0,0]]
Starter codePython
def projection_matrix(basis):
    # Your code here
    pass

4 test cases · run your code against them in the editor