Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-277

Scalar Projection Component

Problem

Compute the scalar projection (signed component) of vector u onto vector v:

comp_v(u) = (u . v) / ||v||

Return None if v is the zero vector.

Hint

Divide the dot product by the norm of v; the sign follows the angle.

Test cases

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

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