I'm getting the inv error code saying it must be squared

I can't find where my error is, can some one help please
My code is :
E1=3;
E2=2;
Z1= j*10e-03;
Z2= 1.5e03;
Z3= -j* 0.1e-06;
Z4= j*1e-03;
Z5= -j*1e-06;
Z6= 10e03;
Z= [(Z1+Z2+Z3) (-Z3); (-Z3) (Z3+Z4+Z5); (Z5+Z6) (-Z5)]
Z =
1.0e+04 *
0.1500 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i
1.0000 - 0.0000i 0.0000 + 0.0000i
E= [E1;0;-E2]
E =
3
0
-2
I = inv(Z)*E
Error using inv
Matrix must be square.

 Respuesta aceptada

Avoid using inv(); it is not as mathematically stable as the alternatives.
format long g
E1=3;
E2=2;
Z1= j*10e-03;
Z2= 1.5e03;
Z3= -j* 0.1e-06;
Z4= j*1e-03;
Z5= -j*1e-06;
Z6= 10e03;
Z= [(Z1+Z2+Z3) (-Z3); (-Z3) (Z3+Z4+Z5); (Z5+Z6) (-Z5)]
Z =
1500 + 0.0099999i 0 + 1e-07i 0 + 1e-07i 0 + 0.0009989i 10000 - 1e-06i 0 + 1e-06i
E= [E1;0;-E2]
E = 3×1
3 0 -2
I = Z\E
I =
-0.000151589225999787 - 2.93415473517444e-10i 3.15167210679577e-06 + 0.161724791615002i
Z*I
ans =
-0.227383855169225 - 1.95599999618422e-06i -0.000161546894344196 + 3.13304634487832e-09i -1.51589242172266 - 2.93399999427634e-06i
You wil notice that this is not really a good match for E -- but it is the version of I that give the least-squared error compared to E. You have an over-determined system, so you cannot get a perfect fit.

Más respuestas (1)

Voss
Voss el 14 de Dic. de 2021
Editada: Voss el 14 de Dic. de 2021
inv takes the inverse of a square matrix (that is, a matrix with size n-by-n for some n). In this case you are trying to take the inverse of the matrix Z, but Z is not square (it's 3-by-2), so you get that error. Check that your definition of Z is correct.

Categorías

Etiquetas

Preguntada:

el 14 de Dic. de 2021

Comentada:

el 14 de Dic. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by