matlab - Code Analyzer: INV is slow and inaccurate -


when try calculate matrix inverse using matlab's inv() operation:

a = rand(10,10); b = rand(10,1);  c = inv(a); d = c*b; 

i following warning @ last row: inv slow , inaccurate. use a\b inv(a)*b , , b/a b*inv(a).

i can change code above into:

a = rand(10,10); b = rand(10,1);  c = inv(a); d = a\b; 

now don't warning, don't think solution better.

note: need store both inverse of matrix inv(a)*c. also, in real file size of matrix can 5000 x 5000 or bigger.

are there better solutions in terms of efficiency , accuracy or first method fine?

you should listen matlab , use second option. inv(a)*b , a\b computed different algorithms under hood, , \ indeed more accurate.

the documentation inv states:

in practice, seldom necessary form explicit inverse of matrix. frequent misuse of inv arises when solving system of linear equations ax = b. 1 way solve x = inv(a)*b. better way, both execution time , numerical accuracy standpoint, use matrix division operator x = a\b. produces solution using gaussian elimination, without forming inverse. see mldivide () further information.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -