如何准确计算矩阵的逆? [英] How to compute inverse of a matrix accurately?

查看:34
本文介绍了如何准确计算矩阵的逆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算矩阵 P 的逆矩阵,但是如果我乘以 inv(P)*P,MATLAB 不会返回单位矩阵.这几乎是身份(10^(-12) 顺序的非对角线值).但是,在我的应用程序中,我需要更高的精度.

在这种情况下我该怎么办?

解决方案

仅当您明确需要您使用的矩阵的逆


作为10^(-12) 数量级误差的旁注,除了上述 inv() 函数的不准确性外,还有浮点数准确性.这篇关于 MATLAB 问题的帖子非常有见地,上面有一篇更一般的计算机科学帖子此处.基本上,如果您正在计算数字,请不要担心(至少是过度担心)小 12 个数量级的错误.

I'm trying to compute an inverse of a matrix P, but if I multiply inv(P)*P, the MATLAB does not return the identity matrix. It's almost the identity (non diagonal values in the order of 10^(-12)). However, in my application I need more precision.

What can I do in this situation?

解决方案

Only if you explicitly need the inverse of a matrix you use inv(), otherwise you just use the backslash operator .

The documentation on inv() explicitly states:

x = A is computed differently than x = inv(A)*b and is recommended for solving systems of linear equations.

This is because the backslash operator, or mldivide() uses whatever method is most suited for your specific matrix:

x = AB solves the system of linear equations A*x = B. The matrices A and B must have the same number of rows. MATLAB® displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.

Just so you know what algorithm MATLAB chooses depending on your input matrices, here's the full algorithm flowchart as provided in their documentation

The versatility of mldivide in solving linear systems stems from its ability to take advantage of symmetries in the problem by dispatching to an appropriate solver. This approach aims to minimize computation time. The first distinction the function makes is between full (also called "dense") and sparse input arrays.


As a side-note about error of order of magnitude 10^(-12), besides the above mentioned inaccuracy of the inv() function, there's floating point accuracy. This post on MATLAB issues on it is rather insightful, with a more general computer science post on it here. Basically, if you are computing numerics, don't worry (too much at least) about errors 12 orders of magnitude smaller.

这篇关于如何准确计算矩阵的逆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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