All problems
Null Space Basis
Problem
Find a basis for the null space of matrix A (vectors x with A*x = 0).
Compute the RREF, then for each free column build a basis vector with a 1 in that free position and the negated RREF pivot entries elsewhere. Return the basis in free-column order; return [] if the null space is trivial.
Hint
Each free variable produces one basis vector; read its coordinates from the RREF.
Test cases
case 1
in: [[[1,2],[2,4]]]
expected: [[-2,1]]
case 2
in: [[[1,1,1],[2,2,2]]]
expected: [[-1,1,0],[-1,0,1]]
case 3
in: [[[1,0],[0,1]]]
expected: []
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [[1,-2,1]]
Starter codePython
def null_space_basis(A):
# Your code here
pass4 test cases · run your code against them in the editor