how to substitute multiple variables of syms toolbox into matrix elements using subs function.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vatan Bedel
el 29 de Oct. de 2021
Comentada: Sulaymon Eshkabilov
el 30 de Oct. de 2021
Hello dear community,
I would like to create a matrix (5,1) of functions using variables that are defined in syms toolbox using for loop to decrease manual work. yet, when I try to assign the function into a cell value by subs I get an error as follow: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters. In attach you can see my code, and related info. Thnak you very much for your valuable time and help in advance.
PS: The image shows the formula that I am trying to obtain at the end to analyze a system, which has 6 nodes in total.
clc, clear all
syms u1 u2 u3 u4 u5 u6 phi1 phi2 phi3 phi4 phi5 phi6
r = 0.01; %ohm/km
x = 0.1; %ohm/km
l13 = 200; %km
l24 = 160; %km
l34 = 80; %km
l35 = 100; %km
l46 = 125; %km
z13 = l13*(r+1j*x); %ohm
z24 = l24*(r+1j*x); %ohm
z34 = l34*(r+1j*x); %ohm
z35 = l35*(r+1j*x); %ohm
z46 = l46*(r+1j*x); %ohm
g13 = 1/z13; %S
g24 = 1/z24; %S
g34 = 1/z34; %S
g35 = 1/z35; %S
g46 = 1/z46; %S
%addmittance matrix
G = [g13 0 -g13 0 0 0;...
0 g24 0 -g24 0 0;...
-g13 0 g13+g34+g35 -g34 -g35 0;...
0 -g24 -g34 g24+g34+g46 0 -g46;...
0 0 -g35 0 g35 0;...
0 0 0 -g46 0 g46];
display(G);
[Yang, Ymag] = cart2pol(real(G), imag(G));
display(Ymag);
display(Yang);
%input data
p1 = -2e6; %W
q1 = -1j*0.5e6; %VAr
s1 = p1 + q1; %MVA
p2 = -2.5e6; %W
q2 = +1j*1e6; %VAr
s2 = p2 + q2; %MVA
p3 = 0e6; %W
q3 = +1j*0e6; %VAr
s3 = p3 + q3; %MVA
p4 = 0e6; %W
q4 = +1j*0e6; %VAr
s4 = p4 + q4; %MVA
u5 = 20e3*exp(1j*deg2rad(0)); %V
u5mag = abs(u5); %V
phi5 = angle(u5); %rad
u6mag = 20e3; %V
p6 = 2.9e6; %W
u = [u1; u2; u3; u4; u5; u6];
phi = [phi1; phi2; phi3; phi4; phi5; phi6];
% F = matlabFunction([F1; F2; F3; F4; F6]);
F = zeros(5,1);
for j=1:5
for k=1:5
if k~=j
F(j) = subs(Ymag(j,j)*u(j)^2*cos(-Yang(j,j))-(u(j)*(Ymag(j,k)*u(k)*cos(phi(j)-phi(k)-Yang(j,k))));
end
end
end
disp([F]);

0 comentarios
Respuesta aceptada
Sulaymon Eshkabilov
el 30 de Oct. de 2021
Note that you don't need subs instead you'd need to save all calc values in a cell array. Here is the corrected part of your code:
...
H = cell(5,1);
for j=1:5
for k=1:5
if k~=j
F= Ymag(j,j)*u(j)^2*cos(-Yang(j,j))-(u(j)*(Ymag(j,k)*u(k)*cos(phi(j)-phi(k)-Yang(j,k))));
H(j) ={F};
end
end
end
celldisp(H);
2 comentarios
Más respuestas (1)
Walter Roberson
el 30 de Oct. de 2021
F(j) = subs(Ymag(j,j)*u(j)^2*cos(-Yang(j,j))-(u(j)*(Ymag(j,k)*u(k)*cos(phi(j)-phi(k)-Yang(j,k))));
1 0 1 2 1 2 1 2 3 21 2 3 2 3 4 3 4 3 4 5 4 5 4 5 4321
The digit is the number of open bracket levels "after" the character the digit is below.
Notice at the end the digit is 1. There is one unclosed bracket. You are missing one )
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!