Top Banner
Introduction to Power Flow Analysis Toolbox Version 1.0a Revision: February, 2011 Chao Lei Sichuan Agricultural University advancedMcode.org
79
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: pfatb_v1.0a

Introduction toPower Flow Analysis Toolbox

Version 1.0aRevision: February, 2011

Chao LeiSichuan Agricultural University

advancedMcode.org

Page 2: pfatb_v1.0a

This edition first published 2011Copyright ©2010-2011 by Chao Lei. All Rights Reserved.Power Flow Analysis Toolbox(M-files), and the accompanying document Introduction to PowerFlow Analysis Toolbox, are facilitated to practice, educate and research. It can not be alteredin any way, or be used as part of other documents without written permission consented by theauthor.

Page 3: pfatb_v1.0a

Dedicated to my mother, Yurong Wang,who practiced ingenuity,and to my friend, Biwei Su,who lighted me up from dark

Page 4: pfatb_v1.0a

This page intentionally left blank

Page 5: pfatb_v1.0a

Preface and Acknowledgements

This introduction, a partner of Power Flow Analysis Toolbox(PFATB), has been organized to takethe power flow analysis combination with MATLAB programming codes in stages. It is writtenfor whoever might possibly use this toolbox to research power flow analysis. However, the biggestaddition is including the specific basics of power flows, which is combined to explain program-ming functions. But I continue to emphasize the programming part of this introduction––it iswritten for the practicing scientist, engineer, and so forth. The reader who wishes to know moreabout power flow in more detail is highly recommended to read two publications: Optimizationof Power System Operation by Jizhong Zhu(Wiley & IEEE Press,2009) and Power System Analysisby Hadi Saadat(McGraw-Hill,2002). I make no claims of this toolbox including latest research onalgorithms applied on power flow problems; instead, I refer the reader to use these routines totestify your new thoughts. To be frank, I think all the routines in the toolbox are not best to facil-itate in solving power flow problems, but its most biggest feature is to visualize computations insteps. Because they are remarkably concise and lucid to be applied and then to be revised forwarduser’s decisions. I hope readers find these a useful start to their own applications and wish themwell in their own forays into using with advanced algorithms such as genetic algorithm, particleswarm optimization algorithm and so forth to slove economical dispatch and optimal power flowin large-scale power system.

I am indebted to serval engineers and friends for their kind help. First, my thanks goes to aMr.Long of Zhejiang University for arising my tremendous interests to implement this toolboxand making contributions to provide the initial prototype for this toolbox. Without his hard-working efforts, the toolbox would have not been born. Subsequently, I am also deeply gratefulto Principal Engineer Jizhong Zhu of AREVA T&D Incorporation for encouraging me to go onmy job instantly half a year ago. Likewise, the idea for writing this partner introduction andthe encouragement to write it, I owe to my friend Yuanyuan Jiang of Lancaster University andLab Technical Engineer Hong Wen of Sichuan Agricultural University. Additionally, thanks alsofor Luigi Giaccari providing me a webpage and a link to my toolbox in the main webpage ofadvancedMcode.org. Finally, the excellent reviews by postgraduate Simon Catmull of Loughbor-ough University in UK were invaluable in the writing of this manuscript.

While acknowledging the help I have received from individuals referred to above, the respon-sibility for the work is mine alone, so corrections and/or constructive criticisms would be warmlywelcome.

Chao Lei

Chongqing,ChinaSpring,2011

Page 6: pfatb_v1.0a

This page intentionally left blank

Page 7: pfatb_v1.0a

Contents

1 INTRODUCTION 11.1 An Overview of PFATB 11.2 PFATB-Interface 2

2 ABOUT AUTHOR 3

3 INSTALLATION 4

4 TOOLBOX DESIGN 54.1 Toolbox Design Process 54.2 MATLAB Programming Style 6

5 STANDARDDATA STRUCTURES 75.1 Bus Data 75.2 Transmission Line Data and Transformer Data 75.3 Transmission Line Admittance Data 85.4 Transmission Line Flow and Loss Data 9

6 TOOLBOX FUNCTIONS 136.1 Data Pre-processing 136.2 Execute Algorithms 176.3 Data Reconfiguration 266.4 Output Solution 26

7 POWER FLOWALGORITHMS 297.1 Algorithm Convergence Speed 297.2 Gauss-Seidel Algorithm 307.3 Newton-Raphson Algorithm 38

7.3.1 N-R Algorithm With Polar Coordinate System 387.3.2 N-R Algorithm With Rectangular Coordinate System 45

7.4 P-Q Decoupling Algorithm 527.5 Algorithm Discussions 59

8 IEEE 30-BUS TEST SYSTEM 60

9 FURTHER REVERSIONS 65

A APPENDIX IEEE 30-BUS SOLUTIONS 67

Page 8: pfatb_v1.0a

This page intentionally left blank

Page 9: pfatb_v1.0a

Introduction to PFATB 1

1 INTRODUCTION

1.1 An Overview of PFATB

PFATB, which stands for Power Flow Analysis Toolbox, is a package of MATLAB M-files. It is acollection of routines, written mostly in m-files, which implement the most important functionsto compute and analysis in the applications of power flow. The PFATB is much useful for powerflow analysis practitioner and those wishing to experiment with the power flow algorithm for thefirst time. It is intended as a simulation tool and computing tool for researchers and educatorsthat is easy to use and modify under the uniform MATLAB programming environment. I sin-cerely hope that this toolbox will make it possible for you to do more complex computations justas easily.

PFATB is made up with three main algorithms within Gauss-Seidel, Newton-Raphson and P-Qdecoupling methods. Figure 1.1 shows the relationship tree between PFATB tool with visualizedcomputations and other interactions with Simpower and GUI Interface.

Gauss-Seidel

Algorithm

Newton-Raphson

Algorithm

P-Q Decoupling

Algorithm

PFATB

MATLAB

Environment

Visualized

ComputationSimpower GUI Interface

Backbone

Roots

Branches

FIGURE 1.1: Diagram of PFATB tree

Before getting started, the basic theory of power flow in the whole manuscript is drawn fromthe power flow literatures, which are listed in a separate section(REFERENCES). Any questionsabout basics, please trace the literature source for further reading. I believed that with an inter-active environment like PFATB, you would be able to pick up the basics quickly, and begin usingit confidently in just a few hours. Additionally, the cases presented in this manuscript are almost

Page 10: pfatb_v1.0a

2 Introduction to PFATB

derived from Optimization of Power System Control by Jizhong Zhu(Wiley & IEEE Press,2009) andPower System Analysis by Hadi Saadat(McGraw-Hill,2002).

Let us begin this brief introduction, and hope it will be helpful for enhancing codes readabilityin PFATB.

1.2 PFATB-Interface

A bridge between PFATB and MATLAB allows using sophisticated nonlinear computation toolswith the visualization capabilities provided by MATLAB.

The existing GUI interface, located in the toolbox file, has been used as the main referencefor creating the PFATB-Interface. The PFATB-Interface software is developed as a simple GUIapplication based on PFATB. The Figure 1.2 depicts the scheme of the PFATB-Interface. Theresulting software is a rather innovative tool able to set up large scale power system test cases,solve power flow problems and finally visualize results by means of a user-friendly GUI.

PFATBNetwork

Graphic

Visualization

Toolbox

PFATB

Interface

MATLAB

PFATB

Interface

Input Data Output Solution

FIGURE 1.2: Structure of PFATB-Interface

Page 11: pfatb_v1.0a

Introduction to PFATB 3

2 ABOUT AUTHOR

PFATBwas developed by Chao Lei, at Electronics Lab of Sichuan Agricultural University(SICAU).I graduated from Sichuan Agricultural University in 2010 with a Bachelor of Engineer degreein Agro-machinery Engineering. My interesting research areas of expertise are Optimization ofPower System Operation, Reliability of Power System Distribution, Electricity Markets, and PowerSystem State Estimation.

The original thoughts for developing PFATB toolbox are intending for fun and ready for grad-uate career. Nevertheless, that the core codes are born at Electronics Engineering Lab of SICAUmakes me somewhat relaxed and feel kind of easy since I will have a chance to enjoy life again.

Page 12: pfatb_v1.0a

4 Introduction to PFATB

3 INSTALLATION

I authorize advancedMcode(See http://www.advancedmcode.org) to release PFATB for the userto download. It is available from PFATB Home Page

http://www.advancedmcode.org/power-flow-analysis-toolboxpfatb.html

For another, its duplicate copy and latest version is uploaded and released on Mathworks Cen-tral File Exchange and search PFATB 1to download as well.

Please follow the download instructions. And then place the files in a location in your ownpath. It is highly recommended that the files for this toolbox are stored in a directory namedPFATB off the main MATLAB toolbox directory.

A number of demonstrations are available in the file DOC which include some simple typ-ical problems of power flow and user’s documentations. The codes of examples illustrated inthis manuscript are located in TEST_FUNC document. It is certain that these test examples aredemonstrated and discussed in detail in Toolbox Functions Section and IEEE 30-Bus Test SystemSection.

In addition, PFATB can be obtained freely and anyone can use it. Because PFATB is free toolboxyou are encouraged to help make PFATB more useful by writing and contributing additionalfunctions for it, and by reporting any problems you may have. But any publications derived fromPFATB must be consented by the author in written permission. If you have any questions, pleasesend an email to contact me via [email protected]. Also you can contact me via GoogleVoice:+1-315-220-0696. I hope it’ll help our communications.

1See http://www.mathworks.com/matlabcentral/fileexchange/30272

Page 13: pfatb_v1.0a

Introduction to PFATB 5

4 TOOLBOX DESIGN

4.1 Toolbox Design Process

The power flow problem is the computation of voltage magnitude and phase angle at each busin a power system under balanced three-phase steady-state conditions. The designs of usefulutilities translated into the MATLAB language are the primary and most useful goals of usersto make it as tools. I have been eager to find a valid way to solute power flow, which should beuseful in a separable, clearly and understandable way to visualize its computations. Subtasks orsubprograms can do some specific part of the main mask. It is much easier to read subprogramsthat have fewer lines, than main task, and thus it is certain to help you enhance codes readabilityin Gauss-Seidel algorithm, Newton-Raphson algorithm and P-Q decoupling algorithm.

The gaols of this toolbox tool design are that it rapidly works, easily be read and clearly un-derstood. Firstly, set up a flow chart in steps as a draft; secondly, add the programming essen-tial steps into the flow chart; thirdly, try to translate the flow chart into programming language.Overall, the flow chart, interpreted as programming design outline, is one of the most key body ofprogramming. This is why I always write programming in steps in each section as preliminariesbefore introducing algorithm functions(which are described later in Section 7).

Observe the following approaches to prepare this toolbox global design and its main processare outlined below.

Input Raw Data

Data

Pre-processing

Execute

Algorithms

Converged?

Data

Reconfiguration

Output Solution

N

Y

FIGURE 4.1: Flowchart for toolbox design

Step1: Input Raw Data. Input the electrical grid data, with containing varieties of infor-

Page 14: pfatb_v1.0a

6 Introduction to PFATB

mation: bus data, transmission line data and transformer data. To make the computation moresignificant, we must adopt one data structure to be used as standard(which we will describe inputdata structure later).

Step2: Data Pre-processing. This step consists of two small steps. First, Sort Bus Numbers.Observing from bus data and line data, we find that the bus numbers aren’t in sequence of bustype, and that may result in reducing efficiency in solving problems, and augmenting the numberof iterations, computation time, and memory space. So, it’s necessary to predefine the order ofbus numbers in the data. Second, Data Regeneration. Along with all the changes in bus numbers,line data and bus data should be specified to change simultaneously.

Step3: Execute Algorithms. The power flow algorithms are normally including Gauss-Seidelalgorithm, Newton-Raphson algorithm, P-Q Decoupling algorithm and so forth will be discussedstep by step in Section 7.

Step4: Data Reconfiguration. Due to variation in order of bus numbers happened in Step 2,another reconfiguration must be performed to reset each bus number and its counterpart param-eters in its original order.

Step5: Output Solution. After the power flow evaluation, we can get the results, that is tosay, the final voltage magnitude and phase angle at each bus under balanced three-phase steady-state conditions. Additionally, as a by-product of this solution, real and reactive power flows inequipments such as transmission lines and transformers, as well as equipment losses, can also becomputed.

4.2 MATLAB Programming Style

In this part, I want to give some advice for readers about writing MATLAB programming codes.These suggestions, I think, every programmer should notice as guidelines to help produce codethat are more likely to be readable, understandable, sharable and maintainable. However, thispart isn’t include how to address efficiency concerns, with recommendations such as“Donąŕt useloops. ”Instead, it is all about writing programming style. The reader wishes to learn aboutthis toolbox design and style writing in more detail will be highly encouraged to study MATLABProgramming Style Guidelines by Richard Johnson, which is complied in another document onDatatool. In a word, as Brian Kernighan, one of the world renowned authors of The Practiceof Programming, writes, “Well-written programs are better than badly-written ones––they havefewer errors and are easier to debug and to modify––so it is important to think about style fromthe beginning.”

Page 15: pfatb_v1.0a

Introduction to PFATB 7

5 STANDARDDATA STRUCTURES

The data files importing to PFATB are in a specific structure by using MATLAB M-files or MAT-files which is inspired by Hadi Saadat in Chapter 6(DATA PREPARATION) of [2] so that to con-tinue its input data format with brevity and clarity.

The input data includes bus data, line data and transformer data. The format of the data is sim-ilar to IEEE format described in "Common Format for Exchange of Solved Load Flow Data",IEEETRANS on PAS, Vol-92, No.6, Nov./Dec., 1973, pp. 1916-1925. Additionally, it is pointed out thegeneral base MVA is at 100MVA.

5.1 Bus Data

The format for the bus entry is chosen to facilitate the required data for each bus in a single row.The information in bus data shown in Table 5.1 and Table 5.2 which are considered as the formatof the input matrix. Column 1 contains bus numbers. Column 2 contains bus types. Columns 3and 4 contain voltage magnitude in per unit and phase angle in degrees. Columns 5 and 6 areload MW and Mvar. Column 7 through 10 contain MW, Mvar, minimum Mvar and maximumMvar of generation, in that order. The last column is the injected Mvar of shunt capacitors. Thebus type entered in column 2 is used for identifying load, voltage-controlled, and slack buses asoutlined below.

TABLE 5.1: Bus Data Structure In Polar CoordinateBus Bus Voltage Angle —-Load—- ———-Generator———- InjectedNo Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar

TABLE 5.2: Bus Data Structure In Rectangular CoordinateBus Bus Real Imaginary —-Load—- ———-Generator———- InjectedNo Type e f MW Mvar MW Mvar Qmin Qmax Mvar

• 1-PQ This type means to be used for load buses. The loads are entered positive in inputtingmegawatts and megavars; negative in outputting megawatts and megavars by the powersystem. For this bus, initial voltage estimations must be specified. This is usually 1 and 0for voltage magnitude and phase angle, respectively.

• 2-PV This type means to be used for voltage-controlled buses. For this bus, voltage mag-nitude, real power generation in megawatts, and the minimum and maximum limits of themegavar demand must be specified.

• 3-Swing bus This type means to be used for swing bus, or called slack bus, or called ref-erence bus. The swing bus is general only one in the power system. The only necessaryinformation for this bus is the voltage magnitude and its phase angle. At the swing bus,voltage magnitude and its phase angle must be specified. Generally speaking, the phaseangle degree is zero.

5.2 Transmission Line Data and Transformer Data

The format for line data is designed to facilitate the required data for each line in a single rowas shown in Table 5.3. Columns 1 and 2 contain bus numbers. Columns 3 through 5 contain the

Page 16: pfatb_v1.0a

8 Introduction to PFATB

line resistance, reactance, and one-half of the total line charging susceptance in per unit on thespecified MVA base. The last column is for the transformers tap setting. It will be described anddiscussed in the following.

TABLE 5.3: Line Data StructureBus Bus R X 1/2B Tr.Tap Settingnl nr p.u. p.u. p.u. p.u.

Transformer DataTwo-winding transformer or three-winding transformer data is included in last column of

line data structure. At each line, 1 must be entered in this column due to no transformers on thistransmission line. The lines may be entered in any sequence or order with the only restrictionbeing that if the entry is a transformer, the left bus number is defined as the tap side of thetransformer.

Let us discuss a two-winding transformer, which is the also basic component of three-windingtransformer, represented by the equivalent PI circuit as shown in Figure 5.1. The transformer tapratio is setting as 1:k∗. The branch admittance elements can be calculated from its PI equivalentcircuit.

i j1: k*

YT

i jYT/k*

k*-1

k*YT

k*-1

k*YT2

FIGURE 5.1: Diagram of a two-winding transformer circuit

The branch self-admittance of bus i is obtained by the following equation.

Yi = Ym//YTk∗ − 1k∗

+YTk∗

(5.1)

If Ym is neglected, we rearrange (5.1)

Yi = YT (5.2)

The branch self-admittance of bus j is obtained by the following equation.

Yj = YT1− k∗k∗

2 +YTk∗

=YTk∗

2 (5.3)

5.3 Transmission Line Admittance Data

The format for line admittance data is designed to show the line admittance matrix of the powersystem network in Table 5.4. Columns 1 and 2 contain the bus numbers. Column 3 contains line

Page 17: pfatb_v1.0a

Introduction to PFATB 9

admittance between bus nl and bus nr. Column 4 contains branch admittance at bus nl in perunit; while column 5 contains branch admittance at bus nr in per unit on the specified MVA base.

TABLE 5.4: Line Admittance Data StructureBus Bus LineAdmittance BranchAdmittance BranchAdmittancenl nr p.u. at bus nl p.u. at bus nr p.u.

5.4 Transmission Line Flow and Loss Data

The format for line flow and loss data is designed to show the final solution of line flows andlosses for each line in a single row. Columns 1 and 2 contain bus numbers. Column 3 containsthe line power flows from bus nl to bus nr in per unit; while column 4 contains the line powerflows from bus nr to bus nl in per unit on the specified MVA base. The last column is for thetransmission line power losses between bus nr and bus nl.

TABLE 5.5: Line Flow and Loss Data StructureBus Bus Power Flow Power Flow –Power Loss–nl nr nl to nr nr to nl MW Mvar

Let us illustrate an example to demonstrate the data preparation with standard data struc-tures.

Figure 5.2 shows a single-line diagram of a 5-bus power system. Input data are given in Table5.6, 5.7, 5.8, and the per-unit quantities are based on their own ratings. As shown in Table 5.6,bus 5, to which a generator is connected, is the swing bus. Bus 4, to which a generator and a loadare connected, is a voltage-controlled bus. Buses 1,2 and 3 are load buses. Note that the load atbuses 1, 2 and 3 are inductive since Q1, Q2 and Q3 should be negative.

bus 4

bus 3bus 2

bus 5

bus 1

j0.015

1:1.05

0.08+j0.30

j0.25

j0.25

j0.25

0.04+j0.25

0.1+j0.35

j0.030

2+j1 3.7+j1.3

1.6+j0.8

U =1.05

delta =05

5

T-L T-R

Generator Generator

1.05:1j0.25

FIGURE 5.2: One-line Diagram of a 5-bus power system

Page 18: pfatb_v1.0a

10 Introduction to PFATB

TABLE 5.6: Bus DataBus Type Voltage Angle PG QG PL QL QGmax QGmin

p.u. Degree MW Mvar MW Mvar Mvar Mvar1 Load - - 0 0 1.6 0.8 - -2 Load - - 0 0 2 1 - -3 Load - - 0 0 3.7 1.3 - -4 Controlled 1.05 - 5 - 0 0 -50 505 Swing 1.05 0 - - 0 0 -50 50

TABLE 5.7: Line DataBus R X 1/2B Max MVA

to Bus p.u. p.u. p.u p.u.1-2 0.04 0.25 0.25 121-3 0.01 0.35 0 122-3 0.08 0.30 0.25 12

TABLE 5.8: Transformer DataBus R X 1/2B Tap Setting

to Bus p.u. p.u. p.u p.u.2-4 0 0.015 0 1.053-5 0 0.030 0 1.05

For each bus k, determine which of the variables: voltage magnitude Uk , phase angle δk , netreal power Pk and reactive power Qk are input data and which are unknowns. At each bus, twoof these variables are specified as input data, and the other two are unknowns to be computed bythe power-flow program.

The Table 5.9 and Table 5.10 are listed bus standard data for PFATB. The initial voltage mag-nitude of each PQ bus labeled in type 1 estimate 1 and its phase angle estimate 0. The initialvoltage magnitude of each PV bus labeled in type 2 estimate 1.05 and its phase angle estimate 0,respectively. The initial voltage magnitude of the slack bus labeled in type 3 estimate 1.05 andits phase angle estimate 0. In Table 5.10, the initial voltage real part e of each PQ bus labeled intype 1 estimate 1 and its imaginary part f estimate 0. The initial voltage real part e of each PV buslabeled in type 2 estimate 1.05 and its imaginary part f estimate 0. The initial voltage real part eof the slack bus labeled in type 3 estimate 1.05 and its imaginary part f estimate 0. Note that bus1-3 are load buses with no generations, and their real power P and reactive power Q should benegative; on the contrary, if the power supplies to buses 1-3, P and Q are positive.

Let us discuss how to specify transformer data. In Figure 5.2, we find that on the right of bus4 is the entry of a two-winding transformer labeled as T-L, and on the left of bus 5 is the entryof another two-winding transformer labeled as T-R. We may observe that T-L is a step-up trans-former, while T-R is a step-down transformer. Owing to the difference types of the transformers,we discuss them in separate steps.

Figure 5.3 shows the PI equivalent circuit of the T-L transformer. We can calculate bus admit-tance matrix of the T-L transformer as follows.

Page 19: pfatb_v1.0a

Introduction to PFATB 11

bus 4 bus 2

j0.015

1:1.05

bus 4 bus 2

High voltageLow voltage

YT/k

1-k

k2 YTk-1

kYT

FIGURE 5.3: PI equivalent circuit of the T-L transformer

If we neglect the other branches on bus 2, we get

Y44 = YT =1

j0.015= −j66.66

Y22 =YTk2∗

=

1j0.0151.052

= −j60.46

Likewise, we calculate bus admittance matrix of the T-R transformer as follows.

bus 3 bus 5

j0.030

1.05:1

bus 3 bus 5

High voltage Low voltage

YT/k

1-k

k2 YTk-1

kYT

FIGURE 5.4: PI equivalent circuit of the T-R transformer

If we neglect the other branches on bus 3, we get

Y55 = YT =1

j0.030= −j33.33

Y33 =YTk2∗

=

1j0.0301.052

= −j30.23

In the process of the above calculations, we can draw a conclusion k∗ is on the same side ofthe high-voltage rating. We know that bus 2 is the tap side of the T-L transformer, so the left busnumber is 2. Therefore, the tap ratio equals 1.05, when bus 2 to bus 4 is filled in the tabulatedblank. And about T-R transformer, vice versa. Table 5.11 is listed line standard data for PFATB.

Page 20: pfatb_v1.0a

12 Introduction to PFATB

TABLE 5.9: Bus Data Structure In Polar CoordinateBus Bus Voltage Angle —-Load—- ———-Generator———- InjectedNo Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar1 1 1 0 -1.6 -0.8 0 0 0 0 02 1 1 0 -2 -1 0 0 0 0 03 1 1 0 -3.7 -1.3 0 0 0 0 04 2 1.05 0 0 0 5 0 -50 50 05 3 1.05 0 0 0 0 0 -50 50 0

TABLE 5.10: Bus Data Structure In Rectangular CoordinateBus Bus Real Imaginary —-Load—- ———-Generator———- InjectedNo Type e f MW Mvar MW Mvar Qmin Qmax Mvar1 1 1 0 -1.6 -0.8 0 0 0 0 02 1 1 0 -2 -1 0 0 0 0 03 1 1 0 -3.7 -1.3 0 0 0 0 04 2 1.05 0 0 0 5 0 -50 50 05 3 1.05 0 0 0 0 0 -50 50 0

TABLE 5.11: Line Data StructureBus Bus R X 1/2B Tr.Tap Settingnl nr p.u. p.u. p.u. p.u.1 2 0.04 0.25 0.25 11 3 0.01 0.35 0 12 3 0.08 0.30 0.25 12 4 0 0.015 0 1.053 5 0 0.030 0 1.05

Page 21: pfatb_v1.0a

Introduction to PFATB 13

6 TOOLBOX FUNCTIONS

In this section, we start to introduce PFATB toolbox functions. It begins with a list of functionscategorized by steps in toolbox design process. Each functions will be described in a sequence ofits utility intention, function syntax and its description. Information about individual functionsis also available through the function help facility in MATLAB command window.

6.1 Data Pre-processing

sortbus returns the bus data matrix in the required sequence of bus type(PQ-PV-Swing).

Syntax

[bus,line,nPQ,nPV,nodenum] = sortbus(bus,line)

Description

[bus,line,nPQ,nPV,nodenum] = sortbus(bus,line) returns the standard bus data and standardline data in the required sequence of bus type(PQ-PV-Swing), described in Section 5; nPQ andnPV are the counts of the PQ & PV bus numbers; nodenum is the matrix to record which busnumber is to be changed.

Example 6.1

As shown in Figure 6.1, the 3-bus sample system is tested for processing standard data. TheM-file ex1.m is the program codes to exemplify how to present solutions of the sorting process.Try the following:

1 3

2

0.01+j0.04 -j3.03y30

0.05+j0.20

FIGURE 6.1: 3-bus sample system

% ex1.mclc;clear all

%% Bus data% Bus Bus Voltage Angle −−−Load−−− −−−−−−Generator−−−− Injected% No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvarbus = [1 3 1 0 0 0 0 0 0 0 0

2 1 1 0 0.8 0.6 0 0 0 0 0

Page 22: pfatb_v1.0a

14 Introduction to PFATB

3 2 1.1 0 0 0 0.4 0 0 0 0];

%% Line data% Bus Bus R X 1/2 B Tr.Tap Setting% nl nr p.u. p.u. p.u. p.u.line = [1 3 0.05 0.20 0 1

2 1 0.01 0.04 0 13 0 0 0 −3.03 1];

[bus,line,nPQ,nPV,nodenum] = sortbus(bus,line)format bank

The ex1.m results in

bus =1.00 1.00 1.00 0 0.80 0.60 0 0 0 0 02.00 2.00 1.10 0 0 0 0.40 0 −0.5 0.5 03.00 3.00 1.00 0 0 0 0 0 −0.5 0.5 0

line =3.00 2.00 0.05 0.20 0 1.001.00 3.00 0.01 0.04 0 1.002.00 0 0 0 −3.03 1.00

nPQ =1.00

nPV =1.00

nodenum =1.00 2.002.00 3.003.00 1.00

busAM returns the bus admittance matrix.

Syntax

Y = busAM(bus,line)

Description

Y = busAM(bus,line) returns bus admittance matrix. Its diagonal element Yii is known asthe self-admittance or driving point admittance of bus i, which equals the sum of all branchadmittances connecting to bus i. The off-diagonal element of the bus admittance matrix Yij isknown as the mutual admittance or transfer admittance, which equals the negative of branchadmittance connecting bus i to bus j. If there’s no line between the nodes, the term of admittanceis zero.

Bpq returns the bus admittance matrix B′ and B′′.

Syntax

[B1,B2,Y] = Bpq(bus,line,nPQ,model)

Description

These are three methods introduced in Chapter 2 of [1] to handle bus admittance matrix usedin the real and reactive power fast decoupling power flow.

Page 23: pfatb_v1.0a

Introduction to PFATB 15

[B1,B2,Y] = Bpq(bus,line,nPQ,’simplified’) returns the bus admittance B′ and B′′ with simpli-fied method. The matrix B′ and B′′ only contain the imagination part of bus admittance matrix.If the model is omitted, ’simplified’ is set in default.

[B1,B2,Y] = Bpq(bus,line,nPQ,’XB’) returns the bus admittance B′ and B′′ with XB method––the resistance is ignored during the calculation of B′, expressed in (6.1)∼(6.4).

B′

ij = −1xij

(6.1)

B′

ii =n∑j,i

xij (6.2)

B′′

ij = −xij

r2ij + x2ij(6.3)

B′′

ii = −n∑j,i

B′′

ij (6.4)

[B1,B2,Y] = Bpq(bus,line,nPQ,’BX’) returns the bus admittance B′ and B′′ with BX method––theresistance is ignored during the calculation of B′′, expressed in (6.5)∼(6.8).

B′

ij = −xij

r2ij + x2ij(6.5)

B′

ii =n∑j,i

xij

r2ij + x2ij(6.6)

B′′

ij = −1xij

(6.7)

B′′

ii = −n∑j,i

B′′

ij (6.8)

lineAM returns the line admittance matrix.

Syntax

YtYm = lineAM(line)

Description

YtYm = lineAM(line) returns line admittance matrix. The data structure of YtYm is tabulatedin Table 5.4.

Example 6.2

Page 24: pfatb_v1.0a

16 Introduction to PFATB

3

21

0.0125+j0.025

256.6MW

110.2Mvar

0.01+j0.03

0.02+j0.04

138.6MW 45.2Mvar

Slack Bus

V1=1.05 0

FIGURE 6.2: The impedance diagram of a simple system

As shown in Figure 6.2, the 3-bus power system is tested for bus admittance matrix by state-ment commands busAM, Bpq and line admittance matrix by statement command lineAM. Theexample is taken from [2] Example 6.7. The M-file ex2.m is the program codes to exemplify howto present solutions of evaluating Ybus and Yline. Try the following:

% ex2.mclc;clear all

%% Bus data% Bus Bus Voltage Angle −−−Load−−− −−−−−−Generator−−−− Injected% No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvarbus = [1 3 1.05 0 0 0 0 0 0 0 0

2 2 1 0 −2.566 −1.102 0 0 0 0 03 2 1 0 −1.386 −0.452 0 0 0 0 0];

%% Line data% Bus Bus R X 1/2 B Tr.Tap Setting% nl nr p.u. p.u. p.u. p.u.line = [1 2 0.02 0.04 0 1

1 3 0.01 0.03 0 12 3 0.0125 0.025 0 1];

% Evaluate YbusY = busAM(bus,line)

% Evaluate YbusnPQ = find(bus(:,2) == 2);[B1,B2] = Bpq(bus,line,nPQ,'simplified')[B1,B2] = Bpq(bus,line,nPQ,'XB')[B1,B2] = Bpq(bus,line,nPQ,'BX')

% Evaluate YlineYtYm = lineAM(line)

The ex2.m results in

Y =20.0000 −50.0000i −10.0000 +20.0000i −10.0000 +30.0000i−10.0000 +20.0000i 26.0000 −52.0000i −16.0000 +32.0000i−10.0000 +30.0000i −16.0000 +32.0000i 26.0000 −62.0000i

Page 25: pfatb_v1.0a

Introduction to PFATB 17

B1 =−50 2020 −52

B2 =−50 2020 −52

B1 =−58.3333 25.000025.0000 −65.0000

B2 =−50 2020 −52

B1 =−50 2020 −52

B2 =−58.3333 25.000025.0000 −65.0000

YtYm =Columns 1 through 41.0000 2.0000 10.0000 −20.0000i 01.0000 3.0000 10.0000 −30.0000i 02.0000 3.0000 16.0000 −32.0000i 0

Column 5000

6.2 Execute Algorithms

The algorithms in PFATB toolbox are Gauss-Seidel algorithm, Newton-Raphson algorithm andP-Q decoupling algorithm. In each algorithm, it is useful to decompose major tasks into subtasksthat do specific parts of the main task. So does the major algorithm program. It is much eas-ier to read subprograms that a fewer lines, than one large main program that doesn’t segregatethe subtasks effectively, particularly if all the power flow algorithms to be solved are relativelycomplicated. Each subtask are designed so that it can be evaluated in the testing phase of thedesign process. As an addition, the specifications and the brief descriptions of function purposeare added enough in comments to provide the function’s task so as to remind you exactly whatwas done and for what purpose.

busVnewPQ returns new bus voltage at each PQ bus in Gauss-Seidel algorithm.

Syntax

busV_PQ = busVnewPQ(busV,Y,P,Q,n,nPQ)

Description

busV_PQ = busVnewPQ(busV,Y,P,Q,n,nPQ) returns new bus voltage at each PQ bus from thefollowing equation.

U(k+1)i =

Pi − jQi

U∗(k)i

−n∑

j=1

YijU(k+1)j

Yii(i , j) (6.9)

where i indicates bus i is a only PQ bus in system.

Page 26: pfatb_v1.0a

18 Introduction to PFATB

busVnewPV returns new bus voltage and reactive power of each PV bus in Gauss-Seidel algo-rithm.

Syntax

[busV_PV,Q_PV] = busVnewPV(busV,bus0,Y,P,Q,n,nPQ)

Description

[busV_PV,Q_PV] = busVnewPV(busV,bus0,Y,P,Q,n,nPQ) returns new bus voltage and reactivepower of each PV bus from the following equation.

U(k+1)i =

Pi − jQi

U∗(k)i

−n∑

j=1

YijU(k+1)j

Yii(i , j) (6.10)

where i indicates bus i is a only PV bus in system.

Q(k+1)i = −ℑ

U ∗(k)i [U (k)i Yii +

n∑j=1

YijU(k+1)j ]

(i , j) (6.11)

where i indicates bus i is a only PV bus in system.

dPQpm returns ∆Pi and ∆Qis respectively from real power mismatch equations in Newton-Rapson with polar coordinate method.

Syntax

[delta_P,delta_Q] = dPQpm(bus,nPQ,Y)

Description

[delta_P,delta_Q] = dPQpm(bus,nPQ,Y) returns ∆Pi and ∆Qis respectively from real powermismatch equations as follows. Note that ∆Pi contains each PV and PQ bus, and ∆Qis onlycontains each PQ bus.

∆Pi = Pis − Pi = Pis −Ui

n∑j=1

Uj(Gijcosθij +Bijsinθij ) (6.12)

∆Qis =Qis −Qi +Qvari =Qis +Qvari −Ui

n∑j=1

Uj(Gijsinθij −Bijcosθij ) (6.13)

where Pis,Qis are the active power and reactive power supplied from generations. Qvari is theinjected reactive power from shunt capacitors like capacitors, SVC and so forth.

dPQcm returns ∆P , ∆Q and ∆U2 respectively from real power mismatch equations in Newton-Rapson with rectangular coordinate method.

Syntax

[delta_P,delta_Q,delta_U] = dPQcm(bus,bus0,nPQ,Y)

Page 27: pfatb_v1.0a

Introduction to PFATB 19

Description

[delta_P,delta_Q,delta_U] = dPQcm(bus,bus0,nPQ,Y) returns ∆P , ∆Q and ∆U2 respectivelyfrom real power mismatch equations as follows.

For each PQ bus, dPQcm evaluates the following power mismatch equations

∆Pi = Pis − Pi = Pis − ein∑

j=1

(Gijej −Bijfj )− fin∑

j=1

(Gijfj +Bijej ) (6.14)

∆Qi =Qis +Qvari −Qi =Qis +Qvari − fin∑

j=1

(Gijej −Bijfj ) + ei

n∑j=1

(Gijfj +Bijej ) (6.15)

For each PV bus, dPQcm evaluates the following power mismatch equations

∆PP V = PP V 0 − PP V = PP V 0 − eP Vn∑

j=1

(GP V jej −BP V jfj )− fP Vn∑

j=1

(GP V jfj +BP V jej ) (6.16)

∆U2P V =U2

P V 0 −U2P V =U2

P V 0 − (f2P V + e2P V ) (6.17)

Jacpm returns Jacobian submatrix elements of H,N,K,L in Newton-Rapson with polar coordi-nate method.

Syntax

J = Jacpm(bus,Y,nPQ)

Description

J = Jacpm(bus,Y,nPQ) returns the Jacobian submatrix H,N,K,L equations as follows.

Hij = −UiUj(Gijsinθij −Bijcosθij ) (i , j) (6.18)

Hii =U2i Bii +Qi (i = j) (6.19)

Nij = −UiUj(Gijcosθij −Bijsinθij ) (i , j) (6.20)

Nii = −U2i Gii − Pi (i = j) (6.21)

Kij =UiUj(Gijcosθij −Bijsinθij ) (i , j) (6.22)

Kii = −U2i Gii − Pi (i = j) (6.23)

Lij = −UiUj(Gijsinθij −Bijcosθij ) (i , j) (6.24)

Lii =U2i Bii −Qi (i = j) (6.25)

Page 28: pfatb_v1.0a

20 Introduction to PFATB

where

Pi =Ui

n∑j=1

Uj(Gijcosθij +Bijsinθij )

Qi =Ui

n∑j=1

Uj(Gijsinθij −Bijcosθij )

The element Hij =∂∆Pi∂∆δj

indicates that the PQ buses and the PV buses are both included in the

rows and columns of H. H is a (n-1)×(n-1) matrix.

The element Nij =∂∆Pi∂∆Uj

Uj indicates that the PQ buses and the PV buses are included in the

rows of N, and also the PQ buses are included in the columns of N. L is a (n-1)×(n-1-nPV) matrix.

The element Kij =∂∆Qi

∂∆δjindicates that the PQ buses are included in the rows of K, and also

the PQ buses and the PV buses are included in the columns of K. K is a (n-1-nPV)×(n-1) matrix.

The element Lij =∂∆Qi

∂∆UjUj indicates that the PQ buses are included in the rows of L, and also

the PQ buses are included in the columns of L. L is a (n-1-nPV)×(n-1-nPV) matrix.

Jaccm returns Jacobian submatrix elements of H,N,K,L,R,S in Newton-Rapson with rectangularcoordinate method.

Syntax

J = Jaccm(bus,Y,nPQ)

Description

J = Jaccm(bus,Y,nPQ) returns Jacobian submatrix H,N,K,L,R,S equations as follows.

Hij = −(Gijei +Bijfi) (i , j) (6.26)

Hii = −n∑

j=1

(Gijej −Bijfj )−Giiei −Biifi (i = j) (6.27)

Nij = −(Gijfi −Bijei) (i , j) (6.28)

Nii = −n∑

j=1

(Gijfj +Bijej )−Giiei +Biifi (i = j) (6.29)

Kij = Gijei +Bijfi (i , j) (i , j) (6.30)

Kii =n∑

j=1

(Gijfj +Bijej )−Giifi +Biiei (i = j) (6.31)

Page 29: pfatb_v1.0a

Introduction to PFATB 21

Lij = Gijfi −Bijei (i , j) (6.32)

Lij = 0 (i , j) (6.33)

Lii = −2ei (i = j) (6.34)

Rij = 0 (i , j) (6.35)

Rii = −2fi (i = j) (6.36)

The element Hij =∂∆Pi∂fj

indicates that the PQ buses and the PV buses are both included in the

rows and columns of H. H is a (n-1)×(n-1) matrix.

The element Nij =∂∆Pi∂ej

indicates that the PQ buses and the PV buses are both included in the

rows and columns of N. N is a (n-1)×(n-1) matrix.

The element Kij =∂∆Qi

∂fjindicates that the PQ buses are included in the rows of K, and also the

PQ bus and the PV buses are both included in the columns of K. K is a (n-1-nPV)×(n-1) matrix.

The element Lij =∂∆Qi

∂ejindicates that the PQ buses are included in the rows of L, and also the

PQ buses and the PV buses are both included in the columns of L. L is a (n-1-nPV)×(n-1) matrix.

The element Rij =∂∆U2

p

∂ejindicates that the PV buses are included in the rows of R, and also

the PQ buses and the PV buses are both included in the columns of R. R is a (nPV)×(n-1) matrix.

The element Sij =∂∆U2

p

∂fjindicates its dimension is the same as R .

HLpq returns Jacobian submatrix H,L in P-Q fast decoupling with polar coordinate method.

Syntax

[H,L] = HLpq(bus,nPQ,B1,B2)

Description

[H,L] = HLpq(bus,nPQ,B1,B2) returns Jacobian submatrix H,L equations as follows.

∆P = −H∆θ =UB′U∆θ (6.37)

∆Q = −LU−1∆U =UB′′∆U (6.38)

dAM returns ∆θ and ∆U in Newton-Rapson with polar coordinate method.

Syntax

[dU,dAng] = dAM(bus,nPQ,Jacobi,delta_P,delta_Q)

Description

Page 30: pfatb_v1.0a

22 Introduction to PFATB

[dU,dAng] = dAM(bus,nPQ,Jacobi,delta_P,delta_Q) returns θ and ∆U by solving the powerflow matrix equation as follows. [

∆P∆Q

]= −

[H NK L

][∆θ

U−1∆U

](6.39)

where

[∆P∆Q

]=

∆P1∆P2...

∆Pn−1∆Q1∆Q2...

∆Qn−1−nPV

[H NK L

]=

H1,1 H1,2 . . . H1,n−1...

......

...Hn−1,1 Hn−1,2 . . . Hn−1,n−1

N1,1 N1,2 . . . N1,n−1...

......

...Nn−1,1 Nn−1,2 . . . Nn−1,n−1−nP V

K1,1 K1,2 . . . K1,n−1...

......

...Kn−1−nP V ,1 Kn−1−nP V ,2 . . . Kn−1−nP V ,n−1

L1,1 L1,2 . . . L1,n−1...

......

...Ln−1−nP V ,1 Ln−1−nP V ,2 . . . Ln−1−nP V ,n−1−nP V

[∆θ

∆U−1∆U

]=

∆θ1∆θ2...

∆θn−1∆U−1U1∆U−1U2

...∆U−1Un−1

dPQU returns ∆e and ∆f in Newton-Raphson with rectangular coordinate method.

Syntax

[df,de] = dPQU(bus,Jacobi,delta_P,delta_Q,delta_U)

Description

[df,de] = dPQU(bus,Jacobi,delta_P,delta_Q,delta_U) returns ∆e and ∆f by following equa-tions.

∆P∆Q∆U2

= −H NK LR S

[∆e∆f

](6.40)

Page 31: pfatb_v1.0a

Introduction to PFATB 23

where

∆P∆Q∆U2

=

∆P1∆P2...

∆Pn−1∆Q1∆Q2...

∆Qn−1−nPV∆U2

1∆U2

2...

∆U2nPV

H NK LR S

=

H11 H12 . . . H1,n−1...

......

...Hn−1,1 Hn−1,2 . . . Hn−1,n−1

N11 N12 . . . N1,n−1...

......

...Nn−1,1 Nn−1,2 . . . Nn−1,n−1

K11 K12 . . . K1,n−1...

......

...Kn−1−nP V ,1 Kn−1−nP V ,2 . . . Kn−1−nP V ,n−1

L11 L12 . . . L1,n−1...

......

...Ln−1−nP V ,1 Ln−1−nP V ,2 . . . Ln−1−nP V ,n−1

R11 R12 . . . R1,n−1...

......

...RnP V ,1 RnP V ,2 . . . RnP V ,n−1

S11 S12 . . . S1,n−1...

......

...SnP V ,1 SnP V ,2 . . . SnP V ,n−1

[∆f∆e

]=

∆f1∆f2...

∆fn−1∆e1∆e2...

∆en−1

dApq returns ∆θ in P-Q fast decoupling with polar coordinate method.

Syntax

dAng = dApq(bus,H,delta_P)

Description

dAng = dApq(bus,H,delta_P) returns ∆θ by the following equation.

∆P =UB′U∆θ (6.41)

dMpq returns ∆U in P-Q fast decoupling with polar coordinate method.

Syntax

Page 32: pfatb_v1.0a

24 Introduction to PFATB

dU = dMpq(bus,nPQ,L,delta_Q)

Description

dU = dMpq(bus,nPQ,L,delta_Q) returns ∆U by the following equation.

∆Q =UB′′∆U (6.42)

changePVpm examines reactive power of each PV bus in Newton-Raphson with polar coordi-nate method.

Syntax

bus_new = changePVpm(bus,Y,nPQ,k)

Description

bus_new = changePVpm(bus,Y,nPQ,k) examines reactive power of each PV bus. If the reactivepower of the PV bus exceeds the generations boundaries of secure limitations within the mini-mum and maximum, the controlled voltages of the PV bus should drop voltage magnitudes tobalance reactive power in power system.

changePVcm examines reactive power of each PV bus in Newton-Raphson with rectangular co-ordinate method.

Syntax

bus0_new = changePVcm(bus,bus0,Y,nPQ,k)

Description

bus0_new = changePVcm(bus,bus0,Y,nPQ,k) examines reactive power of each PV bus. If thereactive power of the PV bus exceeds the generations boundaries of secure limitations within theminimum andmaximum, the controlled voltages of each PV bus should drop voltage magnitudesto balance reactive power in power system.

powerSW returns active power and reactive power of the swing bus in Gauss-Seidel algorithm.

Syntax

S = powerSW(busV,Y,n)

Description

S = powerSW(busV,Y,n) returns active power and reactive power of the swing bus in Gauss-Seidel algorithm by using (6.9).

dPQSWPVpm returns reactive power of each PV bus and active power and reactive power of theswing bus with polar coordinate method.

Syntax

bus = dPQSWPVpm(bus,Y,nPQ)

Description

Page 33: pfatb_v1.0a

Introduction to PFATB 25

bus = dPQSWPVpm(bus,Y,nPQ) returns reactive power of each PV bus and active power andreactive power of the swing bus by the following equations.

After the iterative solution of bus voltage, the next step is to separate the complex powerequation (6.43) into real part and imaginary part to obtain reactive power of each PV bus andactive power and reactive power of the swing bus.

S̃s = U̇s

n∑j=1

(YsjUj )∗ (6.43)

At each PV bus, imaginary part of (6.43) is specified as the reactive power equation as follows.

QP V =n∑

j=1

UP VUj(GP V jsin(θP V −θj )−BP V jcos(θP V −θj ))−QP V l −QP V s (6.44)

where QP V l are the load reactive power and are negative. QP V s are the injected reactive powerfrom shunt capacitors and are positive. Note that UP V ∠θP V is the balanced voltage of the PV bus.

At the swing bus, real part and imaginary part of (6.43) are specified as the reactive powerequation and active power equation, respectively.

PSW =n∑

j=1

USWUj(GP V jcos(θSW −θj ) +BP V jsin(θSW −θj ))− PSW l (6.45)

QSW =n∑

j=1

USWUj(GSWjsin(θSW −θj )−BSWjcos(θSW −θj ))−QSW l (6.46)

where PSW l ,QSW l are the load active power and reactive power, and they are generally equal tozero. Note that USW ∠θSW is the balanced voltage of the swing bus.

dPQSWPVcm returns reactive power of each PV bus and active power and reactive power of theswing bus with rectangular coordinate method.

Syntax

bus = dPQSWPVcm(bus,Y,nPQ)

Description

bus = dPQSWPVcm(bus,Y,nPQ) returns reactive power of each PV bus and active power andreactive power of the swing bus by the following equations.

After the iterative solution of bus voltage, the next step is to separate the complex powerequation (6.43) into real part and imaginary part to obtain reactive power of each PV bus andactive power and reactive power of the swing bus.

At each PV bus, imaginary part of (6.33) is specified as the reactive power equation as follows.

QP V = −fP Vn∑

j=1

BP V jfP V j + eP V

n∑j=1

BP V jeP V j −QP V l −QP V s (6.47)

where QP V l are the load reactive power and are negative. QP V s are the injected reactive powerfrom shunt capacitors and are positive. Note that eP V +jfP V is the balanced voltage of the PV bus.

Page 34: pfatb_v1.0a

26 Introduction to PFATB

At the swing bus, real part and imaginary part of (6.43) are specified as the reactive powerequation and active power equation, respectively.

PSW = −eSWn∑

j=1

BSWjfSWj − fSWn∑

j=1

BSWjeSWj − PSW l (6.48)

QSW = −fSWn∑

j=1

BSWjfSWj + eSW

n∑j=1

BSWjeSWj −QSW l (6.49)

where PSW l ,QSW l are the load active power and reactive power, and they are generally equal tozero. Note that eSW + jfSW is the balanced voltage of the swing bus.

6.3 Data Reconfiguration

resetbus returns each bus numbers to the original bus numbers in the bus data matrix and theline data matrix.

Syntax

[bus_temp,line_temp] = resetbus(bus,line,nodenum)

Description

[bus_temp,line_temp] = resetbus(bus,line,nodenum) returns each bus numbers back to theoriginal bus numbers in the bus data matrix and the line data matrix.

6.4 Output Solution

powerTSpm returns transmission power line flow and loss with polar coordinate method.

Syntax

S_res = powerTSpm(bus,line,YtYm)

Description

S_res = powerTSpm(bus,line,YtYm) returns transmission line power flow and loss in the for-mat of Table 5.5 by using the following equations.

i j

ZTB

2

B

2

delta S ij~

S~

U jUiSij~

ji

FIGURE 6.3: Transmission line flow and loss

Transmission line flow

Page 35: pfatb_v1.0a

Introduction to PFATB 27

In Figure 6.3, S̃ij are the injected complex powers from bus i to bus j. The load flow from busnumber i to bus number j can be expressed as

S̃ij = U̇i[U̇iYi0 + (U̇i − U̇j )Yij ]∗ (6.50)

Rearranging (6.50) we can get

S̃ij = U̇2i (Y

∗ij +Y ∗i0)− U̇iU̇

∗j Y∗ij (6.51)

Similarly, S̃ji are the injected complex powers from bus j to bus i as also shown in Figure 6.3.The load flow from bus number j to bus number i can be expressed as

S̃ji = U̇j [U̇jYj0 + (U̇j − U̇i)Yji]∗ (6.52)

Rearranging (6.52) we can get

S̃ji = U̇2j (Y

∗ji +Y ∗j0)− U̇jU̇

∗i Y∗ji (6.53)

Transmission line lossTransmission line power loss ∆S̃ij can be expressed as

∆S̃ij = S̃ij + S̃ji (6.54)

powerTScm returns transmission line power flow and loss with rectangular coordinate method.

Syntax

S_res = powerTScm(bus,line,YtYm)

Description

S_res = powerTScm(bus,line,YtYm) returns transmission line power flow and loss in the for-mat of Table 5.5 by using equations (6.51), (6.53) and (6.54).

busout outputs each bus voltage magnitude and phase angle and its active and reactive power.Note that this function is a built-in function for Gauss-Seidel algorithm, Newton-Raphson algo-rithm and P-Q decoupling algorithm.

Syntax

busout(bus_res,delta_P,delta_Q,n,k)

Description

busout(bus_res,delta_P,delta_Q,n,k) outputs each bus voltage magnitudes and phase anglesand its active and reactive powers in tabulated format(See Section 7).

lineflow outputs each transmission line power flow and loss. Note that this function is a built-infunction for Gauss-Seidel algorithm, Newton-Raphson algorithm and P-Q decoupling algorithm.

Syntax

lineflow(s_res,n)

Description

lineflow(s_res,n) outputs each transmission line power flow and loss in the format of Table5.5(See Section 7).

Page 36: pfatb_v1.0a

28 Introduction to PFATB

busiter displays each bus increments at each iteration. Note that this function is a built-in func-tion for Gauss-Seidel algorithm, Newton-Raphson algorithm and P-Q decoupling algorithm.

Syntax

busiter(cell_bus,nodenum,n,k)

Description

busiter(cell_bus,nodenum,n,k) displays each bus increments at each iteration(See Section 7).

Page 37: pfatb_v1.0a

Introduction to PFATB 29

7 POWER FLOWALGORITHMS

This section demonstrates how power flow algorithms can be constructed in steps and usingroutines from PFATB toolbox to solve power flow problems.

7.1 Algorithm Convergence Speed

We define the sum of real and reactive power mismatch of each bus at each iterations as theconvergent speed until the iteration is terminated in the tolerance condition. The graph is con-structed to show the algorithm performance on convergence by using the following equations.

Algorithm convergence speed in polar coordinate:

Speed(∆U ) =

√√√n−nP V−1∑

i=1

∆U2 (7.1)

Speed(∆θ) =

√√√n−1∑i=1

∆θ2 (7.2)

Algorithm convergence speed in rectangular coordinate:

Speed(∆e) =

√√√n−1∑i=1

∆e2 (7.3)

Speed(∆f ) =

√√√n−1∑i=1

∆f 2 (7.4)

Page 38: pfatb_v1.0a

30 Introduction to PFATB

7.2 Gauss-Seidel Algorithm

The function GS.m returns to solve power flow in Gauss-Seidel algorithm.

Power-flow Programming Steps

Step 1: Input raw data. Input the electrical grid data in the standard data structure andestimate start points of the remaining undefined bus magnitude and phase angle.

Step 2: Data regeneration. Line data and bus data are specified to change along with busnumbers simultaneously.

Step 3: Evaluate Ybus. Evaluate bus admittance matrix.Step 4: Evaluate new bus voltage at each PQ bus. Evaluate new bus voltage real part ei and

new bus voltage imaginary part fi from nonlinear equation (6.9) at each PQ bus.Step 5: Update variables. Replace the precious bus voltage by substituting new bus voltage

at each PQ bus evaluated from step 4.Step 6: Evaluate new bus voltage and reactive power at each PV bus. Evaluate Ui and Qi

from nonlinear equation (6.10) and (6.11) at each PV bus.

Step 7: Evaluate ∆Q. Evaluate ∆Q(k+1)i by using the following equation.

∆Q(k+1)i =Q

(k+1)i −Q(k)

i (7.5)

Step 8: Update variables. Replace the precious bus voltage by substituting new bus voltageat each PV bus evaluated from Step 6.

Step 9: Termination conditions. The process is continued until the residuals ∆Q(k)i , evaluated

from Step 7, are less than tolerance accuracy as follows.

max|∆Q(k)i | < ε (7.6)

Note that ε is the small positive constant, such as 0.001,0.00001, and the smaller numbers arepretty more accurate.

Step 10: Evaluate power of the swing bus. Evaluate active power and reactive power of theswing bus by using (6.9).

Step 11: Reconfigure bus numbers. Return each bus number to the original bus number inbus data matrix and the line data matrix.

Step 12: Evaluate line flow and loss. Evaluate real and reactive power flows in transmissionlines and transformers, as well as equipment losses.

Step 13: Output solution. Show the final voltage magnitude and phase angle at each busunder balanced three-phase steady-state conditions.

Power-flow Program Function

A complete pseudo-code M-file GS.m of Gauss-Seidel algorithm is shown below.

function [bus_res,s_res,k] = GS(bus,line,EPS,kmax)% Gauss−Seidel Algorithm% [BUS_RES,S_RES,K] = GS(BUS,LINE,EPS,KMAX) returns the final bus voltage real part e% and imaginary part f and line flow and loss.%% [bus_res,S_res,k] = GS(bus,line) returns bus voltage bus_res, line flow and loss S_res,% iteration k at EPS=1.0e−6 and kmax = 100 in default.%% See also sortbus,busAM,busVnewPQ,busVnewPV,powerSW,resetbus,lineAM,powerTScm

Page 39: pfatb_v1.0a

Introduction to PFATB 31

% Author(s):Chao Lei% $Date:2011/02/02 02:40$

if nargin < 2error('Please input 2 variables');

end

if nargin == 2EPS = 1.0e−6; % Tolerance Accuracykmax = 100; % Maximum iterations

elseif nargin == 3kmax = 100; % Maximum iterations

end

format long

[bus,line,nPQ,nPV,nodenum] = sortbus(bus,line); % Step 2: Data Regeneration

n = nPQ+nPV+1;

Y = busAM(bus,line); % Step 3: Evaluate Ybus

% Sparse Symmetric Matrix Figureclf;figure(1)spy(Y);title('Ybus Sparse Symmetric Matrix')nz = nnz(Y);pct = 100 / numel(Y);xlabel(sprintf('nonzeros=%d (%.3f%%)',nz,nz*pct));grid on

j = sqrt(−1);

busV = zeros(n,1);% Complex power expressed in rectangular coordinatebusV = bus(1:n,3).*(cos(bus(1:n,4))+j*sin(bus(1:n,4)));busV_temp = zeros(n,1);

busV_PV = busV(nPQ+1:n−1,1); % Pre−allocatebusV_PQ = busV(1:nPQ,1);

de = zeros(n,1); % Pre−allocatedf = zeros(n,1);

P = zeros(n−1,1);Q = zeros(n−1,1);P = bus(1:n−1,5)+bus(1:n−1,7); % Active power PQ = bus(1:n−1,6)+bus(1:n−1,8)+bus(1:n−1,11); % Reactive power Q

% The Constant voltage magnitude of each PV busbus0 = zeros(n−1−nPQ,1);bus0(:,1) = bus(nPQ+1:n−1,3);

k = 1;

while (k ≤ kmax)% Step 4: Evaluate new bus voltage at each PQ busbusV_PQ = busVnewPQ(busV,Y,P,Q,n,nPQ);

Page 40: pfatb_v1.0a

32 Introduction to PFATB

busV = [busV_PQ;busV_PV;bus(n,3)+j*bus(n,4)]; % Step 5: Update Variables

% Step 6: Evaluate new bus voltage at each PV bus[busV_PV,Q_PV] = busVnewPV(busV,bus0,Y,P,Q,n,nPQ);

dQ = Q_PV − Q(nPQ+1:n−1,1); % Step 7: Evaluate delta Q

% Record Q for comparison at next iterationQ(nPQ+1:n−1,1) = Q_PV;busV = [busV_PQ;busV_PV;bus(n,3)+j*bus(n,4)]; % Step 8: Update Variables

de = real(busV − busV_temp); % Evaluate delta e and delta fdf = imag(busV − busV_temp);

dfrd(k,:) = df'; % Record the delta e and delta fderd(k,:) = de';

% Record bus for comparison at next iterationbusV_temp = busV;

if (max(abs(dQ))<EPS); % Step 9: Termination Conditionsbreak

end

% k equals kmax or notif (k == kmax);

disp('Solution is not accurate.Please increase the maximum iterations in INPUT argument.')break;

end

% Save Increments at each iterationbus_k = zeros(n−1,6);bus_k(:,1) = real(busV(n−1,:));bus_k(:,2) = imag(busV(n−1,:));bus_k(:,3) = de(n−1,:);bus_k(:,4) = df(n−1,:);bus_k(:,5) = Q − bus(1:n−1,6);bus_k(nPQ+1:n−1,6) = dQ;

[row,column] = size(bus_k);for i = 1:column

cell_bus{k,i} = bus_k(:,i);end

k = k+1; % Increase iterations

end% Show the graph of algorithm convergencexk = [1:k];dfrd_sq = sqrt(sum(dfrd.^2,2));derd_sq = sqrt(sum(derd.^2,2));

figure(2)plot(xk,dfrd_sq,'k',xk,derd_sq,'k−−','LineWidth',2)title('The Convergence Speed of Gauss−Seidel Algorithm')xlabel('Iterations');ylabel('Speed');legend('E Increments','F Increments')grid on

Page 41: pfatb_v1.0a

Introduction to PFATB 33

% Step 10: Evaluate Power of the swing busS = powerSW(busV,Y,n);

% Allocate and update variables into bus matrixbus(:,3) = real(busV);bus(:,4) = imag(busV);bus(n,7) = real(S);bus(n,8) = imag(S);bus(nPQ+1:n−1,8) = Q(nPQ+1:n−1,1) − bus(nPQ+1:n−1,6);

% Step 11: Reconfigure Bus Numbers[bus_temp,line_temp] = resetbus(bus,line,nodenum);

% Step 12: Evaluate line flow and lossYtYm = lineAM(line_temp);s_res = powerTScm(bus_temp,line_temp,YtYm);bus_res = bus_temp;

% Step 13: Output Solutionformat short

% Output Bus Solutiondisp(' ')disp(' Power Flow Solution by Gauss−Seidel Algorithm')busout(bus_res,dQ,n,k);

% Output Line Solutiondisp(' ')disp(' Transmission Line Flow and Loss')lineflow(s_res,n);

% Display output at each iterationdisp(' ')disp(' Display output at each iteration')busiter(cell_bus,nodenum,n,k)

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−busout(bus_res,dQ,n,k)

fprintf(' Maximum Active Power Mismatch = %g \n', max(abs(dQ)))fprintf(' No. of Iterations = %g \n\n', k)head =[' Bus Real Imaginary −−−Load−−− −−−Generation−−− Injected'

' No. E F MW Mvar MW Mvar Mvar '' '];

disp(head)for i = 1:n

fprintf(' %5g', bus_res(i,1)), fprintf(' %7.3f', bus_res(i,3)),fprintf(' %8.3f', bus_res(i,4)), fprintf(' %9.3f', bus_res(i,5)),fprintf(' %9.3f', bus_res(i,6)), fprintf(' %9.3f', bus_res(i,7)),fprintf(' %9.3f ', bus_res(i,8)), fprintf(' %8.3f\n',bus_res(i,11))

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f', sum(bus_res(:,5))),fprintf(' %9.3f', sum(bus_res(:,6))),fprintf(' %9.3f', sum(bus_res(:,7))),fprintf(' %9.3f', sum(bus_res(:,8))),fprintf(' %9.3f\n\n',sum(bus_res(:,11)))

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function lineflow(s_res,n)

Page 42: pfatb_v1.0a

34 Introduction to PFATB

head =[' '' Bus Bus Power Flow Power Flow −−−Power Loss−−−'' nl. nr. nl to nr nr to nl MW Mvar '' '];

disp(head)

for i = 1:nfprintf(' %5g', s_res(i,1)), fprintf(' %5.0f', s_res(i,2)),fprintf(' %9.3f+j%7.3f', real(s_res(i,3)),imag(s_res(i,3))),fprintf(' %9.3f+j%7.3f', real(s_res(i,4)),imag(s_res(i,4))),fprintf(' %9.3f', real(s_res(i,5))),fprintf(' %9.3f\n', imag(s_res(i,5))),

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,3))),sum(imag(s_res(i,3)))),fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,4))),sum(imag(s_res(i,4)))),fprintf(' %9.3f', sum(real(s_res(:,5)))),fprintf(' %9.3f\n\n', sum(imag(s_res(:,5))))

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function busiter(cell_bus,nodenum,n,k)

for i = 1:n−1disp(' ')fprintf(' Display each iteration at bus %g \n\n', nodenum(i,2))

head =[' Iter Real Imaginary Delta Delta Delta Delta '' No. E F E F P Q '' '];

disp(head)for m = 1:k−1

fprintf(' %6.4g', m),fprintf(' %10.5f', cell_bus{m,1}(i,:)),fprintf(' %10.5f', cell_bus{m,2}(i,:)),fprintf(' %9.5f', cell_bus{m,3}(i,:)),fprintf(' %9.5f', cell_bus{m,4}(i,:)),fprintf(' %9.5f', cell_bus{m,5}(i,:)),

fprintf(' %9.5f\n', cell_bus{m,6}(i,:))endend

Example 7.1

This example is taken from [2] Example 6.8. Figure 7.1 shows the one-line diagram of a simplethree-bus power system with generators at buses 1 and 3. The magnitude of voltage as bus 1 isadjusted to 1.05 per unit. Voltage magnitude at bus 3 is fixed at 1.04 pu with a real powergeneration of 200MW. A load consisting of 400MW and 250Mvar is taken from bus 2. Lineimpedances are marked in per unit on a 100 MVA base, and the line charging susceptances areneglected. Obtain the power flow solution by N-R algorithm with polar method. The M-fileex2.m is the program codes to exemplify how to present solutions of power flow.

Estimate start points of the remaining bus magnitude and phase angle as follows.

TABLE 7.1: The initial estimations of bus magnitude and phase anglebus number 1 2 3U (0)∠δ(0) 1.05∠0◦ 1∠0◦ 1.04∠0◦

Page 43: pfatb_v1.0a

Introduction to PFATB 35

3

21

400MW

250Mvar

0.02+j0.04

0.01+j0.03 0.0125+j0.025

Slack Bus

200MW

V1=1.05 0V3 = 1.04

FIGURE 7.1: One-line diagram of 3-bus system

Let us evaluate this example by calling GS.m to output solutions. Try the following:

% ex7.1.mclc;clear all

%% Bus data% Bus Bus Voltage Angle −−−Load−−− −−−−−−Generator−−−− Injected% No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvarbus = [1 3 1.05 0 0 0 0 0 −3.5 3.5 0

2 1 1 0 −4 −2.5 0 0 0 0 03 2 1.04 0 0 0 2 0 −3.5 3.5 0];

%% Line data% Bus Bus R X 1/2 B Tr.tap Setting% nl nr p.u. p.u. p.u. p.u.line = [1 2 0.02 0.04 0 1

1 3 0.01 0.03 0 12 3 0.0125 0.025 0 1];

%% Gauss−Seidel Algorithm[bus_res,s_res,k] = GS(bus,line)

Try it out and then it results in

Power Flow Solution by Gauss−Seidel AlgorithmMaximum Reactive Power Mismatch = 5.13925e−007

No. of Iterations = 21

Bus Real Imaginary −−−−−Load−−−−− −−−Generation−−− InjectedNo. E F MW Mvar MW Mvar Mvar

1 1.050 0.000 0.000 0.000 2.184 1.409 0.0002 0.971 −0.046 −4.000 −2.500 0.000 0.000 0.0003 1.040 −0.009 0.000 0.000 2.000 1.462 0.000

Total −4.000 −2.500 4.184 2.870 0.000

Transmission Line Flow and Loss

Page 44: pfatb_v1.0a

36 Introduction to PFATB

Bus Bus Power Flow Power Flow −−−Power Loss−−−nl. nr. nl to nr nr to nl MW Mvar

1 2 1.794+j 1.187 −1.710+j −1.019 0.084 0.1681 3 0.391+j 0.221 −0.389+j −0.216 0.002 0.0052 3 −2.290+j −1.481 2.389+j 1.677 0.098 0.197

Total −2.290+j −1.481 2.389+j 1.677 0.184 0.370

Display output at each iteration

Display each iteration at bus 2

Iter Real Imaginary Delta Delta Generation DeltaNo. E F E F Mvar Q

1 1.04000 0.00125 1.04000 0.00125 0.00000 0.000002 1.03999 −0.00376 −0.00001 −0.00501 0.00000 0.000003 1.03998 −0.00647 −0.00001 −0.00271 0.00000 0.000004 1.03997 −0.00770 −0.00001 −0.00123 0.00000 0.000005 1.03997 −0.00837 −0.00001 −0.00066 0.00000 0.000006 1.03996 −0.00870 −0.00000 −0.00034 0.00000 0.000007 1.03996 −0.00887 −0.00000 −0.00017 0.00000 0.000008 1.03996 −0.00896 −0.00000 −0.00009 0.00000 0.000009 1.03996 −0.00901 −0.00000 −0.00005 0.00000 0.00000

10 1.03996 −0.00903 −0.00000 −0.00002 0.00000 0.0000011 1.03996 −0.00904 −0.00000 −0.00001 0.00000 0.0000012 1.03996 −0.00905 −0.00000 −0.00001 0.00000 0.0000013 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.0000014 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.0000015 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.0000016 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.0000017 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.0000018 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.0000019 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.0000020 1.03996 −0.00905 −0.00000 −0.00000 0.00000 0.00000

Display each iteration at bus 3

Iter Real Imaginary Delta Delta Generation DeltaNo. E F E F Mvar Q

1 1.04000 0.00125 1.04000 0.00125 1.16000 1.160002 1.03999 −0.00376 −0.00001 −0.00501 1.29435 0.134353 1.03998 −0.00647 −0.00001 −0.00271 1.36683 0.072484 1.03997 −0.00770 −0.00001 −0.00123 1.41578 0.048955 1.03997 −0.00837 −0.00001 −0.00066 1.43793 0.022156 1.03996 −0.00870 −0.00000 −0.00034 1.44955 0.011627 1.03996 −0.00887 −0.00000 −0.00017 1.45552 0.005978 1.03996 −0.00896 −0.00000 −0.00009 1.45856 0.003059 1.03996 −0.00901 −0.00000 −0.00005 1.46013 0.00156

10 1.03996 −0.00903 −0.00000 −0.00002 1.46093 0.0008011 1.03996 −0.00904 −0.00000 −0.00001 1.46134 0.0004112 1.03996 −0.00905 −0.00000 −0.00001 1.46155 0.0002113 1.03996 −0.00905 −0.00000 −0.00000 1.46166 0.0001114 1.03996 −0.00905 −0.00000 −0.00000 1.46171 0.0000615 1.03996 −0.00905 −0.00000 −0.00000 1.46174 0.0000316 1.03996 −0.00905 −0.00000 −0.00000 1.46175 0.00001

Page 45: pfatb_v1.0a

Introduction to PFATB 37

17 1.03996 −0.00905 −0.00000 −0.00000 1.46176 0.0000118 1.03996 −0.00905 −0.00000 −0.00000 1.46177 0.0000019 1.03996 −0.00905 −0.00000 −0.00000 1.46177 0.0000020 1.03996 −0.00905 −0.00000 −0.00000 1.46177 0.00000

Figure 7.2 shows the process of algorithm convergence until iterations are terminated.

0 5 10 15 20 250

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8The Convergence Graph of Gauss−Seidel Algorithm

Iterations

Spe

ed

E IncrementsF Increments

FIGURE 7.2: The convergence speed of Gauss-Seidel algorithm

Page 46: pfatb_v1.0a

38 Introduction to PFATB

7.3 Newton-Raphson Algorithm

The Newton-Raphson algorithm is evaluated either in polar coordinate or in rectangular coordi-nate. They’re discussed in two subsection in detail.

7.3.1 N-R AlgorithmWith Polar Coordinate System

The functionNRpm.m returns to solve power flow inN-R algorithmwith polar coordinatemethod.

Power-flow Programming Steps

Step 1: Input raw data. Input the electrical grid data in the standard data structure andestimate start points of the remaining undefined bus magnitudes and phase angles.

Step 2: Data regeneration. Line data and bus data are specified to change along with busnumbers simultaneously.

Step 3: Evaluate Ybus. Evaluate bus admittance matrix.Step 4: Evaluate power mismatch. Evaluate ∆Pi and ∆Qis respectively from real power mis-

match equation (6.12) and (6.13).Step 5: Evaluate Jacobian elements. Evaluate Jacobian submatrix elements of H,N,K,L equa-

tions (6.18)∼(6.25).Step 6: Evaluate increments. Evaluate increments of bus voltage magnitude ∆U and incre-

ments of bus angle degree ∆θ by power flow matrix (6.39) with Gauss Elimination method.Step 7: Update variables. Update new bus voltagemagnitude and new bus phase angle degree

by using equations as follows. And then returns to Step5 with new values to replace the preciousvalues.

U(k+1)i =U

(k)i +∆U

(k)i (7.7)

θ(k+1)i = θ

(k)i +∆θ

(k)i (7.8)

Step 8: Examine reactive power at each PV bus. If the reactive power of each PV bus exceedsthe generations boundaries of secure limitations within the minimum and maximum, the con-trolled voltage of the PV bus should drop voltage magnitude to balance reactive power in powersystem.

Step 9: Termination conditions. The process is continued until the residuals ∆P (k)i and ∆Q

(k)i

are less than tolerance accuracy as follows.

max|∆P (k)i | < ε1 (7.9)

max|∆Q(k)i | < ε2 (7.10)

Note that ε1 and ε2 are the small positive constants, such as 0.001,0.00001, and the smaller num-bers are pretty more accurate.

Step 10: Evaluate power of the swing bus and each PV bus. Evaluate reactive power of eachPV bus and evaluate active power and reactive power of the swing bus by (6.44)∼(6.46).

Step 11: Reconfigure bus numbers. Return each bus number to the original bus number inthe bus data matrix and the line data matrix.

Step 12: Evaluate line flow and loss. Evaluate real and reactive power flows in transmissionlines and transformers, as well as equipment losses.

Page 47: pfatb_v1.0a

Introduction to PFATB 39

Step 13: Output solution. Show the final voltage magnitude and phase angle at each busunder balanced three-phase steady-state conditions.

Power-flow Program Function

A complete pseudo-code M-file NRpm.m of N-R algorithm with polar coordinate method isshown below.

function [bus_res,S_res,k] = NRpm(bus,line,EPS,kmax,option)% Newton−Raphson Algorithm With Polar Coordinate Method% [BUS_RES,S_RES,K] = NRpm(BUS,LINE,EPS,KMAX,OPTION) returns the final voltage% magnitude, phase angle and line flow and loss.%% [bus_res,S_res,k] = NRpm(bus,line) returns voltage bus_res, line flow and loss S_res,% iteration k at EPS=1.0e−6 and kmax = 100 in default.%% NRpm uses option to change voltage magnitudes of PV bus to balance reactive power% in power system:% 'unchangePVpm' keep voltage magnitudes of PV bus;(default)% 'changePVpm' drop voltage magnitudes of PV bus.%% See also sortbus,busAM,dPQpm,Jacpm,dAM,dPQSWPVpm,resetbus,lineAM,BSpm,powerTSpm

% Author(s):Long,Chao Lei% $Date:2010/06/24 15:22$

if nargin < 2error('Please input 2 variables');

end

if nargin == 2EPS = 1.0e−6; % Tolerance Accuracykmax = 100; % Maximum iterationsoption = 'unchangePVpm'; % Option default

elseif nargin == 3kmax = 100; % Maximum iterationsoption = 'unchangePVpm'; % Option default

elseif nargin == 4 || isempty(option)option = 'unchangePVpm'; % Option default

end

format long

[bus,line,nPQ,nPV,nodenum] = sortbus(bus,line); % Step 2: Data Regeneration

n = nPV+nPQ+1;

Y = busAM(bus,line); % Step 3: Evaluate Ybus

% Sparse Symmetric Matrix Figureclf;figure(1)spy(Y);title('Ybus Sparse Symmetric Matrix')nz = nnz(Y);pct = 100 / numel(Y);xlabel(sprintf('nonzeros=%d (%.3f%%)',nz,nz*pct));grid on

Page 48: pfatb_v1.0a

40 Introduction to PFATB

k = 1;

while (k ≤ kmax)[delta_P,delta_Q] = dPQpm(bus,nPQ,Y); % Step 4: Evaluate Power Mismatches

Jacobi = Jacpm(bus,Y,nPQ); % Step 5: Evaluate Jacobian Elements

[dU,dAng] = dAM(bus,nPQ,Jacobi,delta_P,delta_Q); % Step 6: Evaluate Increments

bus(1:nPQ,3) = bus(1:nPQ,3) + dU; % Step 7: Update Variablesbus(1:n−1,4) = bus(1:n−1,4) + dAng;

% Record the delta Magnitude and delta AngledUrd(k,:) = dU';dAngrd(k,:) = dAng';

switch option

case 'unchangePVpm'

case 'changePVpm'% Step 8: Examine Reactive Power of each PV Busbus_new = changePVpm(bus,Y,nPQ,k);bus = bus_new;end

% Step 9: Termination Conditionsif (max(abs(dU))<EPS) & (max(abs(dAng))<EPS);

breakend

% k equals kmax or notif (k == kmax);

disp('Solution is not accurate.Please increase the maximum iterations in INPUT argument.')break;

end

% Save increments at each iterationbus_k = zeros(n−1,6);bus_k(1:nPQ,1) = bus(1:nPQ,3);bus_k(:,2) = bus(1:n−1,4);bus_k(:,3) = dAng;bus_k(1:nPQ,4) = dU;bus_k(:,5) = delta_P;bus_k(1:nPQ,6) = delta_Q;

[row,column] = size(bus_k);for i = 1:column

cell_bus{k,i} = bus_k(:,i);end

k = k+1; % Increase iterations

end

% Show the graph of algorithm convergencexk = [1:k];dUrd_sq = sqrt(sum(dUrd.^2,2));dAngrd_sq = sqrt(sum(dAngrd.^2,2));

Page 49: pfatb_v1.0a

Introduction to PFATB 41

figure(2)plot(xk,dUrd_sq,'k',xk,dAngrd_sq,'k−−','LineWidth',2)title('The Convergence Speed of Newton−Raphson Algorithm')xlabel('Iterations');ylabel('Speed');legend('Magnitude Changes','Angle Changes')grid on

% Step 10: Evaluate Power of the swing bus and each PV busbus = dPQSWPVpm(bus,Y,nPQ);

% Step 11: Reconfigure Bus Numbers[bus_temp,line_temp] = resetbus(bus,line,nodenum);

% Step 12: Evaluate line flow and lossYtYm = lineAM(line_temp);bus_res = bus_temp;bus_res(:,4) = bus_temp(:,4)*180/pi;S_res = powerTSpm(bus_temp,line_temp,YtYm);

% Step 13: Output Solutionformat short

% Output Bus Solutiondisp(' ')disp(' Power Flow Solution by N−R Algorithm With Polar Coordinate Method')busout(bus_res,delta_P,delta_Q,n,k);

% Output Line Solutiondisp(' ')disp(' Transmission Line Flow and Loss')lineflow(s_res,n);

% Display output at each iterationdisp(' ')disp(' Display output at each iteration')busiter(cell_bus,nodenum,n,k)

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function busout(bus_res,delta_P,delta_Q,n,k)

fprintf(' Maximum Active Power Mismatch = %g \n', max(abs(delta_P)))fprintf(' Maximum Reactive Power Mismatch = %g \n', max(abs(delta_Q)))fprintf(' No. of Iterations = %g \n\n', k)head =[' Bus Voltage Angle −−−Load−−− −−−Generation−−− Injected'

' No. Mag. Degree MW Mvar MW Mvar Mvar '' '];

disp(head)for i = 1:n

fprintf(' %5g', bus_res(i,1)), fprintf(' %7.3f', bus_res(i,3)),fprintf(' %8.3f', bus_res(i,4)), fprintf(' %9.3f', bus_res(i,5)),fprintf(' %9.3f', bus_res(i,6)), fprintf(' %9.3f', bus_res(i,7)),fprintf(' %9.3f ', bus_res(i,8)), fprintf(' %8.3f\n',bus_res(i,11))

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f', sum(bus_res(:,5))),fprintf(' %9.3f', sum(bus_res(:,6))),fprintf(' %9.3f', sum(bus_res(:,7))),fprintf(' %9.3f', sum(bus_res(:,8))),fprintf(' %9.3f\n\n',sum(bus_res(:,11)))

Page 50: pfatb_v1.0a

42 Introduction to PFATB

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function lineflow(s_res,n)

head =[' '' Bus Bus Power Flow Power Flow −−−Power Loss−−−'' nl. nr. nl to nr nr to nl MW Mvar '' '];

disp(head)

for i = 1:nfprintf(' %5g', s_res(i,1)), fprintf(' %5.0f', s_res(i,2)),fprintf(' %9.3f+j%7.3f', real(s_res(i,3)),imag(s_res(i,3))),fprintf(' %9.3f+j%7.3f', real(s_res(i,4)),imag(s_res(i,4))),fprintf(' %9.3f', real(s_res(i,5))),fprintf(' %9.3f\n', imag(s_res(i,5))),

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,3))),sum(imag(s_res(i,3)))),fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,4))),sum(imag(s_res(i,4)))),fprintf(' %9.3f', sum(real(s_res(:,5)))),fprintf(' %9.3f\n\n', sum(imag(s_res(:,5))))

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function busiter(cell_bus,nodenum,n,k)

for i = 1:n−1disp(' ')fprintf(' Display each iteration at bus %g \n\n', nodenum(i,2))

head =[' Iter Voltage Angle Delta Delta Delta Delta '' No. Mag. Degree Angle Mag. P Q '' '];

disp(head)for j = 1:m−1

fprintf(' %6.4g', m),fprintf(' %10.5f', cell_bus{m,1}(i,:)),fprintf(' %10.5f', cell_bus{m,2}(i,:)),fprintf(' %9.5f', cell_bus{m,3}(i,:)),fprintf(' %9.5f', cell_bus{m,4}(i,:)),fprintf(' %9.5f', cell_bus{m,5}(i,:)),fprintf(' %9.5f\n', cell_bus{m,6}(i,:))

endend

Example 7.2

Obtain the power flow solution by Newton-Raphson algorithm. Let’s use NRpm.m instead ofGS.m in ex7.2.m to solve this power flow problem.

Estimate start points of the remaining bus magnitude and phase angle as follows.

TABLE 7.2: The initial estimations of bus magnitude and phase anglebus number 1 2 3U (0)∠δ(0) 1.05∠0◦ 1∠0◦ 1.04∠0◦

Let us evaluate this example by calling NRpm.m to output solutions. Try the following:

Page 51: pfatb_v1.0a

Introduction to PFATB 43

% ex7.2.mclc;clear all

%% Bus data% Bus Bus Voltage Angle −−−Load−−− −−−−−−Generator−−−− Injected% No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvarbus = [1 3 1.05 0 0 0 0 0 −3.5 3.5 0

2 1 1 0 −4 −2.5 0 0 0 0 03 2 1.04 0 0 0 2 0 −3.5 3.5 0];

%% Line data% Bus Bus R X 1/2 B Tr.tap Setting% nl nr p.u. p.u. p.u. p.u.line = [1 2 0.02 0.04 0 1

1 3 0.01 0.03 0 12 3 0.0125 0.025 0 1];

%% Newton−raphson With Polar Coorinate Method[bus_res,s_res,k] = NRpm(bus,line)

Try it out and then it results in

Power Flow Solution by N−R Algorithm With Polar Coordinate MethodMaximum Active Power Mismatch = 1.16762e−009Maximum Reactive Power Mismatch = 8.82984e−010

No. of Iterations = 4

Bus Voltage Angle −−−−−−Load−−−−−− −−−Generation−−− InjectedNo. Mag. Degree MW Mvar MW Mvar Mvar

1 1.050 0.000 0.000 0.000 2.184 1.409 0.0002 0.972 −2.696 −4.000 −2.500 0.000 0.000 0.0003 1.040 −0.499 0.000 0.000 2.000 1.462 0.000

Total −4.000 −2.500 4.184 2.870 0.000

Transmission Line Flow and Loss

Bus Bus Power Flow Power Flow −−−Power Loss−−−nl. nr. nl to nr nr to nl MW Mvar

1 2 1.794+j 1.187 −1.710+j −1.019 0.084 0.1681 3 0.391+j 0.221 −0.389+j −0.216 0.002 0.0052 3 −2.290+j −1.481 2.389+j 1.677 0.098 0.197

Total −2.290+j −1.481 2.389+j 1.677 0.184 0.370

Display output at each iteration

Display each iteration at bus 2

Iter Voltage Angle Delta Delta Delta DeltaNo. Mag. Degree Angle Mag. P Q

1 0.97345 −0.04526 0.04526 0.02655 −2.86000 −0.220002 0.97168 −0.04706 0.00180 0.00177 −0.09922 −0.050913 0.97168 −0.04706 0.00000 0.00000 −0.00022 −0.00014

Page 52: pfatb_v1.0a

44 Introduction to PFATB

Display each iteration at bus 3

Iter Voltage Angle Delta Delta Delta DeltaNo. Mag. Degree Angle Mag. P Q

1 0.00000 −0.00772 0.00772 0.00000 1.43840 0.000002 0.00000 −0.00870 0.00099 0.00000 0.02171 0.000003 0.00000 −0.00871 0.00000 0.00000 0.00004 0.00000

Figure 7.3 shows the process of algorithm convergence until iterations are terminated.

1 1.5 2 2.5 3 3.5 40

0.005

0.01

0.015

0.02

0.025

0.03

0.035

0.04

0.045

0.05The Convergence Graph of Newton−Raphson Algorithm

Iterations

Spe

ed

Magnitude IncrementsAngle Increments

FIGURE 7.3: The convergence speed of Newton-Raphson algorithm

Page 53: pfatb_v1.0a

Introduction to PFATB 45

7.3.2 N-R AlgorithmWith Rectangular Coordinate System

The function NRcm.m returns to solve power flow in N-R algorithm with rectangular(cartesian)coordinate method.

Power-flow Programming StepsStep 1: Input raw data. Input the electrical grid data in the standard data structure and

estimate start points of the remaining undefined real part e and imaginary parts f of bus voltage.Step 2: Data regeneration. Line data and bus data are specified to change along with bus

numbers simultaneously.Step 3: Evaluate Ybus. Evaluate bus admittance matrix.Step 4: Evaluate power mismatch. Evaluate ∆Pi and ∆Qis respectively from real power mis-

match equations (6.14)∼(6.17).Step 5: Evaluate Jacobian elements. Evaluate Jacobian submatrix elements of H,N,K,L,R,S

equations (6.26)-(6.36).Step 6: Evaluate increments. Evaluate increments of bus voltage real part e and increments

of bus voltage imaginary part f by power flow matrix (6.40) with Gauss Elimination method.Step 7: Update variables. Update new bus voltage real part e and new bus voltage imaginary

part f by using equations as follows. And then returns to Step5 with new values to replace theprecious values.

e(k+1) = e(k) +∆e(k) (7.11)

f (k+1) = f (k) +∆f (k) (7.12)

Step 8: Examine reactive power of each PV Bus. If the reactive power of each PV bus exceedsthe generations boundaries of secure limitations within the minimum and maximum, the con-trolled voltage of the PV bus should drop voltage magnitude to balance reactive power in powersystem.

Step 9: Termination conditions. The process is continued until the residuals ∆P (k)i and ∆Q

(k)i

are less than tolerance accuracy as follows.

max|∆P (k)i | < ε1 (7.13)

max|∆Q(k)i | < ε2 (7.14)

Note that ε1 and ε2 are the small positive constant, such as 0.001,0.00001, and the smaller num-bers are pretty more accurate.

Step 10: Evaluate power of the swing bus and each PV bus. Evaluate reactive power of eachPV bus and evaluate active power and reactive power of the swing bus by (6.47)∼(6.49).

Step 11: Reconfigure bus numbers. Return each bus number to the original bus number inthe bus data matrix and the line data matrix.

Step 12: Evaluate line flow and loss. Evaluate real and reactive power flows in transmissionlines and transformers, as well as equipment losses.

Step 13: Output solution. Show the final bus voltage real part e and imaginary part f underbalanced three-phase steady-state conditions.

Power-flow Program FunctionA complete pseudo-codeM-file NRcm.m of N-R algorithmwith rectangular coordinate is shown

below.

Page 54: pfatb_v1.0a

46 Introduction to PFATB

function [bus_res,S_res,k] = NRcm(bus,line,EPS,kmax,option)% Newton−Raphson Algorithm With Rectangular Coordinate Method% [BUS_RES,S_RES,K] = NRcm(BUS,LINE,EPS,KMAX,OPTION) returns the final bus voltage% real part e and imaginary part f and line flow and loss.%% [bus_res,S_res,k] = NRcm(bus,line) returns voltage bus_res, line flow and loss S_res,% iteration k at EPS=1.0e−6 and kmax = 100 in default.%% NRcm uses option to change voltage magnitudes of PV bus to balance reactive power% in power system:% 'unchangePVcm' keep voltage magnitudes of PV bus;(default)% 'changePVcm' drop voltage magnitudes of PV bus.%% See also sortbus,busAM,dPQcm,Jaccm,dAM,changePVcm,dPQSWPVcm,resetbus,lineAM,powerTScm

% Author(s):Chao Lei% $Date:2011/01/31 00:04$

if nargin < 2error('Please input 2 variables');

end

if nargin == 2EPS = 1.0e−6; % Tolerance Accuracykmax = 100; % Maximum iterationsoption = 'unchangePVcm'; % Option default

elseif nargin == 3kmax = 100; % Maximum iterationsoption = 'unchangePVcm'; % Option default

elseif nargin == 4 || isempty(option)option = 'unchangePVcm'; % Option default

end

format long

[bus,line,nPQ,nPV,nodenum] = sortbus(bus,line); % Step 2: Data Regeneration

n = nPV+nPQ+1;

Y = busAM(bus,line); % Step 3: Evaluate Ybus

% Sparse Symmetric Matrix Figureclf;figure(1)spy(Y);title('Ybus Sparse Symmetric Matrix')nz = nnz(Y);pct = 100 / numel(Y);xlabel(sprintf('nonzeros=%d (%.3f%%)',nz,nz*pct));grid on

k=1;

% The Constant voltage magnitude of each PV busbus0 = zeros(nPV,1);bus0 = bus(nPQ+1:n−1,3).^2 + bus(nPQ+1:n−1,4).^2;

while (k ≤ kmax)[delta_P,delta_Q,delta_U] = dPQcm(bus,bus0,nPQ,Y); % Step 4: Evaluate Power Mismatches

Page 55: pfatb_v1.0a

Introduction to PFATB 47

Jacobi = Jaccm(bus,Y,nPQ); % Step 5: Evaluate Jacobian Elements

[df,de] = dPQU(bus,Jacobi,delta_P,delta_Q,delta_U);% Step 6: Evaluate Increments

bus(1:n−1,3) = bus(1:n−1,3) + de; % Step 7: Update Variablesbus(1:n−1,4) = bus(1:n−1,4) + df;

% Record the delta e and delta fdfrd(k,:) = df';derd(k,:) = de';

switch option

case 'unchangePVcm'

case 'changePVcm'% Step 8: Examine Reactive Power of each PV Busbus0_new = changePVcm(bus,bus0,Y,nPQ,k);bus0 = bus0_new;end

% Step 9: Termination Conditionsif (max(abs(df))<EPS) & (max(abs(de))<EPS);

breakend

% k equals kmax or notif (k == kmax);

disp('Solution is not accurate.Please increase the maximum iterations in INPUT argument.')break;

end

% Save increments at each iterationbus_k = zeros(n−1,6);bus_k(:,1) = bus(1:n−1,3);bus_k(:,2) = bus(1:n−1,4);bus_k(:,3) = de;bus_k(:,4) = df;bus_k(:,5) = delta_P;bus_k(1:nPQ,6) = delta_Q;

[row,column] = size(bus_k);for i = 1:column

cell_bus{k,i} = bus_k(:,i);end

k = k+1; % Increase iterations

end

% Show the graph of algorithm convergencexk = [1:k];dfrd_sq = sqrt(sum(dfrd.^2,2));derd_sq = sqrt(sum(derd.^2,2));

figure(2)plot(xk,dfrd_sq,'k',xk,derd_sq,'k−−','LineWidth',2)title('The Convergence Speed of Newton−Raphson Algorithm')xlabel('Iterations');ylabel('Speed');

Page 56: pfatb_v1.0a

48 Introduction to PFATB

legend('E Changes','F Changes')grid on

% Step 10: Evaluate Power of the swing bus and each PV busbus = dPQSWPVcm(bus,Y,nPQ);

% Step 11: Reconfigure Bus Numbers[bus_temp,line_temp] = resetbus(bus,line,nodenum);

% Step 12: Evaluate line flow and lossYtYm = lineAM(line_temp);S_res = powerTScm(bus_temp,line_temp,YtYm);bus_res = bus_temp;

% Step 13: Output Solutionformat short

% Output Bus Solutiondisp(' ')disp(' Power Flow Solution by N−R Algorithm With Rectangular Coordinate Method')busout(bus_res,delta_P,delta_Q,n,k);

% Output Line Solutiondisp(' ')disp(' Transmission Line Flow and Loss')lineflow(s_res,n);

% Display output at each iterationdisp(' ')disp(' Display output at each iteration')busiter(cell_bus,nodenum,n,k)

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function busout(bus_res,delta_P,delta_Q,n,k)

fprintf(' Maximum Active Power Mismatch = %g \n', max(abs(delta_P)))fprintf(' Maximum Reactive Power Mismatch = %g \n', max(abs(delta_Q)))fprintf(' No. of Iterations = %g \n\n', k)head =[' Bus Real Imaginary −−−Load−−− −−−Generation−−− Injected'

' No. E F MW Mvar MW Mvar Mvar '' '];

disp(head)for i = 1:n

fprintf(' %5g', bus_res(i,1)), fprintf(' %7.3f', bus_res(i,3)),fprintf(' %8.3f', bus_res(i,4)), fprintf(' %9.3f', bus_res(i,5)),fprintf(' %9.3f', bus_res(i,6)), fprintf(' %9.3f', bus_res(i,7)),fprintf(' %9.3f ', bus_res(i,8)), fprintf(' %8.3f\n',bus_res(i,11))

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f', sum(bus_res(:,5))),fprintf(' %9.3f', sum(bus_res(:,6))),fprintf(' %9.3f', sum(bus_res(:,7))),fprintf(' %9.3f', sum(bus_res(:,8))),fprintf(' %9.3f\n\n',sum(bus_res(:,11)))

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function lineflow(s_res,n)

head =[' '' Bus Bus Power Flow Power Flow −−−Power Loss−−−'

Page 57: pfatb_v1.0a

Introduction to PFATB 49

' nl. nr. nl to nr nr to nl MW Mvar '' '];

disp(head)

for i = 1:nfprintf(' %5g', s_res(i,1)), fprintf(' %5.0f', s_res(i,2)),fprintf(' %9.3f+j%7.3f', real(s_res(i,3)),imag(s_res(i,3))),fprintf(' %9.3f+j%7.3f', real(s_res(i,4)),imag(s_res(i,4))),fprintf(' %9.3f', real(s_res(i,5))),fprintf(' %9.3f\n', imag(s_res(i,5))),

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,3))),sum(imag(s_res(i,3)))),fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,4))),sum(imag(s_res(i,4)))),fprintf(' %9.3f', sum(real(s_res(:,5)))),fprintf(' %9.3f\n\n', sum(imag(s_res(:,5))))

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function busiter(cell_bus,nodenum,n,k)

for i = 1:n−1disp(' ')fprintf(' Display each iteration at bus %g \n\n', nodenum(i,2))

head =[' Iter Real Imaginary Delta Delta Delta Delta '' No. E F E F P Q '' '];

disp(head)for m = 1:k−1

fprintf(' %6.4g', m),fprintf(' %10.5f', cell_bus{m,1}(i,:)),fprintf(' %10.5f', cell_bus{m,2}(i,:)),fprintf(' %9.5f', cell_bus{m,3}(i,:)),fprintf(' %9.5f', cell_bus{m,4}(i,:)),fprintf(' %9.5f', cell_bus{m,5}(i,:)),

fprintf(' %9.5f\n', cell_bus{m,6}(i,:))endend

Example 7.3

Obtain the power flow solution by N-R algorithm with rectangular coordinate method. Let’suse NRcm.m instead of NRpm.m in ex3.m to solve this power flow problem.

Estimate start points of the remaining bus magnitude and phase angle as follows.

TABLE 7.3: The initial estimations of real part e and imaginary part fbus number 1 2 3e(0) + j f (0) 1+ j 0 1+ j 0 1+ j 0

Let us evaluate this example by calling NRcm.m to output solutions. Try the following:

% ex7.3.mclc;clear all

%% Bus data% Bus Bus Real Imaginary −−−Load−−− −−−−−−Generator−−−− Injected

Page 58: pfatb_v1.0a

50 Introduction to PFATB

% No Type E F MW Mvar MW Mvar Qmin Qmax Mvarbus = [1 3 1.05 0 0 0 0 0 −3.5 3.5 0

2 1 1 0 −4 −2.5 0 0 0 0 03 2 1.04 0 0 0 2 0 −3.5 3.5 0];

%% Line data% Bus Bus R X 1/2 B Tr.tap Setting% nl nr p.u. p.u. p.u. p.u.line = [1 2 0.02 0.04 0 1

1 3 0.01 0.03 0 12 3 0.0125 0.025 0 1];

%% Newton−Raphson With Rectangular Coordinate Method[bus_res,s_res,k] = NRcm(bus,line)

Try it out and then it results in

Power Flow Solution by N−R Algorithm With Rectangular Coordinate MethodMaximum Active Power Mismatch = 1.6267e−009Maximum Reactive Power Mismatch = 4.70817e−009

No. of Iterations = 4

Bus Real Imaginary −−−−−−Load−−−−−− −−−Generation−−− InjectedNo. E F MW Mvar MW Mvar Mvar

1 1.050 0.000 0.000 0.000 2.184 1.409 0.0002 0.971 −0.046 −4.000 −2.500 0.000 0.000 0.0003 1.040 −0.009 0.000 0.000 2.000 1.462 0.000

Total −4.000 −2.500 4.184 2.870 0.000

Transmission Line Flow and Loss

Bus Bus Power Flow Power Flow −−−Power Loss−−−nl. nr. nl to nr nr to nl MW Mvar

1 2 1.794+j 1.187 −1.710+j −1.019 0.084 0.1681 3 0.391+j 0.221 −0.389+j −0.216 0.002 0.0052 3 −2.290+j −1.481 2.389+j 1.677 0.098 0.197

Total −2.290+j −1.481 2.389+j 1.677 0.184 0.370

Display output at each iteration

Display each iteration at bus 2

Iter Real Imaginary Delta Delta Delta DeltaNo. E F E F P Q

1 0.97345 −0.04526 0.02655 0.04526 −2.86000 −0.220002 0.97061 −0.04571 0.00284 0.00045 −0.05896 −0.134973 0.97060 −0.04571 0.00001 0.00000 −0.00011 −0.00046

Display each iteration at bus 3

Iter Real Imaginary Delta Delta Delta DeltaNo. E F E F P Q

Page 59: pfatb_v1.0a

Introduction to PFATB 51

1 1.04000 −0.00803 −0.00000 0.00803 1.43840 0.000002 1.03996 −0.00905 0.00004 0.00102 −0.00268 0.000003 1.03996 −0.00905 0.00000 0.00000 −0.00011 0.00000

Figure 7.4 shows the process of algorithm convergence until iterations are terminated.

1 1.5 2 2.5 3 3.5 40

0.005

0.01

0.015

0.02

0.025

0.03

0.035

0.04

0.045

0.05The Convergence Graph of Newton−Raphson Algorithm

Iterations

Spe

ed

E IncrementsF Increments

FIGURE 7.4: The convergence speed of Newton-Raphson algorithm

Page 60: pfatb_v1.0a

52 Introduction to PFATB

7.4 P-Q Decoupling Algorithm

The function PQpm.m returns to solve power flow in P-Q fast decoupling algorithm with polarcoordinate method.

Power-flow Programming StepsStep 1: Input raw data. Input the electrical grid data in the standard data structure and

estimate start points of the remaining undefined bus magnitude and phase angle.Step 2: Data regeneration. Line data and bus data are specified to change along with bus

numbers simultaneously.Step 3: Evaluate Ybus. Evaluate bus admittance matrix.Step 4: Evaluate power mismatch. Evaluate ∆Pi and ∆Qis respectively from real power mis-

match equation (6.12) and (6.13).Step 5: Evaluate Jacobian elements. Evaluate Jacobian submatrix elements of H,L equations

(6.18)∼(6.19) and (6.21)∼(6.25).Step 6: Evaluate increments. Evaluate increments of bus voltage magnitude ∆U and in-

crements of bus angle degree ∆θ by power flow matrix (6.37)∼(6.38) with Gauss Eliminationmethod.

Step 7: Update variables. Update new bus voltagemagnitude and new bus phase angle degreeby using equations as follows. And then returns to Step5 with new values to replace the preciousvalues.

U (k+1) =U (k) +∆U (k) (7.15)

θ(k+1) = θ(k) +∆θ(k) (7.16)

Step 8: Examine reactive power of each PV Bus. If the reactive power of each PV bus exceedsthe generations boundaries of secure limitations within the minimum and maximum, the con-trolled voltage of the PV bus should drop voltage magnitude to balance reactive power in powersystem.

Step 9: Termination conditions. The process is continued until the residuals ∆P (k)i and ∆Q

(k)i

are less than tolerance accuracy as follows.

max|∆P (k)i | < ε1 (7.17)

max|∆Q(k)i | < ε2 (7.18)

Note that ε1 and ε2 are the small positive constant, such as 0.001,0.00001, and the smaller num-bers are pretty more accurate.

Step 10: Evaluate power of the swing bus and each PV bus. Evaluate reactive power of eachPV bus and evaluate active power and reactive power of the swing bus by (6.44)∼(6.46).

Step 11: Reconfigure bus numbers. Return each bus number to the original bus number inthe bus data matrix and the line data matrix.

Step 12: Evaluate line flow and loss. Evaluate real and reactive power flows in transmissionlines and transformers, as well as equipment losses.

Step 13: Output solution. Show the final voltage magnitude and phase angle at each busunder balanced three-phase steady-state conditions.

Power-flow Program FunctionA complete pseudo-codeM-file PQpm.m of P-Q fast decoupling algorithmwith polar coordinate

is shown below.

Page 61: pfatb_v1.0a

Introduction to PFATB 53

function [bus_res,s_res,k] = PQpm(bus,line,EPS,kmax,option)% P−Q Fast Decoupling Algorithm With Polar Coordinate Method% [BUS_RES,S_RES,K] = PQpm(BUS,LINE,EPS,KMAX,OPTION) returns the final voltage% magnitude,phase angle and line flow and loss.%% [bus_res,S_res,k] = PQpm(bus,line) returns voltage bus_res, line flow and loss S_res,% iteration k at EPS=1.0e−6 and kmax = 100 in default.%% PQpm uses option to change voltage magnitudes of PV bus to balance reactive power% in power system:% 'unchangePVpm' keep voltage magnitudes of PV bus;(default)% 'changePVpm' drop voltage magnitudes of PV bus.%% See also sortbus,busAM,dPQpm,Jacpm,dAM,dPQSWPVpm,resetbus,lineAM,BSpm,powerTSpm

% Author(s):Long,Chao Lei% $Date:2010/06/24 15:22$

if nargin < 2error('Please input 2 variables');

end

if nargin == 2EPS = 1.0e−6; % Tolerance Accuracykmax = 100; % Maximum iterationsoption = 'unchangePVpm'; % Option default

elseif nargin == 3kmax = 100; % Maximum iterationsoption = 'unchangePVpm'; % Option default

elseif nargin == 4 || isempty(option)option = 'unchangePVpm'; % Option default

end

format long

[bus,line,nPQ,nPV,nodenum] = sortbus(bus,line); % Step 2: Data Regeneration

n = nPV+nPQ+1;

[B1,B2,Y] = Bpq(bus,line,nPQ); % Step 3: Evaluate Ybus

% Sparse Symmetric Matrix Figureclf;figure(1)spy(Y);title('Ybus Sparse Symmetric Matrix')nz = nnz(Y);pct = 100 / numel(Y);xlabel(sprintf('nonzeros=%d (%.3f%%)',nz,nz*pct));grid on

k = 1;

while (k ≤ kmax)[delta_P,delta_Q] = dPQpm(bus,nPQ,Y); % Step 4: Evaluate Power Mismatches

[H,L] = HLpq(bus,nPQ,B1,B2); % Step 5: Evaluate Jacobian Elements H,L

dAng = dApq(bus,H,delta_P); % Step 6: Evaluate IncrementsdU = dMpq(bus,nPQ,L,delta_Q);

Page 62: pfatb_v1.0a

54 Introduction to PFATB

bus(1:nPQ,3) = bus(1:nPQ,3) + dU; % Step 7: Update Variablesbus(1:n−1,4) = bus(1:n−1,4) + dAng;

% Record the delta U and delta AngledUrd(k,:) = dU';dAngrd(k,:) = dAng';

switch option

case 'unchangePVpm'

case 'changePVpm'% Step 8: Examine Reactive Power of each PV Busbus_new = changePVpm(bus,Y,nPQ,k);bus = bus_new;end

% Step 9: Termination Conditionsif (max(abs(dU))<EPS) & (max(abs(dAng))<EPS)

breakend

% k equals kmax or notif (k == kmax);

disp('Solution is not accurate.Please increase the maximum iterations in INPUT argument.')break;

end

% Save increments at each iterationbus_k = zeros(n−1,6);bus_k(1:nPQ,1) = bus(1:nPQ,3);bus_k(:,2) = bus(1:n−1,4);bus_k(:,3) = dAng;bus_k(1:nPQ,4) = dU;bus_k(:,5) = delta_P;bus_k(1:nPQ,6) = delta_Q;

[row,column] = size(bus_k);for i = 1:column

cell_bus{k,i} = bus_k(:,i);end

k = k+1; % Increase iterations

end

% Show the graph of algorithm convergencexk = [1:k];dUrd_sq = sqrt(sum(dUrd.^2,2));dAngrd_sq = sqrt(sum(dAngrd.^2,2));

figure(2)plot(xk,dUrd_sq,'k',xk,dAngrd_sq,'k−−','LineWidth',2)title('The Convergence Speed of P−Q Decoupling Algorithm')xlabel('Iterations');ylabel('Speed');legend('Magnitude Increments','Angle Increments')grid on

Page 63: pfatb_v1.0a

Introduction to PFATB 55

% Step 10: Evaluate power of the swing bus and each PV busbus = dPQSWPVpm(bus,Y,nPQ);

% Step 11: Reconfigure Bus Numbers[bus_temp,line_temp] = resetbus(bus,line,nodenum);

% Step 12: Evaluate line flow and lossYtYm = lineAM(line_temp);bus_res = bus_temp;bus_res(:,4) = bus_temp(:,4)*180/pi;s_res = powerTSpm(bus_temp,line_temp,YtYm);

% Step 13: Output Solutionformat short

% Output Bus Solutiondisp('')disp(' Power Flow Solution by P−Q Decoupling Algorithm With Polar Coordinate Method')busout(bus_res,delta_P,delta_Q,n,k);

% Output Line Solutiondisp(' ')disp(' Transmission Line Flow and Loss')lineflow(s_res,n);

% Display output at each iterationdisp(' ')disp(' Display output at each iteration')busiter(cell_bus,nodenum,n,k)

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function busout(bus_res,delta_P,delta_Q,n,k)

fprintf(' Maximum Active Power Mismatch = %g \n', max(abs(delta_P)))fprintf(' Maximum Reactive Power Mismatch = %g \n', max(abs(delta_Q)))fprintf(' No. of Iterations = %g \n\n', k)head =[' Bus Voltage Angle −−−Load−−− −−−Generation−−− Injected'

' No. Mag. Degree MW Mvar MW Mvar Mvar '' '];

disp(head)for i = 1:n

fprintf(' %5g', bus_res(i,1)), fprintf(' %7.3f', bus_res(i,3)),fprintf(' %8.3f', bus_res(i,4)), fprintf(' %9.3f', bus_res(i,5)),fprintf(' %9.3f', bus_res(i,6)), fprintf(' %9.3f', bus_res(i,7)),fprintf(' %9.3f ', bus_res(i,8)), fprintf(' %8.3f\n',bus_res(i,11))

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f', sum(bus_res(:,5))),fprintf(' %9.3f', sum(bus_res(:,6))),fprintf(' %9.3f', sum(bus_res(:,7))),fprintf(' %9.3f', sum(bus_res(:,8))),fprintf(' %9.3f\n\n',sum(bus_res(:,11)))

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function lineflow(s_res,n)

head =[' '' Bus Bus Power Flow Power Flow −−−Power Loss−−−'' nl. nr. nl to nr nr to nl MW Mvar '

Page 64: pfatb_v1.0a

56 Introduction to PFATB

' '];disp(head)

for i = 1:nfprintf(' %5g', s_res(i,1)), fprintf(' %5.0f', s_res(i,2)),fprintf(' %9.3f+j%7.3f', real(s_res(i,3)),imag(s_res(i,3))),fprintf(' %9.3f+j%7.3f', real(s_res(i,4)),imag(s_res(i,4))),fprintf(' %9.3f', real(s_res(i,5))),fprintf(' %9.3f\n', imag(s_res(i,5))),

endfprintf(' \n'), fprintf(' Total ')fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,3))),sum(imag(s_res(i,3)))),fprintf(' %9.3f+j%7.3f', sum(real(s_res(i,4))),sum(imag(s_res(i,4)))),fprintf(' %9.3f', sum(real(s_res(:,5)))),fprintf(' %9.3f\n\n', sum(imag(s_res(:,5))))

% −−−−−−−−−−−−−−−−−−−−−−Subfunction−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−function busiter(cell_bus,nodenum,n,k)

for i = 1:n−1disp(' ')fprintf(' Display each iteration at bus %g \n\n', nodenum(i,2))

head =[' Iter Voltage Angle Delta Delta Delta Delta '' No. Mag. Degree Angle Mag. P Q '' '];

disp(head)for j = 1:k−1

fprintf(' %6.4g', j),fprintf(' %10.5f', cell_bus{j,1}(i,:)),fprintf(' %10.5f', cell_bus{j,2}(i,:)),fprintf(' %9.5f', cell_bus{j,3}(i,:)),fprintf(' %9.5f', cell_bus{j,4}(i,:)),fprintf(' %9.5f', cell_bus{j,5}(i,:)),fprintf(' %9.5f\n', cell_bus{j,6}(i,:))

endend

Example 7.4

Obtain the power flow solution by P-Q decoupling algorithm with polar coordinate method.Let’s use PQpm.m instead of NRpm.m in ex3.m to solve this power flow problem.

Estimate start points of the remaining bus magnitude and phase angle as follows.

TABLE 7.4: The initial estimations of bus magnitude and phase anglebus number 1 2 3U (0)∠δ(0) 1.05∠0◦ 1∠0◦ 1.04∠0◦

Let us evaluate this example through calling PQpm.m to output solutions. Try the following:

% ex7.4.mclc;clear all

%% Bus data% Bus Bus Voltage Angle −−−Load−−− −−−−−−Generator−−−− Injected% No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar

Page 65: pfatb_v1.0a

Introduction to PFATB 57

bus = [1 3 1.05 0 0 0 0 0 −3.5 3.5 02 1 1 0 −4 −2.5 0 0 0 0 03 2 1.04 0 0 0 2 0 −3.5 3.5 0];

%% Line data% Bus Bus R X 1/2 B Tr.tap Setting% nl nr p.u. p.u. p.u. p.u.line = [1 2 0.02 0.04 0 1

1 3 0.01 0.03 0 12 3 0.0125 0.025 0 1];

%% P−Q Decoupling Algorithm[bus_res,s_res,k] = PQpm(bus,line)

Try it out and then it results in

Power Flow Solution by P−Q Decoupling Algorithm With Polar Coordinate MethodMaximum Active Power Mismatch = 2.89131e−005Maximum Reactive Power Mismatch = 4.7976e−007

No. of Iterations = 17

Bus Voltage Angle −−−−−−Load−−−−−− −−−Generation−−− InjectedNo. Mag. Degree MW Mvar MW Mvar Mvar

1 1.050 0.000 0.000 0.000 2.184 1.409 0.0002 0.972 −2.696 −4.000 −2.500 0.000 0.000 0.0003 1.040 −0.499 0.000 0.000 2.000 1.462 0.000

Total −4.000 −2.500 4.184 2.870 0.000

Transmission Line Flow and Loss

Bus Bus Power Flow Power Flow −−−Power Loss−−−nl. nr. nl to nr nr to nl MW Mvar

1 2 1.794+j 1.187 −1.710+j −1.019 0.084 0.1681 3 0.391+j 0.221 −0.389+j −0.216 0.002 0.0052 3 −2.290+j −1.481 2.389+j 1.677 0.098 0.197

Total −2.290+j −1.481 2.389+j 1.677 0.184 0.370

Display output at each iteration

Display each iteration at bus 2

Iter Voltage Angle Delta Delta Delta DeltaNo. Mag. Degree Angle Mag. P Q

1 0.99577 −0.06048 0.06048 0.00423 −2.86000 −0.220002 0.96515 −0.05649 −0.00400 0.03062 0.18694 −1.585303 0.96572 −0.04370 −0.01279 −0.00057 0.64105 0.028664 0.97325 −0.04487 0.00117 −0.00753 −0.04627 0.378155 0.97309 −0.04785 0.00298 0.00016 −0.15580 −0.008136 0.97131 −0.04759 −0.00026 0.00179 0.01053 −0.090347 0.97134 −0.04687 −0.00072 −0.00003 0.03708 0.001628 0.97177 −0.04694 0.00006 −0.00043 −0.00244 0.021589 0.97176 −0.04711 0.00017 0.00001 −0.00887 −0.00034

10 0.97166 −0.04709 −0.00001 0.00010 0.00056 −0.00515

Page 66: pfatb_v1.0a

58 Introduction to PFATB

11 0.97166 −0.04705 −0.00004 −0.00000 0.00212 0.0000712 0.97168 −0.04705 0.00000 −0.00002 −0.00013 0.0012313 0.97168 −0.04706 0.00001 0.00000 −0.00051 −0.0000114 0.97168 −0.04706 −0.00000 0.00001 0.00003 −0.0002915 0.97168 −0.04706 −0.00000 −0.00000 0.00012 0.0000016 0.97168 −0.04706 0.00000 −0.00000 −0.00001 0.00007

Display each iteration at bus 3

Iter Voltage Angle Delta Delta Delta DeltaNo. Mag. Degree Angle Mag. P Q

1 0.00000 −0.00857 0.00857 0.00000 1.43840 0.000002 0.00000 −0.00799 −0.00058 0.00000 −0.09378 0.000003 0.00000 −0.00867 0.00068 0.00000 −0.45604 0.000004 0.00000 −0.00899 0.00032 0.00000 0.01594 0.000005 0.00000 −0.00871 −0.00028 0.00000 0.11504 0.000006 0.00000 −0.00865 −0.00007 0.00000 −0.00381 0.000007 0.00000 −0.00870 0.00006 0.00000 −0.02712 0.000008 0.00000 −0.00872 0.00002 0.00000 0.00083 0.000009 0.00000 −0.00871 −0.00001 0.00000 0.00650 0.00000

10 0.00000 −0.00870 −0.00000 0.00000 −0.00019 0.0000011 0.00000 −0.00871 0.00000 0.00000 −0.00155 0.0000012 0.00000 −0.00871 0.00000 0.00000 0.00004 0.0000013 0.00000 −0.00871 −0.00000 0.00000 0.00037 0.0000014 0.00000 −0.00871 −0.00000 0.00000 −0.00001 0.0000015 0.00000 −0.00871 0.00000 0.00000 −0.00009 0.0000016 0.00000 −0.00871 0.00000 0.00000 0.00000 0.00000

Figure 7.5 shows the process of algorithm convergence until iterations are terminated.

0 2 4 6 8 10 12 14 16 180

0.01

0.02

0.03

0.04

0.05

0.06

0.07The Convergence Graph of P−Q Decoupling Algorithm

Iterations

Spe

ed

Magnitude IncrementsAngle Increments

FIGURE 7.5: The convergence speed of P-Q decoupling algorithm

Page 67: pfatb_v1.0a

Introduction to PFATB 59

7.5 Algorithm Discussions

Gauss-Seidel algorithm is modified from Gauss algorithm by substituting new voltage into thepreceding equations. In Example 7.1, it can be seen that Gauss-Seidel algorithm needs manyiterations to achieve the desired accuracy, and there is no guarantee for the convergence. BecauseGauss-Seidel algorithm will not converge in a zigzag fashion to one of roots through iterations ifthe initial estimation is not within a "boxed in" region, described in [2] Chapter 6. Therefore, atest of convergence, especially for the n-dimension case, is difficult, and no general methods areknown.

Newton-Raphson algorithm is widespread considered as the better method to solve powerflows. The process of Newton-Raphson algorithm will converge only in less than ten iterations,P-Q decoupling algorithm comes in secondary in less than 100 iterations, and Gauss-Seidel algo-rithm may be converged for more 100 iterations or diverged.

Page 68: pfatb_v1.0a

60 Introduction to PFATB

8 IEEE 30-BUS TEST SYSTEM

In this section, we discuss how well PFATB works on IEEE 30-bus typical test system. The fol-lowing system IEEE 30-bus diagram is part of the American Electric Power Service Corporationnetwork which is being made available to the electric utility industry as a standard test case forevaluating various analytical methods. And its application is practical to be showed to help us tounderstand PFATB programs better. In Figure 8.1, bus 1 is taken as the swing bus with its voltageadjusted to 1.06∠0◦ p.u. The data for the voltage-controlled buses is

TABLE 8.1: Regulated Bus DataBus Voltage Min.Mvar Max.MvarNo. Magnitude Capacity Capacity2 1.043 -40 505 1.010 -40 408 1.010 -10 4011 1.082 -6 2413 1.071 -6 24

Transformer tap setting are given in Table 8.2 below. The left bus number is assumed to be thetap side of the transformer. The data for the injected Q due to shunt capacitors is in Table 8.3.

TABLE 8.2: Transformers DataTransformer Tap SettingDesignation p.u.

4-12 0.9326-9 0.9786-10 0.96928-27 0.968

TABLE 8.3: Shunt Capacitors DataBus No. Mvar

10 1924 4.3

The load data and generation parameters are given in the toolbox file named TEST_IEEE30−BUS.m.And the general base MVA is at 100MVA.

Page 69: pfatb_v1.0a

Introduction to PFATB 61

FIGURE 8.1: IEEE 30-Bus Test System

The following program is prompted to be run with Gauss-Seidel algorithm, Newton-Raphsonalgorithm and P-Q decoupling algorithm. Let us try the following:

% TEST_IEEE30−BUS.mclc;clear allbasemva = 100;

%% IEEE 30−BUS TEST SYSTEM DATA% IEEE 30−BUS TEST SYSTEM (American Electric Power)% Bus Bus Voltage Angle −−−Load−−−− −−−−Generator−−− Static Mvar% No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax +Qc/−Ql

Page 70: pfatb_v1.0a

62 Introduction to PFATB

bus = [1 3 1.06 0 0.0 0.0 0 0 0 0 02 2 1.043 0 21.70 12.7 40 0 −40 50 03 1 1.0 0 2.4 1.2 0 0 0 0 04 1 1.06 0 7.6 1.6 0 0 0 0 05 2 1.01 0 94.2 19.0 0 0 −40 40 06 1 1.0 0 0.0 0.0 0 0 0 0 07 1 1.0 0 22.8 10.9 0 0 0 0 08 2 1.01 0 30.0 30.0 0 0 −10 40 09 1 1.0 0 0.0 0.0 0 0 0 0 010 1 1.0 0 5.8 2.0 0 0 0 0 1911 2 1.082 0 0.0 0.0 0 0 −6 24 012 1 1.0 0 11.2 7.5 0 0 0 0 013 2 1.071 0 0 0.0 0 0 −6 24 014 1 1 0 6.2 1.6 0 0 0 0 015 1 1 0 8.2 2.5 0 0 0 0 016 1 1 0 3.5 1.8 0 0 0 0 017 1 1 0 9.0 5.8 0 0 0 0 018 1 1 0 3.2 0.9 0 0 0 0 019 1 1 0 9.5 3.4 0 0 0 0 020 1 1 0 2.2 0.7 0 0 0 0 021 1 1 0 17.5 11.2 0 0 0 0 022 1 1 0 0 0.0 0 0 0 0 023 1 1 0 3.2 1.6 0 0 0 0 024 1 1 0 8.7 6.7 0 0 0 0 4.325 1 1 0 0 0.0 0 0 0 0 026 1 1 0 3.5 2.3 0 0 0 0 027 1 1 0 0 0.0 0 0 0 0 028 1 1 0 0 0.0 0 0 0 0 029 1 1 0 2.4 0.9 0 0 0 0 030 1 1 0 10.6 1.9 0 0 0 0 0];

% Bus Data Pre−processingbus(:,5:6) = − bus(:,5:6) ./ basemva;bus(:,7:11) = bus(:,7:11) ./ basemva;

% Line code% Bus Bus R X 1/2 B Tr.Tap Setting% nl nr p.u. p.u. p.u. p.u.line = [1 2 0.0192 0.0575 0.02640 1

1 3 0.0452 0.1852 0.02040 12 4 0.0570 0.1737 0.01840 13 4 0.0132 0.0379 0.00420 12 5 0.0472 0.1983 0.02090 12 6 0.0581 0.1763 0.01870 14 6 0.0119 0.0414 0.00450 15 7 0.0460 0.1160 0.01020 16 7 0.0267 0.0820 0.00850 16 8 0.0120 0.0420 0.00450 16 9 0 0.2080 0 0.9786 10 0 0.5560 0 0.9699 11 0 0.2080 0 19 10 0 0.1100 0 14 12 0 0.2560 0 0.93212 13 0 0.1400 0 112 14 0.1231 0.2559 0 112 15 0.0662 0.1304 0 112 16 0.0945 0.1987 0 114 15 0.2210 0.1997 0 116 17 0.0824 0.1923 0 115 18 0.1073 0.2185 0 1

Page 71: pfatb_v1.0a

Introduction to PFATB 63

18 19 0.0639 0.1292 0 119 20 0.0340 0.0680 0 110 20 0.0936 0.2090 0 110 17 0.0324 0.0845 0 110 21 0.0348 0.0749 0 110 22 0.0727 0.1499 0 121 22 0.0116 0.0236 0 115 23 0.1000 0.2020 0 122 24 0.1150 0.1790 0 123 24 0.1320 0.2700 0 124 25 0.1885 0.3292 0 125 26 0.2544 0.3800 0 125 27 0.1093 0.2087 0 128 27 0 0.3960 0 0.96827 29 0.2198 0.4153 0 127 30 0.3202 0.6027 0 129 30 0.2399 0.4533 0 18 28 0.0636 0.2000 0.0214 16 28 0.0169 0.0599 0.065 1];

%% Gauss−Seidel[bus_res,s_res,k] = GS(bus,line,10e−4,200);

%% Newton−Raphson With Polar Coordinate Method[bus_res,s_res,k] = NRpm(bus,line);

%% Newton−Raphson With Rectangualr Coordinate Method[bus_res,s_res,k] = NRcm(bus,line);

%% P−Q Decoupling With Polar Coordinate Method[bus_res,s_res,k] = PQpm(bus,line);

Let us visualize power flow analysis of IEEE 30-bus Test System in Figure 8.2 ∼ Figure 8.5. Figure8.2 shows the sparsity pattern of the Ybus matrix .

0 5 10 15 20 25 30

0

5

10

15

20

25

30

nonzeros=112 (12.444%)

Y Sparse Symmetric Matrix

FIGURE 8.2: Ybus Sparse Symmetric Matrix

Page 72: pfatb_v1.0a

64 Introduction to PFATB

Figure 8.3 shows 2D-visualization of each busmagnitude and Figure 8.4 shows 3D-visualizationof each bus magnitude.

1 3 5 7 9 11 13 15 17 19 21 23 25 27 290.98

1

1.02

1.04

1.06

1.08

1.12D−visualization of bus voltage magnitude

FIGURE 8.3: 2D-visualization of each bus magni-tude

FIGURE 8.4: 3D-visualization of each bus magni-tude

The solution data solved in N-R algorithms and P-Q decoupling algorithm is attached as Ap-pendix A in detail. Meantime, Figure 8.5∼ Figure 8.8 generated by evaluating the above commandstatements show the graphs of algorithm convergence.

0 20 40 60 80 100 1200

1

2

3

4

5

6The Convergence Graph of Gauss−Seidel Algorithm

Iterations

Spe

ed

E IncrementsF Increments

FIGURE 8.5: The convergence speed of Gauss-Seidel algorithm

1 1.5 2 2.5 3 3.5 40

0.2

0.4

0.6

0.8

1

1.2

1.4The Convergence Graph of Newton−Raphson Algorithm

Iterations

Spe

ed

Magnitude IncrementsAngle Increments

FIGURE 8.6: The convergence speed of Newton-Raphson with polar coordinate method

1 1.5 2 2.5 3 3.5 4 4.5 50

0.2

0.4

0.6

0.8

1

1.2

1.4The Convergence Graph of Newton−Raphson Algorithm

Iterations

Spe

ed

E IncrementsF Increments

FIGURE 8.7: The convergence speed of Newton-Raphson with rectangular coordinate method

0 5 10 15 20 25 30 35 400

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8The Convergence Graph of P−Q Decoupling Algorithm

Iterations

Spe

ed

Magnitude IncrementsAngle Increments

FIGURE 8.8: The convergence speed of P-Q decou-pling algorithm

Page 73: pfatb_v1.0a

Introduction to PFATB 65

9 FURTHER REVERSIONS

Owing to the limitation of time and ability, I acclaim PFATB is now only a courseware packagewith limited utility beyond the classroom clearly. Nevertheless, I will be very glad to receivecorrections and/or constructive criticisms from you through sending me emails. Kind under-standing and cooperation will be much appreciated.

Page 74: pfatb_v1.0a

66 Introduction to PFATB

REFERENCES

[1] Jizhong Zhu, Optimization of Power System Operation, Wiley & IEEE Press,2009.

[2] Hadi Saadat, Power System Analysis(2nd Edition), New York:McGraw-Hill,2002.

[3] J.Duncan Glover,Mulukutla S.Sarma,Thomas J.Overbye, Power System Analysis and De-sign(4th Edition), Canada:Thomson Learning,2008.

[4] Brain Hahn,Daniel T.Valentine, Essential MATLAB For Engineers and Scientists(3rd Edi-tion), Elsevier Butterworth Heinemann,2007.

[5] Richard Johnson, MATLAB Programming Style Guidelines,Online: http://www.datatool.com/downloads/matlab_style_guidelines.pdf

Page 75: pfatb_v1.0a

Introduction to PFATB 67

A APPENDIX IEEE 30-BUS SOLUTIONS

In order to show how well PFATB works, the power flow solution of IEEE 30-Bus Test System hasbeen tabulated as key answers for practice. I’ve listed 3 solutions mentioned in Section 8 in thisappendix.

Solution 1: Power Flow Solution by N-R AlgorithmWith Polar Coordinate Method

Power Flow Solution by N−R Algorithm With Polar Coordinate MethodMaximum Active Power Mismatch = 5.59723e−007Maximum Reactive Power Mismatch = 7.54898e−007

No. of Iterations = 4

Bus Voltage Angle −−−−−−Load−−−−−− −−−Generation−−− InjectedNo. Mag. Degree MW Mvar MW Mvar Mvar

1 1.060 0.000 −0.000 −0.000 2.610 −0.170 0.0002 1.043 −5.497 −0.217 −0.127 0.400 0.488 0.0003 1.022 −8.004 −0.024 −0.012 0.000 0.000 0.0004 1.013 −9.661 −0.076 −0.016 0.000 0.000 0.0005 1.010 −14.381 −0.942 −0.190 0.000 0.360 0.0006 1.012 −11.398 −0.000 −0.000 0.000 0.000 0.0007 1.003 −13.150 −0.228 −0.109 0.000 0.000 0.0008 1.010 −12.115 −0.300 −0.300 0.000 0.308 0.0009 1.051 −14.434 −0.000 −0.000 0.000 0.000 0.000

10 1.044 −16.024 −0.058 −0.020 0.000 0.000 0.19011 1.082 −14.434 −0.000 −0.000 0.000 0.161 0.00012 1.057 −15.302 −0.112 −0.075 0.000 0.000 0.00013 1.071 −15.302 −0.000 −0.000 0.000 0.104 0.00014 1.042 −16.191 −0.062 −0.016 0.000 0.000 0.00015 1.038 −16.278 −0.082 −0.025 0.000 0.000 0.00016 1.045 −15.880 −0.035 −0.018 0.000 0.000 0.00017 1.039 −16.188 −0.090 −0.058 0.000 0.000 0.00018 1.028 −16.884 −0.032 −0.009 0.000 0.000 0.00019 1.025 −17.052 −0.095 −0.034 0.000 0.000 0.00020 1.029 −16.852 −0.022 −0.007 0.000 0.000 0.00021 1.032 −16.468 −0.175 −0.112 0.000 0.000 0.00022 1.033 −16.455 −0.000 −0.000 0.000 0.000 0.00023 1.027 −16.662 −0.032 −0.016 0.000 0.000 0.00024 1.022 −16.830 −0.087 −0.067 0.000 0.000 0.04325 1.019 −16.424 −0.000 −0.000 0.000 0.000 0.00026 1.001 −16.842 −0.035 −0.023 0.000 0.000 0.00027 1.026 −15.912 −0.000 −0.000 0.000 0.000 0.00028 1.011 −12.057 −0.000 −0.000 0.000 0.000 0.00029 1.006 −17.136 −0.024 −0.009 0.000 0.000 0.00030 0.995 −18.015 −0.106 −0.019 0.000 0.000 0.000

Total −2.834 −1.262 3.010 1.251 0.233

Transmission Line Flow and Loss

Bus Bus Power Flow Power Flow −−−Power Loss−−−nl. nr. nl to nr nr to nl MW Mvar

1 2 1.778+j −0.221 −1.723+j 0.327 0.055 0.1051 3 0.832+j 0.051 −0.804+j 0.020 0.028 0.0712 4 0.457+j 0.027 −0.446+j −0.032 0.011 −0.005

Page 76: pfatb_v1.0a

68 Introduction to PFATB

3 4 0.780+j −0.032 −0.772+j 0.045 0.008 0.0132 5 0.830+j 0.017 −0.800+j 0.065 0.030 0.0822 6 0.619+j −0.010 −0.599+j 0.032 0.020 0.0234 6 0.701+j −0.175 −0.695+j 0.187 0.006 0.0125 7 −0.142+j 0.105 0.144+j −0.122 0.002 −0.0176 7 0.375+j −0.019 −0.372+j 0.013 0.004 −0.0066 8 0.295+j −0.038 −0.294+j 0.032 0.001 −0.0066 9 0.277+j −0.297 −0.277+j 0.331 0.000 0.0346 10 0.158+j −0.113 −0.158+j 0.134 0.000 0.0219 11 0.000+j −0.157 0.000+j 0.161 0.000 0.0059 10 0.277+j 0.067 −0.277+j −0.059 0.000 0.0084 12 0.441+j −0.460 −0.441+j 0.561 0.000 0.101

12 13 0.000+j −0.103 0.000+j 0.104 0.000 0.00112 14 0.079+j 0.024 −0.078+j −0.023 0.001 0.00212 15 0.179+j 0.069 −0.176+j −0.065 0.002 0.00412 16 0.072+j 0.034 −0.072+j −0.033 0.001 0.00114 15 0.016+j 0.007 −0.016+j −0.007 0.000 0.00016 17 0.037+j 0.015 −0.036+j −0.014 0.000 0.00015 18 0.060+j 0.017 −0.060+j −0.017 0.000 0.00118 19 0.028+j 0.008 −0.028+j −0.008 0.000 0.00019 20 −0.067+j −0.026 0.067+j 0.027 0.000 0.00010 20 0.090+j 0.036 −0.089+j −0.034 0.001 0.00210 17 0.054+j 0.044 −0.054+j −0.044 0.000 0.00010 21 0.157+j 0.098 −0.156+j −0.096 0.001 0.00210 22 0.076+j 0.045 −0.075+j −0.044 0.001 0.00121 22 −0.019+j −0.016 0.019+j 0.016 0.000 0.00015 23 0.050+j 0.030 −0.050+j −0.029 0.000 0.001

Total 0.050+j 0.030 −0.050+j −0.029 0.176 0.307

Solution 2: Power Flow Solution by N-R AlgorithmWith Rectangular Coordinate Method

Power Flow Solution by N−R Algorithm With Rectangular Coordinate MethodMaximum Active Power Mismatch = 2.96612e−011Maximum Reactive Power Mismatch = 8.25393e−011

No. of Iterations = 5

Bus Real Imaginary −−−−−−Load−−−−−− −−−Generation−−− InjectedNo. E F MW Mvar MW Mvar Mvar

1 1.060 0.000 −0.000 −0.000 2.610 −0.170 0.0002 1.038 −0.100 −0.217 −0.127 0.400 0.488 0.0003 1.012 −0.142 −0.024 −0.012 0.000 0.000 0.0004 0.998 −0.170 −0.076 −0.016 0.000 0.000 0.0005 0.978 −0.251 −0.942 −0.190 0.000 0.360 0.0006 0.992 −0.200 −0.000 −0.000 0.000 0.000 0.0007 0.977 −0.228 −0.228 −0.109 0.000 0.000 0.0008 0.988 −0.212 −0.300 −0.300 0.000 0.308 0.0009 1.018 −0.262 −0.000 −0.000 0.000 0.000 0.000

10 1.004 −0.288 −0.058 −0.020 0.000 0.000 0.19011 1.048 −0.270 −0.000 −0.000 0.000 0.161 0.00012 1.020 −0.279 −0.112 −0.075 0.000 0.000 0.00013 1.033 −0.283 −0.000 −0.000 0.000 0.104 0.00014 1.001 −0.291 −0.062 −0.016 0.000 0.000 0.00015 0.996 −0.291 −0.082 −0.025 0.000 0.000 0.00016 1.005 −0.286 −0.035 −0.018 0.000 0.000 0.00017 0.998 −0.290 −0.090 −0.058 0.000 0.000 0.00018 0.984 −0.299 −0.032 −0.009 0.000 0.000 0.00019 0.980 −0.301 −0.095 −0.034 0.000 0.000 0.000

Page 77: pfatb_v1.0a

Introduction to PFATB 69

20 0.985 −0.298 −0.022 −0.007 0.000 0.000 0.00021 0.990 −0.293 −0.175 −0.112 0.000 0.000 0.00022 0.990 −0.293 −0.000 −0.000 0.000 0.000 0.00023 0.984 −0.295 −0.032 −0.016 0.000 0.000 0.00024 0.978 −0.296 −0.087 −0.067 0.000 0.000 0.04325 0.977 −0.288 −0.000 −0.000 0.000 0.000 0.00026 0.958 −0.290 −0.035 −0.023 0.000 0.000 0.00027 0.986 −0.281 −0.000 −0.000 0.000 0.000 0.00028 0.988 −0.211 −0.000 −0.000 0.000 0.000 0.00029 0.961 −0.296 −0.024 −0.009 0.000 0.000 0.00030 0.946 −0.308 −0.106 −0.019 0.000 0.000 0.000

Total −2.834 −1.262 3.010 1.251 0.233

Transmission Line Flow and Loss

Bus Bus Power Flow Power Flow −−−Power Loss−−−nl. nr. nl to nr nr to nl MW Mvar

1 2 1.778+j −0.221 −1.723+j 0.327 0.055 0.1051 3 0.832+j 0.051 −0.804+j 0.020 0.028 0.0712 4 0.457+j 0.027 −0.446+j −0.032 0.011 −0.0053 4 0.780+j −0.032 −0.772+j 0.045 0.008 0.0132 5 0.830+j 0.017 −0.800+j 0.065 0.030 0.0822 6 0.619+j −0.010 −0.599+j 0.032 0.020 0.0234 6 0.701+j −0.175 −0.695+j 0.187 0.006 0.0125 7 −0.142+j 0.105 0.144+j −0.122 0.002 −0.0176 7 0.375+j −0.019 −0.372+j 0.013 0.004 −0.0066 8 0.295+j −0.038 −0.294+j 0.032 0.001 −0.0066 9 0.277+j −0.297 −0.277+j 0.331 0.000 0.0346 10 0.158+j −0.113 −0.158+j 0.134 0.000 0.0219 11 0.000+j −0.157 −0.000+j 0.161 0.000 0.0059 10 0.277+j 0.067 −0.277+j −0.059 0.000 0.0084 12 0.441+j −0.460 −0.441+j 0.561 0.000 0.101

12 13 0.000+j −0.103 −0.000+j 0.104 0.000 0.00112 14 0.079+j 0.024 −0.078+j −0.023 0.001 0.00212 15 0.179+j 0.069 −0.176+j −0.065 0.002 0.00412 16 0.072+j 0.034 −0.072+j −0.033 0.001 0.00114 15 0.016+j 0.007 −0.016+j −0.007 0.000 0.00016 17 0.037+j 0.015 −0.036+j −0.014 0.000 0.00015 18 0.060+j 0.017 −0.060+j −0.017 0.000 0.00118 19 0.028+j 0.008 −0.028+j −0.008 0.000 0.00019 20 −0.067+j −0.026 0.067+j 0.027 0.000 0.00010 20 0.090+j 0.036 −0.089+j −0.034 0.001 0.00210 17 0.054+j 0.044 −0.054+j −0.044 0.000 0.00010 21 0.157+j 0.098 −0.156+j −0.096 0.001 0.00210 22 0.076+j 0.045 −0.075+j −0.044 0.001 0.00121 22 −0.019+j −0.016 0.019+j 0.016 0.000 0.00015 23 0.050+j 0.030 −0.050+j −0.029 0.000 0.001

Total 0.050+j 0.030 −0.050+j −0.029 0.176 0.307

Solution 3: Power Flow Solution by P-QDecoupling AlgorithmWith Polar CoordinateMethod

Power Flow Solution by P−Q Decoupling Algorithm With Polar Coordinate MethodMaximum Active Power Mismatch = 5.85519e−006Maximum Reactive Power Mismatch = 2.98278e−006

No. of Iterations = 37

Page 78: pfatb_v1.0a

70 Introduction to PFATB

Bus Voltage Angle −−−−−−Load−−−−−− −−−Generation−−− InjectedNo. Mag. Degree MW Mvar MW Mvar Mvar

1 1.060 0.000 −0.000 −0.000 2.610 −0.170 0.0002 1.043 −5.497 −0.217 −0.127 0.400 0.488 0.0003 1.022 −8.004 −0.024 −0.012 0.000 0.000 0.0004 1.013 −9.661 −0.076 −0.016 0.000 0.000 0.0005 1.010 −14.381 −0.942 −0.190 0.000 0.360 0.0006 1.012 −11.398 −0.000 −0.000 0.000 0.000 0.0007 1.003 −13.150 −0.228 −0.109 0.000 0.000 0.0008 1.010 −12.115 −0.300 −0.300 0.000 0.308 0.0009 1.051 −14.434 −0.000 −0.000 0.000 0.000 0.000

10 1.044 −16.024 −0.058 −0.020 0.000 0.000 0.19011 1.082 −14.434 −0.000 −0.000 0.000 0.161 0.00012 1.057 −15.302 −0.112 −0.075 0.000 0.000 0.00013 1.071 −15.302 −0.000 −0.000 0.000 0.104 0.00014 1.042 −16.191 −0.062 −0.016 0.000 0.000 0.00015 1.038 −16.278 −0.082 −0.025 0.000 0.000 0.00016 1.045 −15.880 −0.035 −0.018 0.000 0.000 0.00017 1.039 −16.188 −0.090 −0.058 0.000 0.000 0.00018 1.028 −16.884 −0.032 −0.009 0.000 0.000 0.00019 1.025 −17.052 −0.095 −0.034 0.000 0.000 0.00020 1.029 −16.852 −0.022 −0.007 0.000 0.000 0.00021 1.032 −16.468 −0.175 −0.112 0.000 0.000 0.00022 1.033 −16.455 −0.000 −0.000 0.000 0.000 0.00023 1.027 −16.662 −0.032 −0.016 0.000 0.000 0.00024 1.022 −16.830 −0.087 −0.067 0.000 0.000 0.04325 1.019 −16.424 −0.000 −0.000 0.000 0.000 0.00026 1.001 −16.842 −0.035 −0.023 0.000 0.000 0.00027 1.026 −15.912 −0.000 −0.000 0.000 0.000 0.00028 1.011 −12.057 −0.000 −0.000 0.000 0.000 0.00029 1.006 −17.136 −0.024 −0.009 0.000 0.000 0.00030 0.995 −18.015 −0.106 −0.019 0.000 0.000 0.000

Total −2.834 −1.262 3.010 1.251 0.233

Transmission Line Flow and Loss

Bus Bus Power Flow Power Flow −−−Power Loss−−−nl. nr. nl to nr nr to nl MW Mvar

1 2 1.778+j −0.221 −1.723+j 0.327 0.055 0.1051 3 0.832+j 0.051 −0.804+j 0.020 0.028 0.0712 4 0.457+j 0.027 −0.446+j −0.032 0.011 −0.0053 4 0.780+j −0.032 −0.772+j 0.045 0.008 0.0132 5 0.830+j 0.017 −0.800+j 0.065 0.030 0.0822 6 0.619+j −0.010 −0.599+j 0.032 0.020 0.0234 6 0.701+j −0.175 −0.695+j 0.187 0.006 0.0125 7 −0.142+j 0.105 0.144+j −0.122 0.002 −0.0176 7 0.375+j −0.019 −0.372+j 0.013 0.004 −0.0066 8 0.295+j −0.038 −0.294+j 0.032 0.001 −0.0066 9 0.277+j −0.297 −0.277+j 0.331 0.000 0.0346 10 0.158+j −0.113 −0.158+j 0.134 0.000 0.0219 11 −0.000+j −0.157 0.000+j 0.161 0.000 0.0059 10 0.277+j 0.067 −0.277+j −0.059 0.000 0.0084 12 0.441+j −0.460 −0.441+j 0.561 0.000 0.101

12 13 0.000+j −0.103 −0.000+j 0.104 0.000 0.00112 14 0.079+j 0.024 −0.078+j −0.023 0.001 0.002

Page 79: pfatb_v1.0a

Introduction to PFATB 71

12 15 0.179+j 0.069 −0.176+j −0.065 0.002 0.00412 16 0.072+j 0.034 −0.072+j −0.033 0.001 0.00114 15 0.016+j 0.007 −0.016+j −0.007 0.000 0.00016 17 0.037+j 0.015 −0.036+j −0.014 0.000 0.00015 18 0.060+j 0.017 −0.060+j −0.017 0.000 0.00118 19 0.028+j 0.008 −0.028+j −0.008 0.000 0.00019 20 −0.067+j −0.026 0.067+j 0.027 0.000 0.00010 20 0.090+j 0.036 −0.089+j −0.034 0.001 0.00210 17 0.054+j 0.044 −0.054+j −0.044 0.000 0.00010 21 0.157+j 0.098 −0.156+j −0.096 0.001 0.00210 22 0.076+j 0.045 −0.075+j −0.044 0.001 0.00121 22 −0.019+j −0.016 0.019+j 0.016 0.000 0.00015 23 0.050+j 0.030 −0.050+j −0.029 0.000 0.001

Total 0.050+j 0.030 −0.050+j −0.029 0.176 0.307