Why do I get different results for the same inverse calculation in command line and a function?
Show older comments
I have a matrix M =
0.0719 0.1797 -0.0621 -0.0279
0.1797 0.9838 -0.6216 -0.3661
-0.0621 -0.6216 0.5026 0.3248
-0.0279 -0.3661 0.3248 0.2173
and want to calculate its inverse:
M_inverse = inv(M);
But the solution is different when I do it in command line to when I do it in a function. The numbers and code are exactly the same, but when I use the function it gives a warning (in command line it does not!):
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.116735e-18.
Why do the results differ? Calculating the inverse outside matlab states that the command line solution is correct whilst the useage of inv in a function produces a false conditioning number and false solution. I use Matlab r2015b.
Thank you in advance for your answers.
3 Comments
Marcel Usai
on 15 Jun 2017
Adam
on 15 Jun 2017
Post all your code from the function and double check that the matrix is absolutely identical.
JohnGalt
on 15 Jun 2017
I suspect your command window matrix M has greater precision than the one in the file/function... In the command window, to see if this is the case, try:
num2str(M)
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!