如何判断矩阵是否奇异? [英] How to find out if a matrix is singular?

查看:256
本文介绍了如何判断矩阵是否奇异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何知道一个 4x4 矩阵是否是奇异矩阵?

How we can come to know that a 4x4 matrix is singular or not?

我们能否在不使用单位矩阵扩充给定矩阵然后进行行运算的情况下了解这一点?

Can we come to know this without augmenting our given matrix with the identity matrix and then doing the row operations?

推荐答案

那么如何确定一个矩阵是否真的是奇异矩阵呢?(在 MATLAB 中,不使用纸笔或符号计算,或手写行运算?)教科书有时会告诉学生使用行列式,所以我会从那里开始.

So how does one identify if a matrix is truly singular? (In MATLAB, without using paper and pencil or symbolic computations, or hand written row operations?) The textbooks sometimes tell students to use the determinant, so I'll start there.

理论上,可以简单地测试矩阵的行列式是否为零.于是

In theory, one can simply test if the determinant of your matrix is zero. Thus

M = magic(4)
M =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

det(M)
ans =
  -1.4495e-12

事实证明,这个矩阵确实是奇异的,所以有一种方法可以将 M 的一行写成其他行的线性组合(对于列也是如此.)但是我们得到的值并不完全正确零从 det.它真的是零吗,而 MATLAB 只是糊涂了?这是为什么?符号行列式确实为零.

As it turns out, this matrix is indeed singular, so there is a way to write a row of M as a linear combination of the other rows (also true for the columns.) But we got a value that was not exactly zero from det. Is it really zero, and MATLAB just got confused? Why is that? The symbolic determinant is truly zero.

det(sym(M))
ans =
0

事实证明,对于较大的数组,行列式的计算是一件非常低效的事情.所以一个不错的选择是使用我们方阵的特定矩阵分解的对角线元素的乘积.事实上,这就是 MATLAB 在内部对非符号输入所做的事情.

As it turns out, computation of the determinant is a terribly inefficient thing for larger arrays. So a nice alternative is to use the product of the diagonal elements of a specific matrix factorization of our square array. In fact, this is what MATLAB does inside det itself for non-symbolic inputs.

[L,U,P] = lu(M)
L =
            1            0            0            0
         0.25            1            0            0
       0.3125      0.76852            1            0
       0.5625      0.43519            1            1
U =
           16            2            3           13
            0         13.5        14.25        -2.25
            0            0      -1.8889       5.6667
            0            0            0   3.5527e-15
P =
     1     0     0     0
     0     0     0     1
     0     1     0     0
     0     0     1     0

看到 L 的对角线元素都是 1,但 U 有非零对角线元素.并且矩阵乘积的行列式以及上三角矩阵或下三角矩阵的行列式都有很好的性质.

See that the diagonal elements of L are ones, but U has non-zero diagonal elements. And there are nice properties about the determinant of a product of matrices, as well as the determinant of upper or lower triangular matrices.

prod(diag(U))
ans =
  -1.4495e-12

看到我们得到了相同的答案.由于 LU 分解即使对于大型数组也相当快,因此它是计算行列式的好方法.问题是,它使用浮点运算.所以 U 的那些对角元素是实数,浮点数.当我们使用产品时,我们得到的结果并不完全为零.最后一个元素只是略微非零.

See that we got the same answer. Since a LU factorization is reasonably fast even for large arrays, it is a nice way to compute the determinant. The problem is, it uses floating point arithmetic. So those diagonal elements of U are real, floating point numbers. When we take the product, we get a result that is not exactly zero. That last element was just slightly non-zero.

det 还有其他问题.例如,我们知道矩阵 eye(100) 的条件非常好.毕竟是单位矩阵.

There are other problems with det. For example, we know that the matrix eye(100) is extremely well conditioned. It is an identity matrix after all.

det(eye(100))
ans =
     1

现在,如果我们将矩阵乘以一个常数,这不会改变矩阵作为奇异矩阵的状态.但是行列式会发生什么?

Now, if we multiply a matrix by a constant, this does NOT change the status of the matrix as a singular one. But what happens with the determinant?

det(.1*eye(100))
ans =
   1e-100

那么这个矩阵是奇异矩阵吗?毕竟,如果 det(magic(4)) 给我们 1e-12,那么 1e-100 必须对应一个奇异矩阵!但事实并非如此.更糟糕的是,

So is this matrix singular? After all, if det(magic(4)) gives us 1e-12, then 1e-100 must correspond to a singular matrix! But it does not. Even worse,

det(.0001*eye(100))
ans =
     0

事实上,行列式按0.0001^100缩放,在matlab中为1e-400.至少如果 matlab 可以使用双精度表示那么小的数字,那将是正确的.它不能这样做.该数字将下溢.或者很容易,我们可以让它溢出.

In fact, the determinant is scaled by 0.0001^100, which in matlab will be 1e-400. At least that would be true if matlab could represent a number that small using a double. It cannot do so. That number will underflow. Or as easily, we can make it overflow.

det(10000*eye(100))
ans =
   Inf

显然,所有这些缩放的单位矩阵都同样是非奇异的,但是可以通过 det 给出我们想要看到的任何答案!因此,我们必须得出结论,对矩阵计算行列式是一件可怕的事情.我不在乎你的教科书很久以前告诉你什么,或者你的老板或老师告诉你什么.如果有人告诉您为此目的使用计算机计算行列式,那是一个糟糕的建议.时期.决定因素的问题太多了.

Clearly, all of these scaled identity matrices are equally non-singular, but det can be made to give us any answer we want to see! Therefore we must conclude that computing a determinant is a terrible thing to do to a matrix. I don't care what your textbook told you long ago, or what your boss or teacher told you. If somebody told you to compute the determinant for this purpose USING A COMPUTER, that was terrible advice. Period. Determinants simply have too many problems.

我们可以做其他事情来测试奇点.最好的工具是使用等级.因此,如果 NxM 矩阵的秩小于 min(N,M),则该矩阵是奇异矩阵.下面是几个测试:

We can do other things to test for singularity. The best tool is to use rank. Thus, if the rank of an NxM matrix is less than min(N,M), then the matrix is singular. Here are a couple of tests:

rank(M)
ans =
     3

rank(.0001*eye(100))
ans =
   100

所以 rank 可以告诉我们 4x4 幻方是奇异的,但我们缩放的单位矩阵不是奇异的.(好处是秩可以检验非方阵的奇异性.)

So rank is able to tell us that the 4x4 magic square is singular, but our scaled identity matrix is not singular. (A nice thing is that rank can test for singularity of a non-square matrix.)

我们还可以使用 cond 来测试数值奇点.可能的最小条件数是 1.0,它对应于一个表现非常好的矩阵.大的条件数是不好的.在双精度中,这意味着当条件数大于约 1e15 时,您的矩阵很有问题.

We can also use cond to test for numerical singularity. The smallest possible condition number is 1.0, which corresponds to a very well behaved matrix. Large condition numbers are bad. In double precision, this means when the condition number is greater than about 1e15, your matrix is very problematic.

cond(M)
ans =
    8.148e+16

cond(.0001*eye(100))
ans =
     1

事实上,cond 认为缩放后的单位矩阵毕竟是有条件的.大的条件数是不好的.对于双精度矩阵,任何接近 1e15 左右的条件数表示矩阵可能在数值上是奇异的.所以我们看到 M 显然是单数.同样,cond 能够处理非方阵.

In fact, cond perceives that the scaled identity matrix is well conditioned after all. Large condition numbers are bad. For a double precision matrix, a condition number that is anywhere near 1e15 or so indicates a matrix that is probably numerically singular. So we see that M is clearly singular. Again, cond is able to work on non-square matrices.

或者,我们可以使用 rcond,一种估计条件数倒数的工具.对于非常大的数组,这是一个很好的工具.当 rcond 给出的数字接近 eps 时,请注意!

Or, we could use rcond, a tool which estimates the reciprocal of the condition number. This is a nice tool for really large arrays. When rcond gives a number that is anywhere near eps, WATCH OUT!

rcond(M)
ans =
   1.3061e-17

rcond(.0001*eye(100))
ans =
     1

最后,对于数学齿轮头(像我一样),我们可能会拉出 svd.毕竟,svd 是 cond 和 rank 所基于的工具.当矩阵的一个或多个奇异值与最大的奇异值相比很小时,我们再次具有奇异性.

Finally, for the mathematical gear-heads (like me), we might pull out svd. After all, svd is the tool that cond and rank are based on. When one or more of the singular values of the matrix are tiny compared to the largest singular value, again we have singularity.

svd(M)
ans =
           34
       17.889
       4.4721
   4.1728e-16

这里我们看看奇异值何时小于矩阵的最大奇异值.一件好事是 svd 可以告诉我们矩阵与奇异点的接近程度,如果有多个小奇异值,if 可以告诉我们有关矩阵秩的信息.

Here we look at when a singular value is small compared to the largest singular value of the matrix. A nice thing is svd can tell us how close the matrix is to singularity, and if there are more than one small singular values, if gives us information about the rank of the matrix.

好消息是,我展示的所有工具都不需要用户进行基本的行操作或任何花哨的操作.

The nice thing is that none of the tools I've shown require the user to do elementary row operations or anything fancy.

但请不要使用 DET!是的,它出现在教科书中.是的,也许你的导师或你的老板告诉你使用它.他们错了,因为像这样的工具在使用浮点运算的计算机上应用时会失败.而且您根本不想计算符号行列式,这会非常低效.

BUT PLEASE DON'T USE DET! Yes, it shows up in textbooks. Yes, maybe your instructor or your boss told you to use it. They were just wrong, because tools like this fail when they are applied on a computer, which uses floating point arithmetic. And you simply don't want to compute a symbolic determinant, which will be terribly inefficient.

如果这是一个长篇阅读,我很抱歉.我现在就离开肥皂盒.

I'm sorry if this was a long read. I'll get off my soapbox now.

这篇关于如何判断矩阵是否奇异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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