So I have a matrix X
and I want to know a basis for its nullspace. I've seen the suggestion that QR decomposition will give this where, if X
is m × n
then Q
will be m × n
and if you write Q = [Q1, Q2]
where Q1
is m × m
then Q2
will have columns as a basis for the nullspace of X
. However, my X
is 4 × 4
so Q
will be the same, and then you can't split it into any proper pieces, so I don't seem to be able to find vectors in the nullspace.
Am I misunderstanding how to get a basis for the nullspace from QR decomposition, or will it just not work for square matrices that have non-trivial kernels?
Also, is there a way to more efficiently or directly find a basis for the null space?
Here is the actual full code I'm running:
import sympy as sp
c1 = [2, 0, 0, 0]
c2 = [1, 2, 0, 0]
c3 = [0, 1, 2, 0]
c4 = [0, 0, 0, 3]
ul = [1, 1, 1, 1]
A = sp.Matrix([ sp.Matrix(c1).T, sp.Matrix(c2).T, sp.Matrix(c3).T, sp.Matrix(c4).T ]).T
u = sp.Matrix(ul)
M = u.row_join(A*u).row_join(A**2*u).row_join(A**3*u).row_join(A**4*u)
coefs = M.rref()[0].col(4)
x = sp.Symbol('x')
p = 1
for i in range(4):
p = p - coefs[3-i]*x**(i+1)
sol = sp.solve(p,x)
Qs = []
for i in range(2):
Q,R = ((A-sol[i]*sp.eye(4)).T).QRdecomposition()
Qs.append(Q)