Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-168

Projection Matrix onto Line

Problem

Build the 2x2 orthogonal projection matrix onto the line through the origin at angle theta degrees.

With c = cos(t) and s = sin(t), P = [[c^2, c*s], [c*s, s^2]]. The matrix is symmetric and idempotent.

Hint

P = u*u^T where u is the unit vector along the line.

Test cases

case 1
in: [0]
expected: [[1,0],[0,0]]
case 2
in: [90]
expected: [[0,0],[0,1]]
case 3
in: [45]
expected: [[0.5,0.5],[0.5,0.5]]
case 4
in: [30]
expected: [[0.75,0.4330127018922193],[0.4330127018922193,0.25]]
Starter codePython
def projection_matrix_2d(theta_degrees):
    # Your code here
    pass

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