How to compute inverse of a matrix accurately?

独自空忆成欢 提交于 2019-11-26 17:09:15

问题


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?


回答1:


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\b 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 = A\B 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.




回答2:


You have what's called an ill-conditioned matrix. It's risky to try to take the inverse of such a matrix. In general, taking the inverse of anything but the smallest matrices (such as those you see in an introduction to linear algebra textbook) is risky. If you must, you could try taking the Moore-Penrose pseudoinverse (see Wikipedia), but even that is not foolproof.



来源:https://stackoverflow.com/questions/36166599/how-to-compute-inverse-of-a-matrix-accurately

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!