Advertisement
Guest User

Untitled

a guest
Jun 19th, 2012
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Python (NumPy, SciPy), finding the null space of a matrix
  2. A = matrix([
  3. [2,3,5],
  4. [-4,2,3]
  5. ])
  6.  
  7. import scipy
  8. from scipy import linalg, matrixr
  9. def null(A, eps=1e-15):
  10. u, s, vh = scipy.linalg.svd(A)
  11. null_mask = (s <= eps)
  12. null_space = scipy.compress(null_mask, vh, axis=0)
  13. return scipy.transpose(null_space)
  14.  
  15. Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
  16. [GCC 4.4.5] on linux2
  17. Type "help", "copyright", "credits" or "license" for more information.
  18. >>> import scipy
  19. >>> from scipy import linalg, matrix
  20. >>> def null(A, eps=1e-15):
  21. ... u, s, vh = scipy.linalg.svd(A)
  22. ... null_mask = (s <= eps)
  23. ... null_space = scipy.compress(null_mask, vh, axis=0)
  24. ... return scipy.transpose(null_space)
  25. ...
  26. >>> A = matrix([
  27. ... [2,3,5],
  28. ... [-4,2,3]
  29. ... ])
  30. >>>
  31. >>> null(A)
  32. array([], shape=(3, 0), dtype=float64)
  33. >>>
  34.  
  35. A = matrix([[2,3,5],[-4,2,3],[0,0,0]])
  36. A * null(A)
  37. >>> [[ 4.02455846e-16]
  38. >>> [ 1.94289029e-16]
  39. >>> [ 0.00000000e+00]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement