有没有一种快速的方法来反转在Matlab矩阵? [英] Is there a fast way to invert a matrix in Matlab?

查看:242
本文介绍了有没有一种快速的方法来反转在Matlab矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多大的(约5000倍5000)矩阵,我需要在Matlab反转。我真正需要的倒数,所以我不能使用mldivide相反,这是一个很大更快的解决Ax = b的只是一个B。

我的矩阵是由一个问题,这意味着他们有一些不错的性能来了。首先,他们的决定因素是1,因此他们绝对可逆的。他们不是对角化,不过,我还是会尝试diagonlize他们,颠倒它们,然后把它们放回。他们的作品都是实数(实际上是合理的)。

我用Matlab获取这些矩阵和这个东西,我需要与他们的逆,所以我会preFER的方式来加速Matlab的了。但是,如果有另一种语言,我可以用这会更快,那么请让我知道。我不知道很多其他语言的(一个小的C,但与一点点,但Java的),所以如果它真的复杂,一些其他的语言,那么我可能无法使用它。请继续和建议吧,虽然,以备不时之需。

解决方案
  

我真正需要的倒数,所以我不能使用mldivide而是......

这是不正确的,因为你仍然可以使用 mldivide 得到的倒数。需要注意的是 A 1 = A 1 * I 。在MATLAB中,这相当于

 的invA = A \ speye(尺寸(A));
 

在我的机器,这需要约10.5秒的 5000x5000 矩阵。需要注意的是MATLAB确实有一个 INV 函数来计算矩阵的逆。虽然这将需要大约相同的时间量,它是低效率的数值精度(在链接的详细信息)术语


  

首先,其决定因素是1,因此他们绝对可逆的。

而不是 DET(A)= 1 ,它是你的矩阵的条件数决定如何准确或稳定的逆会。需要注意的是 DET(A)=Π<子> I = 1:N λ<子>我 。因此,只要设置λ<子> 1 = M λ<子> N = 1 / M λ<子> I≠1,N = 1 会给你 DET(A)= 1 。然而,由于中号→∞ COND(A)= M 2 →∞λ<子> N →0 ,这意味着你的矩阵接近奇异会有大数值的误差在计算反。


  

我的矩阵是由一个问题,这意味着他们有一些不错的性能来了。

当然,也有可能,如果你的矩阵是稀疏的或有其他良好的性能可以采用其他更高效的算法。但是,如果没有您的具体问题的任何其他信息,没有什么可说。


  

我会preFER的方式来加速Matlab的了

MATLAB采用高斯消元法来计算一般矩阵的逆(满秩,非稀疏,没有任何特殊的属性),使用 mldivide 这是Θ(N 3 ,其中 N 是矩阵的大小。所以,你的情况, N = 5000 键,有 1.25×10 11 浮动浮点运算。因此,一个合理的机器计算能力约为10 GFLOPS上,你将需要至少12.5秒计算逆,也没有办法离开这里,除非你利用特殊性质(如果他们开采)

I have lots of large (around 5000 x 5000) matrices that I need to invert in Matlab. I actually need the inverse, so I can't use mldivide instead, which is a lot faster for solving Ax=b for just one b.

My matrices are coming from a problem that means they have some nice properties. First off, their determinant is 1 so they're definitely invertible. They aren't diagonalizable, though, or I would try to diagonlize them, invert them, and then put them back. Their entries are all real numbers (actually rational).

I'm using Matlab for getting these matrices and for this stuff I need to do with their inverses, so I would prefer a way to speed Matlab up. But if there is another language I can use that'll be faster, then please let me know. I don't know a lot of other languages (a little but of C and a little but of Java), so if it's really complicated in some other language, then I might not be able to use it. Please go ahead and suggest it, though, in case.

解决方案

I actually need the inverse, so I can't use mldivide instead,...

That's not true, because you can still use mldivide to get the inverse. Note that A-1 = A-1 * I. In MATLAB, this is equivalent to

invA = A\speye(size(A));

On my machine, this takes about 10.5 seconds for a 5000x5000 matrix. Note that MATLAB does have an inv function to compute the inverse of a matrix. Although this will take about the same amount of time, it is less efficient in terms of numerical accuracy (more info in the link).


First off, their determinant is 1 so they're definitely invertible

Rather than det(A)=1, it is the condition number of your matrix that dictates how accurate or stable the inverse will be. Note that det(A)=∏i=1:n λi. So just setting λ1=M, λn=1/M and λi≠1,n=1 will give you det(A)=1. However, as M → ∞, cond(A) = M2 → ∞ and λn → 0, meaning your matrix is approaching singularity and there will be large numerical errors in computing the inverse.


My matrices are coming from a problem that means they have some nice properties.

Of course, there are other more efficient algorithms that can be employed if your matrix is sparse or has other favorable properties. But without any additional info on your specific problem, there is nothing more that can be said.


I would prefer a way to speed Matlab up

MATLAB uses Gauss elimination to compute the inverse of a general matrix (full rank, non-sparse, without any special properties) using mldivide and this is Θ(n3), where n is the size of the matrix. So, in your case, n=5000 and there are 1.25 x 1011 floating point operations. So on a reasonable machine with about 10 Gflops of computational power, you're going to require at least 12.5 seconds to compute the inverse and there is no way out of this, unless you exploit the "special properties" (if they're exploitable)

这篇关于有没有一种快速的方法来反转在Matlab矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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