Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-129

Change of Basis Coordinates

Problem

Express vector v in the basis formed by the two vectors in basis = [b1, b2].

Return coordinates [c1, c2] such that v = c1*b1 + c2*b2. Return None if the basis vectors are linearly dependent.

Hint

Solve the 2x2 system whose columns are the basis vectors using the cross formula.

Test cases

case 1
in: [[[1,0],[0,1]],[3,4]]
expected: [3,4]
case 2
in: [[[1,1],[1,-1]],[2,0]]
expected: [1,1]
case 3
in: [[[2,0],[0,3]],[4,9]]
expected: [2,3]
case 4
in: [[[1,1],[2,2]],[1,1]]
expected: null
Starter codePython
def change_of_basis(basis, v):
    # Your code here
    pass

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