Hi, I updated my code, and it retured values, but I believe there still are some errors, maybe the ''theta'' and ''abs'' variables?
solving complex matrix with symbolic variables
조회 수: 4 (최근 30일)
이전 댓글 표시
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.
채택된 답변
Vishnu
2023년 6월 22일
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]);
댓글 수: 0
추가 답변 (2개)
MANIK
2023년 6월 22일
편집: MANIK
2023년 6월 22일
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.
댓글 수: 0
Torsten
2023년 6월 22일
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])
Q=simplify([real(VIt);imag(VIt);abs])
sol=vpasolve(P==Q)
sol.a
sol.b
sol.c
sol.d
sol.e
sol.f
sol.g
sol.h
sol.k
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}
error{2}
error{3}
error{4}
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!