inverse of a matrix wrong??
Show older comments
Hello community,
I've just written this code:
close all
clear all
clc
s = tf('s');
A = [0 , 1 ; -2 , -3]
B = [1 ; 0]
I = [1 , 0 ; 0 , 1]
L = s*I-A;
Linv = inv(L)
and it's not equal to my counts that I've done on the paper; infact the L matrix should be
s+3/(s^2+3*s+2) 1/(s^2+3*s+2)
-2/(s^2+3*s+2) s/(s^2+3*s+2)
while in matlab the last fraction ( row 2 , column 2) is: (s + 8.438e-15)/(s^2+3*s+2)
Answers (1)
Walter Roberson
on 7 Sep 2019
0 votes
It is not wrong, but it is subject to round-off error; it also is not being simplified.
5 Comments
Giovanni Salviati
on 7 Sep 2019
Walter Roberson
on 7 Sep 2019
To calculate it without round-off error you will probably need to switch to Symbolic Toolbox
syms S
inv([S, -1;2, S+3])
Giovanni Salviati
on 8 Sep 2019
Giovanni Salviati
on 8 Sep 2019
Edited: Giovanni Salviati
on 8 Sep 2019
Walter Roberson
on 8 Sep 2019
The underlying code for tf and ss systems works with pure numeric matrices, and those have round off errors in calculations of matrix inverse. Matrix inverse numeric calculations are not done according to the formal definition of matrix inverse, because those calculations can take a long time.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!