Calculating the null space of a matrix

Posted by Ainsworth on Stack Overflow See other posts from Stack Overflow or by Ainsworth
Published on 2010-06-07T20:34:19Z Indexed on 2010/06/07 20:52 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

I'm attempting to solve a set of equations of the form Ax = 0. A is known 6x6 matrix and I've written the below code using SVD to get the vector x which works to a certain extent. The answer is approximately correct but not good enough to be useful to me, how can I improve the precision of the calculation? Lowering eps below 1.e-4 causes the function to fail.

from numpy.linalg import *
from numpy import *

A = matrix([[0.624010149127497 ,0.020915658603923 ,0.838082638087629 ,62.0778180312547 ,-0.336 ,0],
[0.669649399820597 ,0.344105317421833 ,0.0543868015800246 ,49.0194290212841 ,-0.267 ,0],
[0.473153758252885 ,0.366893577716959 ,0.924972565581684 ,186.071352614705 ,-1 ,0],
[0.0759305208803158 ,0.356365401030535 ,0.126682113674883 ,175.292109352674 ,0 ,-5.201],
[0.91160934274653 ,0.32447818779582 ,0.741382053883291 ,0.11536775372698 ,0 ,-0.034],
[0.480860406786873 ,0.903499596111067 ,0.542581424762866 ,32.782593418975 ,0 ,-1]])

def null(A, eps=1e-3):
  u,s,vh = svd(A,full_matrices=1,compute_uv=1)
  null_space = compress(s <= eps, vh, axis=0)
  return null_space.T

NS = null(A)
print "Null space equals ",NS,"\n"
print dot(A,NS)

© Stack Overflow or respective owner

Related posts about python

Related posts about null