the inverse of a symbolic matrix using inv is not correct
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to calculate the incerse of a matrix symbolically, I am using the command inv that matlab suggest, when i try with the following code to multiply sigma times their inverse i have the identity matrixm and that is telling me the inverse is ok.
b1 = sym('b1');
b2 = sym('b2');
c = sym('c');
psi = sym('psi');
K=sym('K');
N1=sym('N1');
N2=sym('N2');
r=sym('r');
mu1=sym('mu1');
mu2=sym('mu2');
rho=sym('rho');
q=sym('q');
a1=sym('a1');
a2=sym('a2');
T=[b1+K*N1 r*K*N1; c*psi*q*N2 b2];
sigma11= mu1+a1+psi*q*N2;
sigma12=0;
sigma21=0;
sigma22= mu2+a2;
sigma=[sigma11 sigma12; sigma21 sigma22];
sigmainverse=inv(sigma);
times=sigma*sigmainverse
I have as output the identity so is great. The problem is that when I do the same thing with a different matrices I have a different output (not the identitiy), what am I doing wrong? Here is the code:
b11 = sym('b11');
b22 = sym('b22');
b12 = sym('b12');
b21 = sym('b21');
K1=sym('K1');
K2=sym('K2');
N1=sym('N1');
N2=sym('N2');
r1=sym('r1');
r2=sym('r2');
mu1=sym('mu1');
mu2=sym('mu2');
a12=sym('a12');
a21=sym('a21');
rho=sym('rho');
T=[b11 0; 0 b22];
sigma11= -mu1-r1*N1/K1-r1*a12*N2/K1;
sigma12=b12;
sigma21=b21;
sigma22= -mu2-r2*N2/K2-r2*a21*N1/K2;
sigmaok=[sigma11 sigma12; sigma21 sigma22];
sigmainverse=inv(sigmaok);
times=sigmaok*sigmainverse;
Why is this?
Thanks
0 comentarios
Respuestas (1)
John D'Errico
el 9 de Jul. de 2016
Editada: John D'Errico
el 9 de Jul. de 2016
Oh. So this is not an identity matrix?
simplify(sigmaok*sigmainverse)
ans =
[ 1, 0]
[ 0, 1]
That darn new math. Why must they keep changing things on me?
SOMETIMES, you need to use tools like simplify. Computers can be surprisingly silly at times, needing an extra hint, a little help.
4 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!