Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-299

Basis Transition Matrix 2D

Problem

Build the change-of-basis matrix from basis B to basis C in 2D.

B and C are pairs of basis vectors; return the 2x2 matrix whose columns are the coordinates of B[0] and B[1] expressed in C. Return None if C is linearly dependent.

Hint

Each column of the transition matrix solves a 2x2 system for one basis vector of B.

Test cases

case 1
in: [[[1,0],[0,1]],[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 2
in: [[[1,0],[0,1]],[[2,0],[0,2]]]
expected: [[0.5,0],[0,0.5]]
case 3
in: [[[1,1],[0,1]],[[1,0],[0,1]]]
expected: [[1,0],[1,1]]
case 4
in: [[[1,1],[0,1]],[[1,1],[0,1]]]
expected: [[1,0],[0,1]]
case 5
in: [[[1,0],[0,1]],[[1,1],[1,1]]]
expected: null
Starter codePython
def basis_transition_matrix(B, C):
    # Your code here
    pass

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