Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-284

Vector Rejection from Another

Problem

Compute the rejection of vector u from vector v: the component of u orthogonal to v.

rej_v(u) = u - proj_v(u) = u - ((u . v) / (v . v)) * v

Return None if v is the zero vector.

Hint

The rejection plus the projection reconstructs u exactly.

Test cases

case 1
in: [[3,3],[1,0]]
expected: [0,3]
case 2
in: [[1,2],[1,1]]
expected: [-0.5,0.5]
case 3
in: [[1,2],[0,0]]
expected: null
case 4
in: [[0,5],[1,0]]
expected: [0,5]
case 5
in: [[2,4,6],[1,0,0]]
expected: [0,4,6]
Starter codePython
def vector_rejection(u, v):
    # Your code here
    pass

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