【问题标题】:Scipy null_space does not give me the correct answerScipy null_space 没有给我正确的答案
【发布时间】:2019-11-28 22:55:12
【问题描述】:

我对 Scipy null_space 有疑问。举个例子:

A = np.array([[7,3,2],[3,9,4],[2,4,5]])
eigen = np.linalg.eig(A)

输出特征=

(array([13.477,  5.   ,  2.523]), 
array([[ 0.486,  0.873, -0.041],
       [ 0.74 , -0.436, -0.511],
       [ 0.464, -0.218,  0.858]]))

我在 eigen 元组中有特征值和特征向量。现在如果eA 的特征值(例如13.477),显然是 A - e I 不应为空,但是:

null = la.null_space(A-eigen[0][0]*np.eye(3))

返回

array([], shape=(3, 0), dtype=complex128)

这应该是对应于eigen[0][0] 的特征向量(请注意,当我为eigen[0][1]eigen[0][2] 运行相同的代码时,它会正确返回我们在上面看到的特征向量)。 为了检查这一点,我询问了(A-eI) 的特征值和特征向量:

null_eigen = np.linalg.eig(A-eigen[0][0]*np.eye(3))

输出 null_eigen =

(array([-1.243e-14, -8.477e+00, -1.095e+01]), 
 array([[ 0.486,  0.873, -0.041],
        [ 0.74 , -0.436, -0.511],
        [ 0.464, -0.218,  0.858]]))

显然第一个特征值,对应于 13.477 的特征向量,“几乎”为零,但为什么 scipy.linalg.null_space 没有拾取呢?

【问题讨论】:

    标签: python numpy scipy


    【解决方案1】:

    来自null_space的文档,

    rcond :相对条件编号。小于rcond * max(s) 的奇异值 s 被视为零。默认值:floating point eps * max(M,N)

    因此rcond 确定了有效的空空间。浮点数学并不精确,因此对于特征值,这恰好滑过阈值。为rcond 使用更大的数字将得到预期的结果:

    import numpy as np
    from scipy.linalg import null_space
    
    A = np.array([[7, 3, 2],
                  [3, 9, 4],
                  [2, 4, 5]])
    eigen = np.linalg.eig(A)
    print(eigen[1][:, 0])
    print(null_space(A - eigen[0][0]*np.eye(3), rcond=1e-14))
    

    输出:

    [0.48622704 0.74041411 0.46407996]
    [[-0.48622704]
     [-0.74041411]
     [-0.46407996]]
    

    更多详情也可以关注at the source code

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多