SlideShare a Scribd company logo
DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY
DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING
Bsc. Electrical and Electronic Engineering
GROUP MEMBERS
Sno. Name Registration Number
1. PETER M. MUNDATI E021u-01-1721/2016
2. CONSOLATA W. IKAME E021u-01-1703/2016
3. GLADYS K. NYANSERA E021u-01-1718/2016
4. RONALD S. ATSIAYA E021u-01-1712/2016
5. ELLIUD K. KIRUI E021u-01-2215 /2016
6. DAVID K. KOSGEY E021u-01-2213 /2016
7. WIILIAM K. SITIENEI E021u-01-2212 /2016
UNIT NAME: POWER SYSTEMS ANALYSIS 1
UNIT CODE:
TASK: LABOLATORY PRACTICE
LECTURER: LUCAS O. MOGAKA
MATLAB DEKUT 2019.doc
MATLAB DEKUT 2019.doc
MATLAB DEKUT 2019.doc
SOLUTIONS
>> %DATA PROVIDED
clear
basemva=100;
accuracy=0.001;maxiter=100;
busdata=[1 1 1.05 0.0 0.0 0.0 0.0 0.0 0 0 0;2 0 1.0 0.0 256.66 110.2 0.0 0.0 0 0 0;3 0 1.0 0.0 138.6 45.2
0.0 0.0 0 0 0];
linedata=[1 2 0.02 0.04 0.01 0;1 3 0.01 0.03 0.01 0;2 3 0.0125 0.025 0.01 0];
%LFYBUS CALCULATIONS
j=sqrt(-1); i = sqrt(-1);
nl = linedata(:,1); nr = linedata(:,2); R = linedata(:,3);
X = linedata(:,4); Bc = j*linedata(:,5); a = linedata(:, 6);
nbr=length(linedata(:,1)); nbus = max(max(nl), max(nr));
Z = R + j*X; y= ones(nbr,1)./Z; %branch admittance
for n = 1:nbr
if a(n) <= 0 a(n) = 1; else end
Ybus=zeros(nbus,nbus); % initialize Ybus to zero
% formation of the off diagonal elements
for k=1:nbr;
Ybus(nl(k),nr(k))=Ybus(nl(k),nr(k))-y(k)/a(k);
Ybus(nr(k),nl(k))=Ybus(nl(k),nr(k));
end
end
% formation of the diagonal elements
for n=1:nbus
for k=1:nbr
if nl(k)==n
Ybus(n,n) = Ybus(n,n)+y(k)/(a(k)^2) + Bc(k);
elseif nr(k)==n
Ybus(n,n) = Ybus(n,n)+y(k) +Bc(k);
else, end
end
end
clear Pgg
%LFGAUSS CALCULATIONS
Vm=0; delta=0; yload=0; deltad =0;
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('accel')~=1
accel = 1.4;
end
while exist('accuracy')~=1
accuracy = 0.001;
end
while exist('basemva')~=1
basemva= 100;
end
while exist('maxiter')~=1
maxiter = 100;
end
iter=1;
maxerror=10;
while maxerror >= accuracy & iter <= maxiter
iter=iter+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);
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)*basemva + Qd(n) - Qsh(n);
if abs(DQ(n)) <= .005 & iter >= 10 % After 10 iterations
if DV(n) <= 0.045 % the Mvar of generator buses are
if Qgc < Qmin(n), % tested. If not within limits Vm(n)
Vm(n) = Vm(n) + 0.005; % is changed in steps of 0.005 pu
DV(n) = DV(n)+.005; % up to .05 pu in order to bring
elseif Qgc > Qmax(n), % the generator Mvar within the
Vm(n) = Vm(n) - 0.005; % specified limits.
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) + accel*(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) + accel*(Vc(n) -V(n));
end
end
maxerror=max( max(abs(real(DP))), max(abs(imag(DQ))) );
if iter == maxiter & maxerror > accuracy
fprintf('nWARNING: Iterative solution did not converged after ')
fprintf('%g', iter), fprintf(' iterations.nn')
fprintf('Press Enter to terminate the iterations and print the results n')
converge = 0; pause, else, end
end
if converge ~= 1
tech= (' ITERATIVE SOLUTION DID NOT CONVERGE'); else,
tech=(' Power Flow Solution by Gauss-Seidel Method');
end
k=0;
for n = 1:nbus
Vm(n) = abs(V(n)); deltad(n) = angle(V(n))*180/pi;
if kb(n) == 1
S(n)=P(n)+j*Q(n);
Pg(n) = P(n)*basemva + Pd(n);
Qg(n) = Q(n)*basemva + Qd(n) - Qsh(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);
Qg(n) = Q(n)*basemva + Qd(n) - Qsh(n);
end
yload(n) = (Pd(n)- j*Qd(n)+j*Qsh(n))/(basemva*Vm(n)^2);
end
Pgt = sum(Pg); Qgt = sum(Qg); Pdt = sum(Pd); Qdt = sum(Qd); Qsht = sum(Qsh);
busdata(:,3)=Vm'; busdata(:,4)=deltad';
clear AcurBus DP DQ DV L Sc Vc VcI VcR YV converge delta
%BUSOUT CALCUALTIONS
disp(tech)
fprintf(' Maximum Power Mismatch = %g n', maxerror)
fprintf(' No. of Iterations = %g nn', iter)
head =[' Bus Voltage Angle ------Load------ ---Generation--- Injected'
' No. Mag. Degree MW Mvar MW Mvar Mvar '
' '];
disp(head)
for n=1:nbus
fprintf(' %5g', n), fprintf(' %7.3f', Vm(n)),
fprintf(' %8.3f', deltad(n)), fprintf(' %9.3f', Pd(n)),
fprintf(' %9.3f', Qd(n)), fprintf(' %9.3f', Pg(n)),
fprintf(' %9.3f ', Qg(n)), fprintf(' %8.3fn', Qsh(n))
end
fprintf(' n'), fprintf(' Total ')
fprintf(' %9.3f', Pdt), fprintf(' %9.3f', Qdt),
fprintf(' %9.3f', Pgt), fprintf(' %9.3f', Qgt), fprintf(' %9.3fnn', Qsht)
%LINEFLOW CALCULATIONS
SLT = 0;
fprintf('n')
fprintf(' Line Flow and Losses nn')
fprintf(' --Line-- Power at bus & line flow --Line loss-- Transformern')
fprintf(' from to MW Mvar MVA MW Mvar tapn')
for n = 1:nbus
busprt = 0;
for L = 1:nbr;
if busprt == 0
fprintf(' n'), fprintf('%6g', n), fprintf(' %9.3f', P(n)*basemva)
fprintf('%9.3f', Q(n)*basemva), fprintf('%9.3fn', abs(S(n)*basemva))
busprt = 1;
else, end
if nl(L)==n k = nr(L);
In = (V(n) - a(L)*V(k))*y(L)/a(L)^2 + Bc(L)/a(L)^2*V(n);
Ik = (V(k) - V(n)/a(L))*y(L) + Bc(L)*V(k);
Snk = V(n)*conj(In)*basemva;
Skn = V(k)*conj(Ik)*basemva;
SL = Snk + Skn;
SLT = SLT + SL;
elseif nr(L)==n k = nl(L);
In = (V(n) - V(k)/a(L))*y(L) + Bc(L)*V(n);
Ik = (V(k) - a(L)*V(n))*y(L)/a(L)^2 + Bc(L)/a(L)^2*V(k);
Snk = V(n)*conj(In)*basemva;
Skn = V(k)*conj(Ik)*basemva;
SL = Snk + Skn;
SLT = SLT + SL;
else, end
if nl(L)==n | nr(L)==n
fprintf('%12g', k),
fprintf('%9.3f', real(Snk)), fprintf('%9.3f', imag(Snk))
fprintf('%9.3f', abs(Snk)),
fprintf('%9.3f', real(SL)),
if nl(L) ==n & a(L) ~= 1
fprintf('%9.3f', imag(SL)), fprintf('%9.3fn', a(L))
else, fprintf('%9.3fn', imag(SL))
end
else, end
end
end
SLT = SLT/2;
fprintf(' n'), fprintf(' Total loss ')
fprintf('%9.3f', real(SLT)), fprintf('%9.3fn', imag(SLT))
clear Ik In SL SLT Skn Snk
Power Flow Solution by Gauss-Seidel Method
Maximum Power Mismatch = 0.000679948
No. of Iterations = 12
Bus Voltage Angle ------Load------ ---Generation--- Injected
No. Mag. Degree MW Mvar MW Mvar Mvar
1 1.050 0.000 0.000 0.000 409.379 182.639 0.000
2 0.983 -3.518 256.660 110.200 0.000 0.000 0.000
3 1.002 -2.875 138.600 45.200 0.000 0.000 0.000
Total 395.260 155.400 409.379 182.639 0.000
Line Flow and Losses
--Line-- Power at bus & line flow --Line loss-- Transformer
from to MW Mvar MVA MW Mvar tap
1 409.379 182.639 448.273
2 199.357 81.085 215.216 8.435 14.802
3 210.084 101.532 233.332 4.959 12.770
2 -256.660 -110.200 279.318
1 -190.922 -66.283 202.100 8.435 14.802
3 -65.698 -43.956 79.047 0.798 -0.373
3 -138.600 -45.200 145.784
1 -205.125 -88.762 223.506 4.959 12.770
2 66.496 43.583 79.506 0.798 -0.373
Total loss 14.192 27.199

More Related Content

PDF
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
PDF
jacobi method, gauss siedel for solving linear equations
PDF
MITCOE 2011-12 conm-submission
PDF
Numericam Methods using Matlab.pdf
PDF
Solutions_Manual_to_accompany_Applied_Nu.pdf
PDF
Assignment On Matlab
PDF
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
jacobi method, gauss siedel for solving linear equations
MITCOE 2011-12 conm-submission
Numericam Methods using Matlab.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdf
Assignment On Matlab

Similar to MATLAB DEKUT 2019.doc (20)

PDF
Write Python for Speed
DOCX
Examen final
PDF
Help with root locus homework1
PDF
DOCX
scientific computing
PDF
Nonlinear 2nd order analysis of 2 d fixed support beam with plastic hinge con...
PDF
Introduction to CFD FORTRAN code
PDF
Matlab Assignment JK Institute
PDF
optimization c code on blackfin
DOCX
Matlab lab manual
PDF
Newconceptdataanalyze
PPTX
Better performance through Superscalarity
PDF
Computer Oriented Numerical Methods Practical File
PDF
Mathematical Modelling of Electrical/Mechanical modellinng in MATLAB
PDF
This problem illustrates one of the possible pitfalls of blindly appl.pdf
PDF
Matlab Sample Assignment Solution
DOCX
Trabajo Scilab
DOCX
Scientific Computing
Write Python for Speed
Examen final
Help with root locus homework1
scientific computing
Nonlinear 2nd order analysis of 2 d fixed support beam with plastic hinge con...
Introduction to CFD FORTRAN code
Matlab Assignment JK Institute
optimization c code on blackfin
Matlab lab manual
Newconceptdataanalyze
Better performance through Superscalarity
Computer Oriented Numerical Methods Practical File
Mathematical Modelling of Electrical/Mechanical modellinng in MATLAB
This problem illustrates one of the possible pitfalls of blindly appl.pdf
Matlab Sample Assignment Solution
Trabajo Scilab
Scientific Computing
Ad

More from LucasMogaka (20)

PPTX
1502957399lectrure_5_KUET.pptx
PPT
Ch08_PPT_Fund_Elec_Circ_5e.ppt
PPTX
Power_plant_ecomices.pptx
PPTX
Transmission_and_Distribution_System.pptx
PPT
Basic_Laws.ppt
PPTX
loadforecasting-190205135237.pptx
PDF
NR-Power Flow.pdf
PDF
Section 5 Power Flow.pdf
PPTX
Ac_steady_state_analyis.pptx
PDF
slides_12_ch 14-2- complex numbers.pdf
PPT
LOAD FORECASTING.ppt
PDF
0ea1cdf161957c644e8c0b524c973c7e7b2c - Copy.pdf
PDF
Economic_Load_Dispatch.pdf
PDF
18053522.pdf
PPTX
CiT-03.pptx
PPTX
CiT-02.pptx
PPTX
Ac_steady_state_analyis.pptx
PPTX
CiT-03.pptx
PDF
1340050227.pdf
PDF
EE-8353 EDC COURSE MATERIAL.pdf
1502957399lectrure_5_KUET.pptx
Ch08_PPT_Fund_Elec_Circ_5e.ppt
Power_plant_ecomices.pptx
Transmission_and_Distribution_System.pptx
Basic_Laws.ppt
loadforecasting-190205135237.pptx
NR-Power Flow.pdf
Section 5 Power Flow.pdf
Ac_steady_state_analyis.pptx
slides_12_ch 14-2- complex numbers.pdf
LOAD FORECASTING.ppt
0ea1cdf161957c644e8c0b524c973c7e7b2c - Copy.pdf
Economic_Load_Dispatch.pdf
18053522.pdf
CiT-03.pptx
CiT-02.pptx
Ac_steady_state_analyis.pptx
CiT-03.pptx
1340050227.pdf
EE-8353 EDC COURSE MATERIAL.pdf
Ad

Recently uploaded (20)

PDF
Design Guidelines and solutions for Plastics parts
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Software Engineering and software moduleing
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Feature types and data preprocessing steps
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPT
Total quality management ppt for engineering students
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPT
Occupational Health and Safety Management System
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Design Guidelines and solutions for Plastics parts
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
737-MAX_SRG.pdf student reference guides
Software Engineering and software moduleing
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Feature types and data preprocessing steps
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Information Storage and Retrieval Techniques Unit III
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Module 8- Technological and Communication Skills.pptx
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Fundamentals of safety and accident prevention -final (1).pptx
Total quality management ppt for engineering students
III.4.1.2_The_Space_Environment.p pdffdf
Occupational Health and Safety Management System
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf

MATLAB DEKUT 2019.doc

  • 1. DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING Bsc. Electrical and Electronic Engineering GROUP MEMBERS Sno. Name Registration Number 1. PETER M. MUNDATI E021u-01-1721/2016 2. CONSOLATA W. IKAME E021u-01-1703/2016 3. GLADYS K. NYANSERA E021u-01-1718/2016 4. RONALD S. ATSIAYA E021u-01-1712/2016 5. ELLIUD K. KIRUI E021u-01-2215 /2016 6. DAVID K. KOSGEY E021u-01-2213 /2016 7. WIILIAM K. SITIENEI E021u-01-2212 /2016 UNIT NAME: POWER SYSTEMS ANALYSIS 1 UNIT CODE: TASK: LABOLATORY PRACTICE LECTURER: LUCAS O. MOGAKA
  • 5. SOLUTIONS >> %DATA PROVIDED clear basemva=100; accuracy=0.001;maxiter=100; busdata=[1 1 1.05 0.0 0.0 0.0 0.0 0.0 0 0 0;2 0 1.0 0.0 256.66 110.2 0.0 0.0 0 0 0;3 0 1.0 0.0 138.6 45.2 0.0 0.0 0 0 0]; linedata=[1 2 0.02 0.04 0.01 0;1 3 0.01 0.03 0.01 0;2 3 0.0125 0.025 0.01 0]; %LFYBUS CALCULATIONS j=sqrt(-1); i = sqrt(-1); nl = linedata(:,1); nr = linedata(:,2); R = linedata(:,3); X = linedata(:,4); Bc = j*linedata(:,5); a = linedata(:, 6); nbr=length(linedata(:,1)); nbus = max(max(nl), max(nr)); Z = R + j*X; y= ones(nbr,1)./Z; %branch admittance for n = 1:nbr if a(n) <= 0 a(n) = 1; else end Ybus=zeros(nbus,nbus); % initialize Ybus to zero % formation of the off diagonal elements for k=1:nbr; Ybus(nl(k),nr(k))=Ybus(nl(k),nr(k))-y(k)/a(k); Ybus(nr(k),nl(k))=Ybus(nl(k),nr(k)); end end % formation of the diagonal elements for n=1:nbus for k=1:nbr if nl(k)==n Ybus(n,n) = Ybus(n,n)+y(k)/(a(k)^2) + Bc(k); elseif nr(k)==n
  • 6. Ybus(n,n) = Ybus(n,n)+y(k) +Bc(k); else, end end end clear Pgg %LFGAUSS CALCULATIONS Vm=0; delta=0; yload=0; deltad =0; 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('accel')~=1 accel = 1.4; end while exist('accuracy')~=1 accuracy = 0.001;
  • 7. end while exist('basemva')~=1 basemva= 100; end while exist('maxiter')~=1 maxiter = 100; end iter=1; maxerror=10; while maxerror >= accuracy & iter <= maxiter iter=iter+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); 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)*basemva + Qd(n) - Qsh(n);
  • 8. if abs(DQ(n)) <= .005 & iter >= 10 % After 10 iterations if DV(n) <= 0.045 % the Mvar of generator buses are if Qgc < Qmin(n), % tested. If not within limits Vm(n) Vm(n) = Vm(n) + 0.005; % is changed in steps of 0.005 pu DV(n) = DV(n)+.005; % up to .05 pu in order to bring elseif Qgc > Qmax(n), % the generator Mvar within the Vm(n) = Vm(n) - 0.005; % specified limits. 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) + accel*(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) + accel*(Vc(n) -V(n)); end end maxerror=max( max(abs(real(DP))), max(abs(imag(DQ))) ); if iter == maxiter & maxerror > accuracy fprintf('nWARNING: Iterative solution did not converged after ') fprintf('%g', iter), fprintf(' iterations.nn') fprintf('Press Enter to terminate the iterations and print the results n') converge = 0; pause, else, end end
  • 9. if converge ~= 1 tech= (' ITERATIVE SOLUTION DID NOT CONVERGE'); else, tech=(' Power Flow Solution by Gauss-Seidel Method'); end k=0; for n = 1:nbus Vm(n) = abs(V(n)); deltad(n) = angle(V(n))*180/pi; if kb(n) == 1 S(n)=P(n)+j*Q(n); Pg(n) = P(n)*basemva + Pd(n); Qg(n) = Q(n)*basemva + Qd(n) - Qsh(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); Qg(n) = Q(n)*basemva + Qd(n) - Qsh(n); end yload(n) = (Pd(n)- j*Qd(n)+j*Qsh(n))/(basemva*Vm(n)^2); end Pgt = sum(Pg); Qgt = sum(Qg); Pdt = sum(Pd); Qdt = sum(Qd); Qsht = sum(Qsh); busdata(:,3)=Vm'; busdata(:,4)=deltad'; clear AcurBus DP DQ DV L Sc Vc VcI VcR YV converge delta %BUSOUT CALCUALTIONS disp(tech) fprintf(' Maximum Power Mismatch = %g n', maxerror) fprintf(' No. of Iterations = %g nn', iter) head =[' Bus Voltage Angle ------Load------ ---Generation--- Injected' ' No. Mag. Degree MW Mvar MW Mvar Mvar '
  • 10. ' ']; disp(head) for n=1:nbus fprintf(' %5g', n), fprintf(' %7.3f', Vm(n)), fprintf(' %8.3f', deltad(n)), fprintf(' %9.3f', Pd(n)), fprintf(' %9.3f', Qd(n)), fprintf(' %9.3f', Pg(n)), fprintf(' %9.3f ', Qg(n)), fprintf(' %8.3fn', Qsh(n)) end fprintf(' n'), fprintf(' Total ') fprintf(' %9.3f', Pdt), fprintf(' %9.3f', Qdt), fprintf(' %9.3f', Pgt), fprintf(' %9.3f', Qgt), fprintf(' %9.3fnn', Qsht) %LINEFLOW CALCULATIONS SLT = 0; fprintf('n') fprintf(' Line Flow and Losses nn') fprintf(' --Line-- Power at bus & line flow --Line loss-- Transformern') fprintf(' from to MW Mvar MVA MW Mvar tapn') for n = 1:nbus busprt = 0; for L = 1:nbr; if busprt == 0 fprintf(' n'), fprintf('%6g', n), fprintf(' %9.3f', P(n)*basemva)
  • 11. fprintf('%9.3f', Q(n)*basemva), fprintf('%9.3fn', abs(S(n)*basemva)) busprt = 1; else, end if nl(L)==n k = nr(L); In = (V(n) - a(L)*V(k))*y(L)/a(L)^2 + Bc(L)/a(L)^2*V(n); Ik = (V(k) - V(n)/a(L))*y(L) + Bc(L)*V(k); Snk = V(n)*conj(In)*basemva; Skn = V(k)*conj(Ik)*basemva; SL = Snk + Skn; SLT = SLT + SL; elseif nr(L)==n k = nl(L); In = (V(n) - V(k)/a(L))*y(L) + Bc(L)*V(n); Ik = (V(k) - a(L)*V(n))*y(L)/a(L)^2 + Bc(L)/a(L)^2*V(k); Snk = V(n)*conj(In)*basemva; Skn = V(k)*conj(Ik)*basemva; SL = Snk + Skn; SLT = SLT + SL; else, end if nl(L)==n | nr(L)==n fprintf('%12g', k), fprintf('%9.3f', real(Snk)), fprintf('%9.3f', imag(Snk)) fprintf('%9.3f', abs(Snk)), fprintf('%9.3f', real(SL)), if nl(L) ==n & a(L) ~= 1 fprintf('%9.3f', imag(SL)), fprintf('%9.3fn', a(L)) else, fprintf('%9.3fn', imag(SL)) end else, end end end SLT = SLT/2;
  • 12. fprintf(' n'), fprintf(' Total loss ') fprintf('%9.3f', real(SLT)), fprintf('%9.3fn', imag(SLT)) clear Ik In SL SLT Skn Snk Power Flow Solution by Gauss-Seidel Method Maximum Power Mismatch = 0.000679948 No. of Iterations = 12 Bus Voltage Angle ------Load------ ---Generation--- Injected No. Mag. Degree MW Mvar MW Mvar Mvar 1 1.050 0.000 0.000 0.000 409.379 182.639 0.000 2 0.983 -3.518 256.660 110.200 0.000 0.000 0.000 3 1.002 -2.875 138.600 45.200 0.000 0.000 0.000 Total 395.260 155.400 409.379 182.639 0.000 Line Flow and Losses --Line-- Power at bus & line flow --Line loss-- Transformer from to MW Mvar MVA MW Mvar tap 1 409.379 182.639 448.273 2 199.357 81.085 215.216 8.435 14.802 3 210.084 101.532 233.332 4.959 12.770 2 -256.660 -110.200 279.318 1 -190.922 -66.283 202.100 8.435 14.802 3 -65.698 -43.956 79.047 0.798 -0.373 3 -138.600 -45.200 145.784
  • 13. 1 -205.125 -88.762 223.506 4.959 12.770 2 66.496 43.583 79.506 0.798 -0.373 Total loss 14.192 27.199