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

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

问题描述

我们怎么知道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内部在det自身中为非符号输入所做的事情.

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还有其他问题.例如,我们知道矩阵眼(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

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

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可以告诉我们矩阵离奇异点有多近,如果有多个小奇异值,可以告诉我们有关矩阵秩的信息.

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天全站免登陆