Code Analyzer has detected a call to inv
in a multiplication
operation.
For solving a system of linear equations, the inverse of a matrix is primarily
of theoretical value. Never use the inverse of a matrix to solve a linear system
Ax=b
with x=inv(A)*b
, because it is
slow and inaccurate.
Instead of multiplying by the inverse, use matrix right division
(/
) or matrix left division (\
). That is:
Replace inv(A)*b
with
A\b
Replace b*inv(A)
with
b/A
In longer expressions, parentheses might be necessary to preserve the order of
operations. For example, replace A*inv(B)*C
with
A*(B\C)
.
Frequently, an application needs to solve a series of related linear systems
Ax=b
, where A
does not change, but
b
does. In this case, use lu
, chol
, or qr
instead of
inv
,
depending on the matrix type.