MATLAB中最有效的矩阵求逆 [英] Most efficient matrix inversion in MATLAB

查看:1941
本文介绍了MATLAB中最有效的矩阵求逆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB中计算某些方阵A的逆时,使用

When computing the inverse for some square matrix A in MATLAB, using

Ai = inv(A)
% should be the same as:
Ai = A^-1

MATLAB通常会通知我这不是最有效的反相方法. 那么更有效率吗?如果我有一个方程式系统,则可能使用/,\运算符. 但是有时候我需要逆运算来进行其他计算.

MATLAB usually notifies me that this is not the most efficient way of inverting. So what's more efficient? If I have an equation system, using the /,\ operators probably is. But sometimes I need the inverse for other computations.

最有效的反转方法是什么?

What's the most efficient way to invert?

推荐答案

我建议使用svd(除非您确实完全确定您的矩阵没有病态).然后,基于奇异值,您可以决定要采取的其他措施.这听起来像是一种过度杀伤"的方法,但是从长远来看,它会有所回报.

I would recommend to use svd (unless you are really absolute sure that your matrix is not ill-conditioned). Then, based on singular values you make your decisions on further actions to take. This may sound like a 'overkill' approach, but in long run it will pay back.

现在,如果矩阵A实际上是可逆的,则Apseudo inverseinv(A)符合,但是,如果您接近奇点",则可以轻松地做出适当的决定,以继续进行制作pseudo inverse.当然,这些决定将取决于您的应用程序.

Now if your matrix A is actually invertible, then the pseudo inverse of A coincidence with inv(A), however if you are close to 'singularity' you'll easily make appropriate decision how to proceed to actually make the pseudo inverse. Naturally these decisions will depend on your application.

添加一个简单的示例:

> A= randn(3, 2); A= [A A(:, 1)+ A(:, 2)]
A =
  -1.520342  -0.239380  -1.759722
   0.022604   0.381374   0.403978
   0.852420   1.521925   2.374346

> inv(A)
warning: inverse: matrix singular to machine precision, rcond = 0
ans =
   Inf   Inf   Inf
   Inf   Inf   Inf
   Inf   Inf   Inf

> [U, S, V]= svd(A)
U =
  -0.59828  -0.79038   0.13178
   0.13271  -0.25993  -0.95646
   0.79022  -0.55474   0.26040

S =
Diagonal Matrix
  3.6555e+000            0            0
            0  1.0452e+000            0
            0            0  1.4645e-016

V =
   0.433921   0.691650   0.577350
   0.382026  -0.721611   0.577350
   0.815947  -0.029962  -0.577350

> s= diag(S); k= sum(s> 1e-9) % simple thresholding based decision
k =  2

> Ainv= (U(:, 1: k)* diag(1./ s(1: k))* V(:, 1: k)')'
Ainv =
  -0.594055  -0.156258  -0.273302
   0.483170   0.193333   0.465592
  -0.110885   0.037074   0.192290

> A* Ainv
ans =
   0.982633   0.126045  -0.034317
   0.126045   0.085177   0.249068
  -0.034317   0.249068   0.932189

> A* pinv(A)
ans =
   0.982633   0.126045  -0.034317
   0.126045   0.085177   0.249068
  -0.034317   0.249068   0.932189

这篇关于MATLAB中最有效的矩阵求逆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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