indices must either be real?

1 view (last 30 days)
arian hoseini
arian hoseini on 24 Jun 2023
Commented: Image Analyst on 24 Jun 2023
at line 101 i get this error dont know why??????
% Radial network-reactive and active load-current
clear all;
clc;
%V:network voltage
%q:number of loads
%w:number of lines
%f:frequency
%real:Real section of load current
%image:Image section of load current
%a:matrix of load current
%L:inductance of each line (H/m)
%L_line:inductance of total line
%X:reactance of each line
%R:Resistance of each line
%I:Current of each line
%SLoad:power of each load
%P_Load:Active power of each load
%Q_Load:Reactive power of each load
%P_loss_line:Active power loss of each line
%Q_loss_line:Reactive power loss of each line
%P_loss_total:Active power loss of total network
%Q_loss_total:Reactive power loss of total network
%P_input:Input active power
%Q_input:Input reactive power
V=input('insert voltage of network(V)= ');
f=input('insert frequency of network(Hz)=');
q=input('insert number of load=');
w=q;
for n=1:q
disp('Load')
disp(n)
real(n,1)=input('insert Real current of load (A)= ');
image(n,1)=input('insert Image current of load (A)= ');
end
a=real+i*image;
disp('Guide')
disp(' if you want Specific electrical conductivity (s/mm^2), insert 1, and if you want Specific electrical resistance (ohm.mm^2), insert 2')
e=input('Specific electrical conductivity or Specific electrical resistance of lines= ');
if e==1
t=input('insert Specific electrical conductivity (s/mm^2)= ');
end
if e==2
t=input('insert Specific electrical resistance (ohm.mm^2)= ');
end
A=input('insert area of lines (mm^2)= ');
L=input('insert inductance of line(H/m)=');
for n=1:w
disp('Line')
disp(n)
l(n,1)=input('insert lenght of line(m)= ');
end
if e==1
for n=1:w
R(n,1)=l(n,1)/(t*A);
end
end
if e==2
for n=1:w
R(n,1)=t*l(n,1)/(A);
end
end
for n=1:w
L_line(n,1)=L*l(n,1);
end
for n=1:w
X(n,1)=2*pi*f*L_line(n,1);
end
I(n,1)=0;
for n=1:w
for m=n:q
I(n,1)=I(n,1)+a(m,1);
end
end
for n=1:w
deltaV(n,1)=2*(R(n,1)+i*X(n,1))*I(n,1);
end
voltage_bus(1,1)=V;
for n=2:q+1
voltage_bus(n,1)=voltage_bus(n-1,1)-deltaV(n-1,1);
end
voltage_Regulation=100*((V-abs(voltage_bus(q+1,1)))/abs(voltage_bus(q+1,1)));
for n=1:q
SLoad(n,1)=voltage_bus(n+1,1)*conj(a(n,1));
end
for n=1:w
P_loss_line(n,1)=2*R(n,1)*(abs(I(n,1))^2);
end
P_loss_total=0;
for n=1:w
P_loss_total=P_loss_total+P_loss_line(n,1);
end
for n=1:q
Q_loss_line(n,1)=2*X(n,1)*(abs(I(n,1))^2);
end
Q_loss_total=0;
for n=1:w
Q_loss_total=Q_loss_total+Q_loss_line(n,1);
end
P_Load=0;
Q_Load=0;
P_Load=real(SLoad);
Q_Load=imag(SLoad);
P_Load_total=sum(P_Load);
Q_Load_total=sum(Q_Load);
P_input=P_Load_total+P_loss_total;
Q_input=Q_Load_total+Q_loss_total;
Efficiency=P_Load_total/P_input;
clc;
disp('Resisrance(R) of each line:')
disp(R)
disp('reactance(X) of each line:')
disp(X)
disp('Current of each line:')
disp(I)
disp('Voltage drop of each line:')
disp(deltaV)
disp('voltage of each bus:')
disp(voltage_bus)
disp('voltage Regulation(%)')
disp(voltage_Regulation)
disp('S of each load(VA):')
disp(SLoad)
disp('Active power(P) of each load(W):')
disp(P_load)
disp('Reactive power(Q) of each load(VAR):')
disp(Q_load)
disp('Power loss of each line(W)')
disp(P_loss_line)
disp('Reactive power of each line(VAR)')
disp(Q_loss_line)
disp('Total power loss(W):')
disp(P_loss_total)
disp('Total reactive power loss(VAR):')
disp(Q_loss_total)
disp('Input power(W):')
disp(P_input)
disp('Input reactive power(VAR):')
disp(Q_input)
disp('Efficiency:')
disp(Efficiency)

Accepted Answer

DGM
DGM on 24 Jun 2023
Edited: DGM on 24 Jun 2023
You're creating a variable called real, which conflicts with the function real(). Consequentially, when you try to call real() on a complex scalar, you're actually trying to index into the array of the same name using a complex-valued index.
Simply name your variable something else.
  2 Comments
arian hoseini
arian hoseini on 24 Jun 2023
oooooh what a simple mistake...really thanks
Image Analyst
Image Analyst on 24 Jun 2023
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!