计算矩阵的零空间 [英] Calculating the null space of a matrix

查看:773
本文介绍了计算矩阵的零空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试求解一组形式为Ax = 0的方程.A是已知的6x6矩阵,并且我已使用SVD编写了以下代码,以得到在一定程度上起作用的向量x.答案大致正确,但不足以对我有用,如何提高计算精度?将eps降低到1.e-4以下会导致功能失败.

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)

推荐答案

A是满分---所以x 0

A is full rank --- so x is 0

因为看起来您需要一个最小二乘解,即min ||A*x|| s.t. ||x|| = 1,所以请执行SVD,以使[U S V] = svd(A)V的最后一列(假设这些列按递减的奇异值排序)是x.

Since it looks like you need a least-squares solution, i.e. min ||A*x|| s.t. ||x|| = 1, do the SVD such that [U S V] = svd(A) and the last column of V (assuming that the columns are sorted in order of decreasing singular values) is x.

U =

     -0.23024     -0.23241      0.28225     -0.59968     -0.04403     -0.67213
      -0.1818     -0.16426      0.18132      0.39639      0.83929     -0.21343
     -0.69008     -0.59685     -0.18202      0.10908     -0.20664      0.28255
     -0.65033      0.73984    -0.066702     -0.12447     0.088364       0.0442
  -0.00045131    -0.043887      0.71552     -0.32745       0.1436      0.59855
     -0.12164      0.11611       0.5813      0.59046     -0.47173     -0.25029


S =

       269.62            0            0            0            0            0
            0       4.1038            0            0            0            0
            0            0        1.656            0            0            0
            0            0            0       0.6416            0            0
            0            0            0            0      0.49215            0
            0            0            0            0            0   0.00027528


V =

    -0.002597     -0.11341      0.68728     -0.12654      0.70622    0.0050325
   -0.0024567     0.018021       0.4439      0.85217     -0.27644    0.0028357
   -0.0036713      -0.1539      0.55281      -0.4961      -0.6516   0.00013067
      -0.9999    -0.011204   -0.0068651    0.0013713    0.0014128    0.0052698
    0.0030264      0.17515      0.02341    -0.020917   -0.0054032      0.98402
     0.012996     -0.96557     -0.15623      0.10603     0.014754      0.17788

所以

x =

    0.0050325
    0.0028357
   0.00013067
    0.0052698
      0.98402
      0.17788

并且,||A*x|| = 0.00027528与您先前的x解决方案(其中||A*x_old|| = 0.079442

And, ||A*x|| = 0.00027528 as opposed to your previous solution for x where ||A*x_old|| = 0.079442

这篇关于计算矩阵的零空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆