# GIÁO TRÌNH hệ THỐNG điện phu luc

Phụ lục: Chương trình Matlab

PHỤ LỤC
CHƯƠNG TRÌNH MATLAB
P1.1. Chương trình Matlab cho chương 1
[Chapter1ex1]
------------Um = 250; tetau = 0;
Zt=1+j*7;
Z=abs(Zt);
gama=angle(Zt)*180/pi;
tetai = tetau - gama;
teta = (tetau - tetai)*pi/180;
Im = Um/Z;
wt=0:.05:5*pi;
u=Um*cos(wt);
i=Im*cos(wt + tetai*pi/180);
p=u.*i;
U=Um/sqrt(2); I=Im/sqrt(2);
P = U*I*cos(teta);
Q = U*I*sin(teta);
S = P + j*Q

pr = P*(1 + cos(2*(wt + tetau)));
px = Q*sin(2*(wt + tetau));
PP=P*ones(1, length(wt));
xline = zeros(1, length(wt));
wt=180/pi*wt;
subplot(2,2,1), plot(wt, u, wt, i,wt, xline), grid
title(['u(t)=Um coswt, i(t)=Im cos(wt +', num2str(tetai), ')'])
xlabel('wt, Do')
subplot(2,2,2), plot(wt, p, wt, xline), grid
title('p(t)=u(t) i(t)'), xlabel('wt, Do')
subplot(2,2,3), plot(wt, pr, wt, PP, wt,xline), grid
title('pr(t)
Pt 2.04'), xlabel('wt, Do')
subplot(2,2,4), plot(wt, px, wt, xline), grid
title('px(t) Pt 2.05'), xlabel('wt, Do')
subplot(111)
----------------------------------------------------------------------[Chapter1ex2]
------------E1=input('Bien do dien ap nguon 1.
a1=input('Goc pha dien ap nguon 1.
E2=input('Bien do dien ap nguon 2.
a2=input('Goc pha dien ap nguon 2.
R=input('Dien tro day dan = ');
X= input('Dien khang day dan = ');
Z= R + j*X;
a1=a1*pi/180;
a2=a2*pi/180;
U1=E1*cos(a1) + j*E1*sin(a1);
U2=E2*cos(a2) + j*E2*sin(a2);
I12 = (V1 - V2)/Z;
I21=-I12;
I12p=abs(I12)
gocphaI12=angle(I12)*180/pi
I21p=abs(I21)
gocphaI21=angle(I21)*180/pi
S12= U1*conj(I12)

=
=
=
=

');
');
');
');

175

Phụ lục: Chương trình Matlab
P1 = real(S12);
Q1 = imag(S12);
S21= U2*conj(I21)
P2 = real(S21);
Q2 = imag(S21);
SL= S12+S21
PL = real(SL); QL = imag(SL);
S12p=abs(S12)
gocphaS12=angle(S12)*180/pi
S21p=abs(S21)
gocphaS21=angle(S21)*180/pi

-----------------------------------------------------------[Chapter1ex3]
------------E1=input('Bien do dien ap nguon 1. = ');
a1=input('Goc pha dien ap nguon 1. = ');
E2=input('Bien do dien ap nguon 2. = ');
a2=input('Goc pha dien ap nguon 2. = ');
R=input('Dien tro day dan = ');
X= input('Dien khang day dan = ');
Z= R + j*X;
% Tong tro day
a1 = (-30+a1:5:30+a1)';
% tao day thay doi
a1r = a1*pi/180;
k=length(a1);
a2=ones(k,1)*a2;
% tao day thay doi
a2r = a2*pi/180;
U1=E1.*cos(a1r) + j*E1.*sin(a1r);
U2=E2.*cos(a2r) + j*E2.*sin(a2r);
I12 = (V1 - V2)/Z; I21=-I12;
S1= U1.*conj(I12); P1 = real(S1); Q1 = imag(S1);
S2= U2.*conj(I21); P2 = real(S2); Q2 = imag(S2);
SL= S1+S2;
PL = real(SL); QL = imag(SL);
Result1=[a1, P1, P2, PL];
disp('
Delta 1
P-1
P-2
P-L ')
disp(Result1)
plot(a1, P1, a1, P2, a1, PL), grid
text(-26, -550, 'P1'), text(-26, 600,'P2'), text(-26, 100, 'ton that cs')
xlabel('Goc pha dien ap cua nguon 1'), ylabel('P, Watts')

-------------------------------------------------------------

P1.2. Chương trình Matlab cho chương 2
[Chapter2ex1]
------------GMR = (exp(1)^(-0.25)*2^6*3^(6/7)*2^(6/7))^(1/7);
fprintf('GMR = %5.4fr \n', GMR)
------------------------------------------------------------------------

[Chapter2ex2]
------------r = (3.416*10^-2)/2;
GMRL = 1.3533*10^-2;
GMD = (12.5*12.5*25)^(1/3)
L = 0.2*log(GMD/GMRL)
C=0.0556/log(GMD/r)

------------------------------------------------------------

176

Phụ lục: Chương trình Matlab

P1.3. Chương trình Matlab cho chương 3
[Chapter3ex1]
------------Ra=0; Xs = 0.3; Zs = Ra + j*Xs;
AR = acos(0.75);
S = 0.75*(cos(AR) + j*sin(AR));
Ia1 = conj(S)/(3*conj(V));
Ia1M = abs(Ia1), Ia1ang=angle(Ia1)*180/pi
E1 = V + Zs*Ia1;
E1M = abs(E1), delta1 = angle(E1)*180/pi
disp('(b)')
P = 0.6;
delta2 = asin(P*Xs/(3*E1M*V));
delta2d = delta2*180/pi
E2 = E1M*(cos(delta2) +j*sin(delta2));
Ia2 = (E2 - V)/Zs; Ia2M = abs(Ia2), Ia2ang=angle(Ia2)*180/pi
PF = cos(angle(Ia2))
disp('(c)')
Pmax = 3 *E1M*V/Xs
E3 = E1M*(cos(pi/2) +j*sin(pi/2));
Ia3 = (E3 -V)/Zs;
Ia3M = abs(Ia3), Ia3ang=angle(Ia3)*180/pi
PF = cos(angle(Ia3))

------------------------------------------------------------[Chapter3ex3]
------------clear all
r = .1; g = 0; f = 50;
L = 0.0012;
% H
C = 0;
% microF
Length = 60; VR3ph = 110;
VR = VR3ph/sqrt(3) + j*0;
% kV
z = r + j*2*pi*f*L; ; Z = z*Length;
R = real(Z); X = imag(Z);
y = g + j*2*pi*f*C/1000000;
Y = y*Length;
A = 1 + Z*Y/2; B = Z;
C = Y*(1 + Z*Y/4); D = A;
ABCD=[A B
C D];
AR = acos(0.75);
SR = 150*(cos(AR) + j*sin(AR));
%
MVA
IR = conj(SR)/(3*conj(VR));
% kA
VsIs = ABCD* [VR; IR];
%
disp('(a)')
Vs = VsIs(1);
Vs3ph = sqrt(3)*abs(Vs);
% kV
Is = VsIs(2); Ism = 1000*abs(Is);
%
A
pfs= cos(angle(Vs)- angle(Is));
%
Ss = 3*Vs*conj(Is);
%
MVA
hstt=((real(SR))/real(Ss))*100;
REG = (Vs3ph/abs(ABCD(1,1)) - VR3ph)/VR3ph *100;
fprintf(' Is = %g A', Ism), fprintf(' pf = %g\n', pfs)
fprintf(' Vs = %g L-L kV\n', Vs3ph)
fprintf(' Ps = %g MW', real(Ss)),
fprintf(' Qs = %g Mvar\n', imag(Ss))
fprintf(' Hieu suat truyen tai = %g Mvar\n', hstt)
fprintf(' Phan tram sut ap = %g\n', REG)
%==================

177

Phụ lục: Chương trình Matlab
disp('(b)')
AR = -acos(0.75);
SR = 150*(cos(AR) + j*sin(AR));
%
MVA
IR = conj(SR)/(3*conj(VR));
% kA
VsIs = ABCD* [VR; IR];
%
Vs = VsIs(1);
Vs3ph = sqrt(3)*abs(Vs);
% kV
Is = VsIs(2); Ism = 1000*abs(Is);
%
A
pfs= cos(angle(Vs)- angle(Is));
%
Ss = 3*Vs*conj(Is);
%
MVA
hstt=((real(SR))/real(Ss))*100;
REG = (Vs3ph/abs(ABCD(1,1)) - VR3ph)/VR3ph *100;
fprintf(' Is = %g A', Ism), fprintf(' pf = %g\n', pfs)
fprintf(' Vs = %g L-L kV\n', Vs3ph)
fprintf(' Ps = %g MW', real(Ss)),
fprintf(' Qs = %g Mvar\n', imag(Ss))
fprintf(' Hieu suat truyen tai = %g Mvar\n', hstt)
fprintf(' Phan tram sut ap = %g\n', REG)

----------------------------------------------------------[Chapter3ex4]
------------r = .04; g = 0; f = 50;
L = 0.00075;
% H
C = 0.01;
% microF
Length = 100; VR3ph = 210;
VR = VR3ph/sqrt(3) + j*0;
% kV
z = r + j*2*pi*f*L; ; Z = z*Length;
R = real(Z); X = imag(Z);
y = g + j*2*pi*f*C/1000000;
Y = y*Length;
A = 1 + Z*Y/2; B = Z;
C = Y*(1 + Z*Y/4); D = A;
ABCD=[A B
C D];
AR = acos(0.75);
SR = 250*(cos(AR) + j*sin(AR));
%
MVA
IR = conj(SR)/(3*conj(VR));
% kA
VsIs = ABCD* [VR; IR];
%
Vs = VsIs(1);
Vs3ph = sqrt(3)*abs(Vs);
% kV
Is = VsIs(2); Ism = 1000*abs(Is);
%
A
pfs= cos(angle(Vs)- angle(Is));
%
Ss = 3*Vs*conj(Is);
%
MVA
REG = (Vs3ph/abs(ABCD(1,1)) - VR3ph)/VR3ph *100;
fprintf(' Is = %g A', Ism), fprintf(' pf = %g\n', pfs)
fprintf(' Vs = %g L-L kV\n', Vs3ph)
fprintf(' Ps = %g MW', real(Ss)),
fprintf(' Qs = %g Mvar\n', imag(Ss))
fprintf(' Phan tram sut ap = %g\n', REG)

----------------------------------------------------------[Chapter3ex7]
------------%==== CHUONG TRINH CHO VI DU 3.7====
clear all;
z = input('Nhap vao tong tro phuc noi tiep tren moi km z = ');
y = input('Nhap vao tong dan phuc tren moi km y = ');
l = input('Nhap vao chieu dai duong day l(km) = ');
gamma = sqrt(z*y); Zc = sqrt(z/y);
Z = Zc * sinh(gamma*l)
Y = 2/Zc * tanh(gamma*l/2)

178

Phụ lục: Chương trình Matlab
A = cosh(gamma*l); B = Zc*sinh(gamma*l);
C = 1/Zc * sinh(gamma*l); D = A;
ABCD = [A B; C D]
----------------------------------------------------------------------

[Chuongtrinh_tao tu truong quay]
ab=['
'
'
'
'
'
'
'
'
'
'
];

ROTATING MAGNETIC FIELD

'
'
Van de co ban cua may phat dien nhieu cuc la tu truong quay trong'
cua cac pha. Tat ca cac may phat dien xoay chieu deu co phan quay'
duoc goi la rotor va phan dung yen la stator. Cac thanh phan doi '
cua dong dien se tao ra cac tu truong quay doi xung co toc do phu'
thuoc vao cau truc cua stator. Toc do quay cua tu truong duoc goi'
la toc do dong bo. Rotor cua may dien dong bo duoc kich thich bo'
dong dien mot chieu co so cuc tu co dinh tuong ung voi toc do qua'
cua rotor de tao ra toc do qua cua tu truong la co dinh. Dieu nay'
co ban cua may phat dong bo.

disp(ab)
offset=pi/50;
tf=50;
theta=pi-offset;
theta=-pi/2;
dt=1; t =0;
clf

h1=axes('position',[.1 .55 .4 .4]);
axis([0 2*pi -4 4]); axis('off');
text(0.1, 3.5, 'fa'), text(2.1, 3.5, 'fb'),text(4.4, 3.5, 'fc'),
text(0.5, 4.35,'Thu thu thuan (Positive-phase sequence)')
line([0; 0],
[-4; 4],'color','w')
line([0; 6.3], [0; 0],'color','w')
text(-.3, 0,'0')

Displ1=line('xdata',[],'ydata',[],'linestyle','','color','r','erasemode','none');
Displ2=line('xdata',[],'ydata',[],'linestyle','','color','y','erasemode','non');
Displ3=line('xdata',[],'ydata',[],'linestyle','','color','b','erasemode','none');

h2=axes('position',[.1 .05 .4 .4]);
axis([0 2*pi -4 4]);axis('off');
text(0.1, 3.5, 'fa'), text(2.1, 3.5, 'fc'),text(4.4, 3.5, 'fb'),
text(0.5, 4.35,'Thu tu ngich (Negative-phase sequence)')
line([0; 0],
[-4; 4],'color','w')
line([0; 6.3], [0; 0],'color','w')
text(-.3, 0,'0')
Displ4=line('xdata',[],'ydata',[],'linestyle','','color','r','erasemode','none');
Displ5=line('xdata',[],'ydata',[],'linestyle','','color','b','erasemode','non');
Displ6=line('xdata',[],'ydata',[],'linestyle','','color','y','erasemode','none');

179

Phụ lục: Chương trình Matlab
h4=axes('position',[.58 .68 .3 .3]);
axis([-2. 2. -2. 2.]);
axis('equal')
text(-1.75, -2.3,'Tu truong quay thuan (Forward Rotating mmf)')
data1=[0 0; 2 0 ];
phi=0;
R1=[cos(phi) -sin(phi); sin(phi) cos(phi)];
bar1=line('xdata',data1(1,:),'ydata',data1(2,:),'linewidth',2,'color','g'
,'erase','xor');
hinge1=line('xdata',0,'ydata',0,'linestyle','o','color','r');
path1=line('xdata',[],'ydata',[],'linestyle','.','color','m','erasemode',
'none');
h3=axes('position',[.58 0 .3 .3]);
axis([-2. 2. -2. 2.]);
axis('equal')
text(-1.75, 2.3,'Tu truong quay ngich (Reverse Rotating mmf)')
text(-6.75, -1.5,'TU TRUONG QUAY TRONG MAY PHAT DONG BO BA PHA')
data2=[0 0; -2 0 ];
R2=[cos(phi) sin(phi); sin(phi) cos(phi)];
bar2=line('xdata',data2(1,:),'ydata',data2(2,:),'linewidth',2,'color','c'
,'erase','xor');
hinge2=line('xdata',0,'ydata',0,'linestyle','o','color','r');
path2=line('xdata',[],'ydata',[],'linestyle','.','color','m','erasemode',
'none');
for k=1:1:50
t=0:0.0005:k;
R1=[cos(theta) (-sin(theta)); sin(theta) cos(theta)];
datanew=R1*data1;
axes(h4); axis('off')
set(path1,'xdata',datanew(1,1),'ydata',datanew(2,1));
set(bar1,'xdata',datanew(1,:),'ydata',datanew(2,:));
R2=[cos(theta) (sin(theta)); sin(theta) cos(theta)];
datanew2=R2*data2;
axes(h3); axis('off')
set(path2,'xdata',datanew2(1,1),'ydata',datanew2(2,1));
set(bar2,'xdata',datanew2(1,:),'ydata',datanew2(2,:));
ia=3*cos(2*pi*t/tf);
ib=3*cos(2*pi*t/tf -2*pi/3);
ic=3*cos(2*pi*t/tf-4*pi/3);
axes(h1);
set(Displ1,'xdata',2*pi*t/50, 'ydata',ia);
set(Displ2,'xdata',2*pi*t/50, 'ydata',ib);
set(Displ3,'xdata',2*pi*t/50, 'ydata',ic);
axes(h2);
set(Displ4,'xdata',2*pi*t/50, 'ydata',ia);
set(Displ5,'xdata',2*pi*t/50, 'ydata',ib);
set(Displ6,'xdata',2*pi*t/50, 'ydata',ic);
drawnow;
end

-----------------------------------------------------------[Chapter3baitap10]
-----------------%==== CHUONG TRINH CHO BAI TAP 3.10 ====
clear all;
%z = input('Nhap vao tong tro phuc noi tiep tren moi km z = ');
%y = input('Nhap vao tong dan phuc tren moi km y = ');

180

Phụ lục: Chương trình Matlab
%l = input('Nhap vao chieu dai duong day l(km) = ');
%z = 0.04 + j*.39;
y = j*4.2/1000000; Length = 300;
%r =0; g = 0; f = 50;
%L = 0.0012;
% H
%C = 0.01;
% microF
VR3ph=220;
VR = VR3ph/sqrt(3) + j*0;
% kV
%z = r + j*2*pi*f*L;
%Z = j*0.6283*Length;
%R = real(Z); X = imag(Z);
%y = g + j*2*pi*f*C/1000000;
%Y = j*4.7124*Length/1000000;
A = 0.9055 + 0.0095i;
B =1.4952e+001 +1.5528e+002i;
C = -0.0000 + 0.0016i; D = A;
%gamma = sqrt(z*y); Zc = sqrt(z/y);
%Z = Zc * sinh(gamma*l)
%Y = 2/Zc * tanh(gamma*l/2)
%A = cosh(gamma*l); B = Zc*sinh(gamma*l);
%C = 1/Zc * sinh(gamma*l); D = A;
ABCD = [A B; C D]
AR = acos(0.85);
SR = 250*(cos(AR) + j*sin(AR));
%
MVA
IR = conj(SR)/(3*conj(VR));
% kA
VsIs = ABCD* [VR; IR];
%
%disp('(a)')
Vs = VsIs(1);
Vs3ph = sqrt(3)*abs(Vs);
% kV
Is = VsIs(2); Ism = 1000*abs(Is);
%
A
pfs= cos(angle(Vs)- angle(Is));
%
Ss = 3*Vs*conj(Is);
%
MVA
hstt=((real(SR))/real(Ss))*100;
REG = (Vs3ph/abs(ABCD(1,1)) - VR3ph)/VR3ph *100;
fprintf(' Is = %g A', Ism), fprintf(' pf = %g\n', pfs)
fprintf(' Vs = %g L-L kV\n', Vs3ph)
fprintf(' Ps = %g MW', real(Ss)),
fprintf(' Qs = %g Mvar\n', imag(Ss))
fprintf(' Hieu suat truyen tai = %g\n', hstt)
fprintf(' Phan tram sut ap = %g\n', REG)

----------------------------------------------------------[Chapter3baitap14]
-----------------%==== CHUONG TRINH CHO BAI TAP 3.14 ====
clear all;
%z = input('Nhap vao tong tro phuc noi tiep tren moi km z = ');
%y = input('Nhap vao tong dan phuc tren moi km y = ');
%l = input('Nhap vao chieu dai duong day l(km) = ');
z = 0.028 + j*.41;
y = 0 + j*4.6/1000000; Length = 350;
VR3ph = 500;
VR = VR3ph/sqrt(3) + j*0;
% kV
z = 0.04 + j*.39;
y = j*4.2/1000000; Length = 300;
gamma = sqrt(z*y); Zc = sqrt(z/y);
A = cosh(gamma*Length); B = Zc*sinh(gamma*Length);
C = 1/Zc * sinh(gamma*Length); D = A;
ABCD = [A B; C D]
Znew = Zc * sinh(gamma*Length)
Ynew = 2/Zc * tanh(gamma*Length/2)
Anew = 1 + Znew*Ynew/2; Bnew = Znew;
Cnew = Ynew*(1 + Znew*Ynew/4); Dnew = Anew;

181

Phụ lục: Chương trình Matlab
%gamma = sqrt(z*y); Zc = sqrt(z/y);
%Z = Zc * sinh(gamma*l)
%Y = 2/Zc * tanh(gamma*l/2)
%A = cosh(gamma*l); B = Zc*sinh(gamma*l);
%C = 1/Zc * sinh(gamma*l); D = A;
ABCD = [Anew Bnew; Cnew Dnew]
AR = acos(0.8);
SR = 150*(cos(AR) + j*sin(AR));
%
MVA
IR = conj(SR)/(3*conj(VR));
% kA
VsIs = ABCD* [VR; IR];
%
%disp('(a)')
Vs = VsIs(1);
Vs3ph = sqrt(3)*abs(Vs);
% kV
Is = VsIs(2); Ism = 1000*abs(Is);
%
A
pfs= cos(angle(Vs)- angle(Is));
%
Ss = 3*Vs*conj(Is);
%
MVA
hstt=((real(SR))/real(Ss))*100;
REG = (Vs3ph/abs(ABCD(1,1)) - VR3ph)/VR3ph *100;
fprintf(' Is = %g A', Ism), fprintf(' pf = %g\n', pfs)
fprintf(' Vs = %g L-L kV\n', Vs3ph)
fprintf(' Ps = %g MW', real(Ss)),
fprintf(' Qs = %g Mvar\n', imag(Ss))
fprintf(' Hieu suat truyen tai = %g\n', hstt)
fprintf(' Phan tram sut ap = %g\n', REG)

----------------------------------------------------------[Chapter3baitap15]
-----------------%==== CHUONG TRINH CHO BAI TAP 4.10 ====
clear all;
%z = input('Nhap vao tong tro phuc noi tiep tren moi km z = ');
%y = input('Nhap vao tong dan phuc tren moi km y = ');
%l = input('Nhap vao chieu dai duong day l(km) = ');
z = 0.028 + j*.41;
y = 0 + j*4.6/1000000; Length = 350;
VR3ph = 500;
VR = VR3ph/sqrt(3) + j*0;
% kV
gamma = sqrt(z*y); Zc = sqrt(z/y);
A = cosh(gamma*Length); B = Zc*sinh(gamma*Length);
C = 1/Zc * sinh(gamma*Length); D = A;
ABCD = [A B; C D]
Znew = Zc * sinh(gamma*Length)
Ynew = 2/Zc * tanh(gamma*Length/2)
Anew = 1 + Znew*Ynew/2; Bnew = Znew;
Cnew = Ynew*(1 + Znew*Ynew/4); Dnew = Anew;
%gamma = sqrt(z*y); Zc = sqrt(z/y);
%Z = Zc * sinh(gamma*l)
%Y = 2/Zc * tanh(gamma*l/2)
%A = cosh(gamma*l); B = Zc*sinh(gamma*l);
%C = 1/Zc * sinh(gamma*l); D = A;
ABCD = [Anew Bnew; Cnew Dnew]
AR = acos(0.8);
SR = 500*(cos(AR) + j*sin(AR));
%
MVA
IR = conj(SR)/(3*conj(VR));
% kA
VsIs = ABCD* [VR; IR];
%
disp('(a)')
Vs = VsIs(1);
Vs3ph = sqrt(3)*abs(Vs);
% kV
Is = VsIs(2); Ism = 1000*abs(Is);
%
A
pfs= cos(angle(Vs)- angle(Is));
%
Ss = 3*Vs*conj(Is);
%
MVA

182

Phụ lục: Chương trình Matlab
hstt=((real(SR))/real(Ss))*100;
REG = (Vs3ph/abs(ABCD(1,1)) - VR3ph)/VR3ph *100;
fprintf(' Is = %g A', Ism), fprintf(' pf = %g\n', pfs)
fprintf(' Vs = %g L-L kV\n', Vs3ph)
fprintf(' Ps = %g MW', real(Ss)),
fprintf(' Qs = %g Mvar\n', imag(Ss))
fprintf(' Hieu suat truyen tai = %g\n', hstt)
fprintf(' Phan tram sut ap = %g\n', REG)
disp('(b)')
Vr0=Vs/Anew;
Vr0L=Vr0*sqrt(3);
fprintf(' Dien ap khong tai cuoi doung day = %g\n', Vr0L)

--------------------------------------------------------

P1.4. Chương trình phân bố công suất
[Chuong trinh PBCS viet bang giai thuat Newton-Raphson]
clear TTCST TTT XTCST st1 A st2 ttn ttr st2kh1 SL st2kh2 st4 stTTT;
clear stdp stdd stdtt stdbd Ithuc MT3D NPU DT I xx yy zz Ik Ii TTCSTP;
fid=fopen('nhanhm.txt','r');
A=fscanf(fid,'%g %g %g %g %g',[5 inf]);
fclose(fid);
A=A';
N=max(A(:,2));
Z=zeros(N);
B=Z;
Y=Z;
G=Y;
BR=size(A);
BR=BR(1);
for k=1:BR
Z(A(k,1),A(k,2))= A(k,3)+1j*A(k,4);
Z(A(k,2),A(k,1))= Z(A(k,1),A(k,2));
B(A(k,1),A(k,2))= 1j*A(k,5);
B(A(k,2),A(k,1))= B(A(k,1),A(k,2));
end
Scb=100;
Ucb=220;
Z=Z*100/220^2;
for k=1:N
for l=1:N
if k~=l
if Z(k,l)~=0
Y(k,k)=Y(k,k)+Z(k,l)^-1+220^2/100*B(k,l);
end
end
end
end
for k=1:N-1
for l=k+1:N
if Z(k,l)~=0
Y(k,l)=-Z(k,l)^-1;
Y(l,k)=Y(k,l);
end
end
end
%----------------------ma tran goc-bien do-matran ao---------------------------G=angle(Y);
BY=abs(Y);
%-------------------cong suat-------------------------------------

183

Phụ lục: Chương trình Matlab
sstt=get(h0_cdt,'string');
sstt=sstt(get(h0_cdt,'value'),:);
sstt=deblank(sstt);
fid1=fopen(sstt,'r');
S=fscanf(fid1,'%g %g %g',[3 inf]);
fclose(fid1);
S=S';
Z2=zeros(N-1);
PB=Z2(:,1);
QB=PB;
Z3=ones(N-1);
SSCSA=Z3(:,1);
SSCST=SSCSA;
SSBD=PB;
SSDA=PB;
SSG=PB;
KQT=PB;
KQK=PB;
Z2=zeros(N-1);
for k=1:N-1
PB(S(k,1),1)=S(k,2);
QB(S(k,1),1)=S(k,3);
end
PB=PB/100;
QB=QB/100;
%-------------------------thuat giai N-R-------------------U1=zeros(N);
U2=U1(:,1);
U=U1(:,1);
U(1)=1.05;
U(2:N,1)=1;
sll=0;
BU=abs(U);
GU=angle(U);
ll=10;hh=0;
t1=cputime;
%while(sll<2)
while((SSCSA>0.001)&(SSCST>0.001))
P1=Z2(:,1);
P2=P1;
Q1=P1;
Q2=P1;
Z1=zeros(N-1);
J11=Z1;
J12=Z1;
J21=Z1;
J22=Z1;
for k=2:N
for l=1:N
if l~=k
P1(k-1)=BU(l)*BY(k,l)*sin(GU(k)-GU(l)-G(k,l));
J11((k-1),(k-1))=J11((k-1),(k-1))+P1(k-1);
end
end
J11((k-1),(k-1))=-BU(k)*J11((k-1),(k-1));
end
for k=1:N-1
for l=1:N-1
if l~=k
J11(k,l)=BU(k+1)*BU(l+1)*BY((k+1),(l+1))*sin(GU(k+1)-GU(l+1)G((k+1),(l+1)));

184

Phụ lục: Chương trình Matlab
end
end
end
%-------------------------J12------------------------------for k=2:N
for l=1:N
if l~=k
P2(k-1)=BU(l)*BY(k,l)*cos(GU(k)-GU(l)-G(k,l));
J12((k-1),(k-1))=J12((k-1),(k-1))+P2(k-1);
end
end
J12((k-1),(k-1))=J12((k-1),(k-1))+2*BU(k)*BY(k,k)*cos(-G(k,k));
end
for k=1:N-1
for l=1:N-1
if l~=k
J12(k,l)=BU(k+1)*BY((k+1),(l+1))*cos(GU(k+1)-GU(l+1)G((k+1),(l+1)));
end
end
end
%-------------------------------J21-----------------------for k=2:N
for l=1:N
if l~=k
Q1(k-1)=BU(l)*BY(k,l)*cos(GU(k)-GU(l)-G(k,l));
J21((k-1),(k-1))=J21((k-1),(k-1))+Q1(k-1);
end
end
J21((k-1),(k-1))=BU(k)*J21((k-1),(k-1));
end
for k=1:N-1
for l=1:N-1
if l~=k
J21(k,l)=-BU(k+1)*BU(l+1)*BY((k+1),(l+1))*cos(GU(k+1)-GU(l+1)G((k+1),(l+1)));
end
end
end
%-----------------------------J22-------------------------for k=2:N
for l=1:N
if l~=k
Q2(k-1)=BU(l)*BY(k,l)*sin(GU(k)-GU(l)-G(k,l));
J22((k-1),(k-1))=J22((k-1),(k-1))+Q2(k-1);
end
end
J22((k-1),(k-1))=J22((k-1),(k-1))+2*BU(k)*BY(k,k)*sin(-G(k,k));
end
for k=1:N-1
for l=1:N-1
if l~=k
J22(k,l)=BU(k+1)*BY((k+1),(l+1))*sin(GU(k+1)-GU(l+1)G((k+1),(l+1)));
end
end
end
Jg=[J11 J12];
Jb=[J21 J22];
J=[Jg;
Jb];
%----------------------ket thuc viec tinh mt jacobi----------t2=cputime;
tgt=t2-t1;

185

Phụ lục: Chương trình Matlab
%----------------------tinh cong suat cac nut-giai lap--------------P=Z2(:,1);
Q=P;
CST=Z2(:,1);
CSK=CST;
for k=1:N-1
for l=1:N
P(k)=BY((k+1),l)*BU(k+1)*BU(l)*cos(GU(k+1)-GU(l)-G((k+1),l));
CST(k)=CST(k)+P(k);
Q(k)=BY((k+1),l)*BU(l)*BU(k+1)*sin(GU(k+1)-GU(l)-G((k+1),l));
CSK(k)=CSK(k)+Q(k);
end
end
for k=1:N-1
KQT(k)=PB(k+1)-CST(k);
KQK(k)=QB(k+1)-CSK(k);
end
CS=[KQT;
KQK];
SSA=inv(J)*CS;
for k=1:N-1
GU(k+1)=GU(k+1)+SSA(k);
end
SSBD=SSA(N:(2*N-2),1);
for k=1:N-1
BU(k+1)=BU(k+1)+SSBD(k);
end
SSCST=max(abs(KQT));
SSCSA=max(abs(KQK));
%-----------------------waitbar------------for kk=hh:ll
waitbar(kk/50,wb)
pause(.0001)
end
hh=ll;
ll=ll+10;
%----------------------------------------sll=sll+1
end
close(wb);
%----------------------------tinh cong suat nut chuan----------CSTNC=0;
CSANC=0;
for l=1:N
P(1)=BY(1,l)*BU(1)*BU(l)*cos(GU(1)-GU(l)-G(1,l));
CSTNC=CSTNC+P(1);
Q(1)=BY(1,l)*BU(1)*BU(l)*sin(GU(1)-GU(l)-G(1,l));
CSANC=CSANC+Q(1);
end
CSTNC=CSTNC*100;
CSANC=CSANC*100;
%---------------------tinh dong tren cac nhanh-ttcs--------------for k=1:N
U1(k)=BU(k)*cos(GU(k))+1j*BU(k)*sin(GU(k));
end
TTCSTP=0;
for k=1:BR
Ik(k)=U1(A(k,1))*(j*A(k,5))-Y(A(k,1),A(k,2))*...
(U1(A(k,1))-U1(A(k,2)));
Ii(k)=U1(A(k,2))*(j*A(k,5))-Y(A(k,1),A(k,2))*...
(U1(A(k,2))-U1(A(k,1)));
Sk(k)=U1(A(k,1))*conj(Ik(k));
Si(k)=U1(A(k,2))*conj(Ii(k));

186

Phụ lục: Chương trình Matlab
SL(k)=Sk(k)+Si(k);
end
%-----------------------tao ra phai de xuat ra man hinh--Ii=Ii';
SL=SL';
TTCSTP=sum(SL);
SL=SL*Scb;
BU1=Ucb*BU;
GU=GU*180/pi;
TTCSTP=TTCSTP*Scb;
Ithuc=Ii*Scb/(Ucb*sqrt(3));
%---------------------tao ra chuoi hien thi ket qua-----%stem(abs(U1(:,1)))
st=num2str(BU1);
for k=1:N
if k<10
st1(k,:)=['U[' num2str(k) ' ]
'];
elseif k<100
st1(k,:)=['U[' num2str(k) ']
'];
else
st1(k,:)=['U[' num2str(k) '] '];
end
end
for k=1:N
st2kh1(k,:)=['
('];
st2kh2(k,:)=[')'];
end
for k=1:BR
st2kh3(k,:)=['
('];
st2kh4(k,:)=[')'];
end
st2g=num2str(GU);
st2=num2str(BU);
% for k=1:N
%
if k<10
% st3(k,:)=['U[' num2str(k) ' ]
'];
% else if k<100
% st3(k,:)=['U[' num2str(k) ' ]
'];
%else
% st3(k,:)=['U[' num2str(k) ']
'];
%end
%end
%end
%std3=['-------biendo(pu)-gocpha(do)'];
%st3d=['----------------------------'];
%st2=[std3;
% st3d;
ttn=char(ttn);
st2=[st1 ttn st2 st2kh1 st2g st2kh2];
st1=[st1 ttn st st2kh1 st2g st2kh2];
t2=cputime;
tgt=t2-t1;
tgtinh=num2str(tgt);
sllap=num2str(sll);
ttr=char(ttr);
sttt=(num2str(SL));
sttt=[ttr sttt];
stdb=num2str(abs(Ithuc));
stdbt=num2str(abs(Ii));
yy=angle(Ithuc)*180/pi;
stdp=num2str(yy);
stdd=[ttr stdb st2kh3 stdp st2kh4];

187

Phụ lục: Chương trình Matlab
stTTT=num2str(TTCSTP);
stddt=[ttr stdbt st2kh3 stdp st2kh4];
U1=220*BU;
BU1=zeros(N,1);
BU1(1:13)=BU(1:13)*220;
BU1(14:92)=BU(14:92)*110;
BU1(93:113)=BU(93:113)*66;
BU1(114:N)=BU(114:N)*13.8;
fid3=fopen('dt3d.txt','r');
DT=fscanf(fid3,'%g %g',[2 inf]);
fclose(fid3);
DT=DT';
for k=1:N
MT3D(DT(k,1),DT(k,2))=U1(k);
end

------------------------------------------------------------[Chuong trinh PBCS viet bang giai thuat Gauss-Seidel]
nbus = length(busdata(:,1));
for k=1:nbus
n=busdata(k,1);
kb(n)=busdata(k,2); Vm(n)=busdata(k,3); delta(n)=busdata(k, 4);
Pd(n)=busdata(k,5); Qd(n)=busdata(k,6); Pg(n)=busdata(k,7); Qg(n) =
busdata(k,8);
Qmin(n)=busdata(k, 9); Qmax(n)=busdata(k, 10);
Qsh(n)=busdata(k, 11);
if Vm(n) <= 0 Vm(n) = 1.0; V(n) = 1 + j*0;
else delta(n) = pi/180*delta(n);
V(n) = Vm(n)*(cos(delta(n)) + j*sin(delta(n)));
P(n)=(Pg(n)-Pd(n))/basemva;
Q(n)=(Qg(n)-Qd(n)+ Qsh(n))/basemva;
S(n) = P(n) + j*Q(n);
end
DV(n)=0;
end
num = 0; AcurBus = 0; converge = 1;
Vc = zeros(nbus,1)+j*zeros(nbus,1); Sc = zeros(nbus,1)+j*zeros(nbus,1);
while exist('hsgt')~=1
hsgt = 1.3;
end
while exist('saiso')~=1
saiso = 0.001;
end
while exist('cscb')~=1
cscb= 100;
end
while exist('sllmax')~=1
sllmax = 100;
end
sll=0;
saisomax=10;
while ssmax >= saso & sll <= sllmax
sll=sll+1;
for n = 1:nbus;
YV = 0+j*0;
for L = 1:nbr;
if nl(L) == n, k=nr(L);
YV = YV + Ybus(n,k)*V(k);
elseif nr(L) == n, k=nl(L);
YV = YV + Ybus(n,k)*V(k);

188

Phụ lục: Chương trình Matlab
end
end
Sc = conj(V(n))*(Ybus(n,n)*V(n) + YV) ;
Sc = conj(Sc);
DP(n) = P(n) - real(Sc);
DQ(n) = Q(n) - imag(Sc);
if kb(n) == 1
S(n) =Sc; P(n) = real(Sc); Q(n) = imag(Sc); DP(n) =0; DQ(n)=0;
Vc(n) = V(n);
elseif kb(n) == 2
Q(n) = imag(Sc); S(n) = P(n) + j*Q(n);
if Qmax(n) ~= 0
Qgc = Q(n)*cscb + Qd(n) - Qsh(n);
if abs(DQ(n)) <= .005 & sll >= 10 %
if DV(n) <= 0.045
%
if Qgc < Qmin(n),
%
Vm(n) = Vm(n) + 0.005;
%
DV(n) = DV(n)+.005;
%
elseif Qgc > Qmax(n),
%
Vm(n) = Vm(n) - 0.005;
%
DV(n)=DV(n)+.005; end
else, end
else,end
else,end
end
if kb(n) ~= 1
Vc(n) = (conj(S(n))/conj(V(n)) - YV )/ Ybus(n,n);
else, end
if kb(n) == 0
V(n) = V(n) + hsgt*(Vc(n)-V(n));
elseif kb(n) == 2
VcI = imag(Vc(n));
VcR = sqrt(Vm(n)^2 - VcI^2);
Vc(n) = VcR + j*VcI;
V(n) = V(n) + hsgt*(Vc(n) -V(n));
end
end
saisomax=max( max(abs(real(DP))), max(abs(imag(DQ))) );
if sll == sllmax & saisomax > saiso
fprintf('\nWARNING: Bai toan khong hoi tu sau ')
fprintf('%g', sll), fprintf(' sll.\n\n')
fprintf('Nhan Enter de hien thi ket qua \n')
converge = 0; pause, else, end
end
if converge ~= 1
tech= ('
tech=('
Ket
end
k=0;
for n = 1:nbus
if kb(n) == 1
S(n)=P(n)+j*Q(n);
Pg(n) = P(n)*cscb + Pd(n);
Qg(n) = Q(n)*cscb + Qd(n) k=k+1;
Pgg(k)=Pg(n);
elseif kb(n) ==2
k=k+1;
Pgg(k)=Pg(n);
S(n)=P(n)+j*Q(n);

giai lap khong hoi tu'); else,
qua giai lap bang PP Gauss-Seidel');

angle(V(n))*180/pi;

Qsh(n);

189

Phụ lục: Chương trình Matlab
Qg(n) = Q(n)*cscb + Qd(n) - Qsh(n);
end
end
Pgt = sum(Pg); Qgt = sum(Qg); Pdt = sum(Pd); Qdt = sum(Qd); Qsht =
sum(Qsh);
clear all

-----------------------------------------------------------[Chuong trinh tinh PBCS bang giai thuat tach bien nhanh FDPF]
------------------------------------------------------------clear TTCST TTT XTCST st1 A st2 ttn ttr st2kh1 SL st2kh2 st4 stTTT;
clear stdp stdd stdtt stdbd Ithuc MT3D NPU DT I xx yy zz Ik Ii TTCSTP;
fid=fopen('nhanhm.txt','r');
A=fscanf(fid,'%g %g %g %g %g',[5 inf]);
fclose(fid);
A=A';
N=max(A(:,2));
BRO=size(A);
BR=BRO(1);
Z=zeros(N);
B=Z;
Y=Z;
G=Y;
%Ucb=get(h0_ucb,'string');
%Ucb=str2num(Ucb);
%Scb=get(h0_scb,'string');
%Scb=str2num(Scb);
%SSCP=get(h0_ss,'string');
%SSCP=str2num(SSCP);
ll=10;hh=0;
t1=cputime;
for k=1:BR
Z(A(k,1),A(k,2))= A(k,3)+1j*A(k,4);
Z(A(k,2),A(k,1))= Z(A(k,1),A(k,2));
B(A(k,1),A(k,2))= 1j*A(k,5);
B(A(k,2),A(k,1))= B(A(k,1),A(k,2));
end
Scb=100;
Ucb=220;
Z=(Z*100)/220^2;
for k=1:N
for l=1:N
if k~=l
if Z(k,l)~=0
Y(k,k)=Y(k,k)+Z(k,l)^-1+220^2/100*B(k,l);
end
end
end
end
for k=1:N-1
for l=k+1:N
if Z(k,l)~=0
Y(k,l)=-Z(k,l)^-1;
Y(l,k)=Y(k,l);
end
end
end
%----------------------ma tran goc-bien do-matran ao------

190

Phụ lục: Chương trình Matlab
teo=get(h0_nc,'string');
teo=str2num(teo);
G=angle(Y);
BY=abs(Y);
BA=-imag(Y);
BA(1,:)=[];
BA(:,1)=[];
BA=BA*teo;
%-------------------cong suat------------------------sstt=get(h0_cdt,'string');
sstt=sstt(get(h0_cdt,'value'),:);
sstt=deblank(sstt);
fid1=fopen(sstt,'r');
S=fscanf(fid1,'%g %g %g',[3 inf]);
fclose(fid1);
S=S';
Z1=zeros(N-1);
PB=Z1(:,1);
QB=PB;
sll=0;
CST=PB;
P=PB;
Q=PB;
CSK=QB;
KQT=PB;
KQK=QB;
SSDA=QB;
X=ones(N-1);
SSCST=X(:,1);
SSCSA=SSCST;
for k=1:N-1
PB(S(k,1),1)=S(k,2);
QB(S(k,1),1)=S(k,3);
end
PB(1,:)=[];
QB(1,:)=[];
PB=PB/100;
QB=QB/100;
TCSTT=0;
TCSTK=0;
TCSFT=0;
TCSFK=0;
%----------------Kiem tra dieu kien can bang cong suat phat va tai------%for k=1:N-1
% if PB(k)>0
%
TCSFT=TCSFT+PB(k);
%
TCSFK=TCSFK+QB(k);
%else
% TCSTT=TCSTT+PB(k);
% TCSTK=TCSTK+QB(k);
% end
%end
%-------------------------thuat giai FDPF-------------------U1=zeros(N);
U=U1(:,1);
TTCST=U1;
U1=U;
U(1,1)=1.05;
U(2:N,1)=1;
BU=abs(U);
GU=angle(U);
while((max(SSCST)>0.001)&(max(SSCSA)>0.001))
CST=Z1(:,1);

191

Phụ lục: Chương trình Matlab
CSK=CST;
for k=1:N-1
for l=1:N
P(k)=BY((k+1),l)*BU(k+1)*BU(l)*cos(GU(k+1)-GU(l)-G((k+1),l));
CST(k)=CST(k)+P(k);
end
end
for k=1:N-1
KQT(k)=(PB(k)-CST(k))/BU(k+1);
end
SGU=inv(BA)*KQT;
for k=1:N-1
GU(k+1)=GU(k+1)+SGU(k);
end
for k=1:N-1
for l=1:N
Q(k)=BY((k+1),l)*BU(l)*BU(k+1)*sin(GU(k+1)-GU(l)-G((k+1),l));
CSK(k)=CSK(k)+Q(k);
end
end
for k=1:N-1
KQK(k)=(QB(k)-CSK(k))/BU(k+1);
end
SSDA=inv(BA)*KQK;
for k=1:N-1
BU(k+1)=BU(k+1)+SSDA(k);
end
SSCST=abs(PB-CST);
SSCSA=abs(QB-CSK);
%-----------------------waitbar------------for kk=hh:ll
waitbar(kk/100,wb);
pause(.01);
end
hh=ll;
ll=ll+10;
%----------------------------------------sll=sll+1;
end
waitbar(1,wb);
close(wb);
%----------------------------tinh cong suat nut chuan--CSTNC=0;
CSANC=0;
for l=1:N
P(1)=BY(1,l)*BU(1)*BU(l)*cos(GU(1)-GU(l)-G(1,l));
CSTNC=CSTNC+P(1);
Q(1)=BY(1,l)*BU(1)*BU(l)*sin(GU(1)-GU(l)-G(1,l));
CSANC=CSANC+Q(1);
U1(l)=BU(l)*cos(GU(l))+1j*BU(l)*sin(GU(l));
end
CSTNC=CSTNC*100;
CSANC=CSANC*100;
%---------------------tinh dong tren cac nhanh-ttcs----TTCSTP=0;
for k=1:BR
Ik(k)=U1(A(k,1))*(j*A(k,5))-Y(A(k,1),A(k,2))*...
(U1(A(k,1))-U1(A(k,2)));
Ii(k)=U1(A(k,2))*(j*A(k,5))-Y(A(k,1),A(k,2))*...
(U1(A(k,2))-U1(A(k,1)));
Sk(k)=U1(A(k,1))*conj(Ik(k));
Si(k)=U1(A(k,2))*conj(Ii(k));
SL(k)=Sk(k)+Si(k);
end

192

Phụ lục: Chương trình Matlab
%-----------------------tao ra phai de xuat ra man hinh--Ii=Ii';
SL=SL';
TTCSTP=sum(SL);
SL=SL*Scb;
BU1=Ucb*BU;
GU=GU*180/pi;
TTCSTP=TTCSTP*Scb;
Ithuc=Ii*Scb/(Ucb*sqrt(3));
%---------------------tao ra chuoi hien thi ket qua-----%stem(abs(U1(:,1)))
st=num2str(BU1);
for k=1:N
if k<10
st1(k,:)=['U[' num2str(k) ' ]
'];
elseif k<100
st1(k,:)=['U[' num2str(k) ']
'];
else
st1(k,:)=['U[' num2str(k) '] '];
end
end
for k=1:N
st2kh1(k,:)=['
('];
st2kh2(k,:)=[')'];
end
for k=1:BR
st2kh3(k,:)=['
('];
st2kh4(k,:)=[')'];
end
st2g=num2str(GU);
st2=num2str(BU);
% for k=1:N
%
if k<10
% st3(k,:)=['U[' num2str(k) ' ]
'];
% else if k<100
% st3(k,:)=['U[' num2str(k) ' ]
'];
%else
% st3(k,:)=['U[' num2str(k) ']
'];
%end
%end
%end
%std3=['-------biendo(pu)-gocpha(do)'];
%st3d=['----------------------------'];
%st2=[std3;
% st3d;
ttn=char(ttn);
st2=[st1 ttn st2 st2kh1 st2g st2kh2];
st1=[st1 ttn st st2kh1 st2g st2kh2];
t2=cputime;
tgt=t2-t1;
tgtinh=num2str(tgt);
sllap=num2str(sll);
ttr=char(ttr);
sttt=(num2str(SL));
sttt=[ttr sttt];
stdb=num2str(abs(Ithuc));
stdbt=num2str(abs(Ii));
yy=angle(Ithuc)*180/pi;
stdp=num2str(yy);
stdd=[ttr stdb st2kh3 stdp st2kh4];
stTTT=num2str(TTCSTP);
stddt=[ttr stdbt st2kh3 stdp st2kh4];

193

Phụ lục: Chương trình Matlab
U1=220*BU;
BU1=zeros(N,1);
BU1(1:13)=BU(1:13)*220;
BU1(14:92)=BU(14:92)*110;
BU1(93:113)=BU(93:113)*66;
BU1(114:N)=BU(114:N)*13.8;
fid3=fopen('dt3d.txt','r');
DT=fscanf(fid3,'%g %g',[2 inf]);
fclose(fid3);
DT=DT';
for k=1:N
MT3D(DT(k,1),DT(k,2))=U1(k);
End
========================================================================

Mọi chi tiết gặp phải khi sử dụng các đoạn chương trình trên xin liên liên hệ trực
tiếp với nhóm tác giả của tài liệu này. Xin chân thành cảm ơn.

194

### Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×