solving complex matrix with symbolic variables

21 vues (au cours des 30 derniers jours)
ZENONG
ZENONG le 22 Juin 2023
Réponse apportée : Torsten le 22 Juin 2023
hello, I am trying to solve a complex matrix with symbols, but it returns''Empty sym: 0-by-1''. I would like to know why this happened and how could I solve this problem. Thank you.
  1 commentaire
ZENONG
ZENONG le 22 Juin 2023
Hi, I updated my code, and it retured values, but I believe there still are some errors, maybe the ''theta'' and ''abs'' variables?

Connectez-vous pour commenter.

Réponse acceptée

Vishnu
Vishnu le 22 Juin 2023
Hi Zenong,
From the code, it seems that you are trying to solve the complex matrix equations using symbolic variables.However, the issue is that the variables used for 'VI' and 'Vscl' are not symbolic variables, and this is causing the error "Empty sym: 0-by-1".
To solve this issue, the you need to define symbolic variables 'p1', 'q1', 'p2', 'q2', 'p3', 'q3', 'p4' and 'q4' using 'syms' function.
syms a b c d e f g h k p1 p2 p3 p4 q1 q2 q3 q4
Here is the modified code:
syms a b c d e f g h k real %defining symbolic variables
z1=-30j;
z2=0.08+0.40j;
z3=-35j;
z4=0.10+0.50j;
z5=0.10+0.50j;
z6=-25j;
z7=0.30j;
p1=a;
p2=0.55;
p3=0.30;
p4=0.50;
q1=1j*b;
q2=0.15j;
q3=0.201j;
q4=1j*c;
e1=1.05;
e2=d;
e3=e;
e4=f;
f1=0j;
f2=1j*g;
f3=1j*h;
f4=1j*k;
y11=1/z1+1/z2+1/z5;
y12=(-1)*1/z2;
y13=(-1)*1/z5;
y14=0;
y21=y12;
y22=1/z2+1/z4+1/z3;
y23=(-1)*1/z4;
y24=0;
y31=y13;
y32=y23;
y33=1/z6+1/z7+1/z5+1/z4;
y34=0;
y41=y14;
y42=y24;
y43=y34;
y44=1/z7;
Y=[y11,y12,y13,y14;
y21,y22,y23,y24;
y31,y32,y33,y34;
y41,y42,y43,y44];
conjY=conj(Y); %conjugate Y
V=[e1+f1;e2+f2;e3+f3;e4+f4];
format shortG
conjY=round(conjY,2,'significant') %conjugate Y
Vscl=diag(V) %scalar matrix V
conjV=conj(V) %conjugate V
%Defining symbolic variables
syms a b c d e f g h k p1 p2 p3 p4 q1 q2 q3 q4
[a,b,c,d,e,f,g,h,k] = solve([p1+q1;p2+q2;p3+q3;p4+q4]==Vscl*conjY*conjV,[a,b,c,d,e,f,g,h,k]);

Plus de réponses (2)

MANIK
MANIK le 22 Juin 2023
Modifié(e) : MANIK le 22 Juin 2023
As per my understanding, you're trying to solve a complex matrix equation in MATLAB
Well, I was going through your code, it is all correct. But, here you're trying to solve a problem, which contains 4 equations and 9 variables which is not possible. That's why you're getting an error here.

Torsten
Torsten le 22 Juin 2023
syms a b c d e f g h k real
z1=-30j;
z2=0.08+0.40j;
z3=-35j;
z4=0.10+0.50j;
z5=0.10+0.50j;
z6=-25j;
z7=0.30j;
p1=a;
p2=-0.55;
p3=-0.30;
p4=0.50;
q1=1j*b;
q2=-0.15j;
q3=-0.20j;
q4=1j*c;
e1=1.05;
e2=d;
e3=e;
e4=f;
f1=0j;
f2=1j*g;
f3=1j*h;
f4=1j*k;
y11=1/z1+1/z2+1/z5;
y12=(-1)*1/z2;
y13=(-1)*1/z5;
y14=0;
y21=y12;
y22=1/z2+1/z4+1/z3;
y23=(-1)*1/z4;
y24=0;
y31=y13;
y32=y23;
y33=1/z6+1/z7+1/z5+1/z4;
y34=(-1)*1/z7;
y41=y14;
y42=y24;
y43=y34;
y44=1/z7;
theta=f^2+k^2;
abs=1.1^2;
Y=[y11,y12,y13,y14;
y21,y22,y23,y24;
y31,y32,y33,y34;
y41,y42,y43,y44];
conjY=conj(Y);
V=[e1+f1;e2+f2;e3+f3;e4+f4];
format shortG
conjY=round(conjY,2,'significant');
Vscl=diag(V);
conjV=conj(V);
VIt=Vscl*conjY*conjV;
P=simplify([real([p1;p2;p3;p4]);imag([q1;q2;q3;q4]);theta])
P = 
Q=simplify([real(VIt);imag(VIt);abs])
Q = 
sol=vpasolve(P==Q)
sol = struct with fields:
a: [4×1 sym] b: [4×1 sym] c: [4×1 sym] d: [4×1 sym] e: [4×1 sym] f: [4×1 sym] g: [4×1 sym] h: [4×1 sym] k: [4×1 sym]
sol.a
ans = 
sol.b
ans = 
sol.c
ans = 
sol.d
ans = 
sol.e
ans = 
sol.f
ans = 
sol.g
ans = 
sol.h
ans = 
sol.k
ans = 
error = arrayfun(@(i)subs(P-Q,[a b c d e f g h k],[sol.a(i) sol.b(i) sol.c(i) sol.d(i) sol.e(i) sol.f(i) sol.g(i) sol.h(i) sol.k(i)]),1:4,'UniformOutput',0)
error = 1×4 cell array
{9×1 sym} {9×1 sym} {9×1 sym} {9×1 sym}
error{1}
ans = 
error{2}
ans = 
error{3}
ans = 
error{4}
ans = 

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by