power system analysis toolbox

Upload: joyjoy-c-lbanez

Post on 14-Apr-2018

265 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Power System Analysis Toolbox

    1/79

    Introduction toPower Flow Analysis ToolboxVersion 1.0a

    Revision: February, 2011

    Chao LeiSichuan Agricultural University

    advancedMcode.org

  • 7/30/2019 Power System Analysis Toolbox

    2/79

    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.

  • 7/30/2019 Power System Analysis Toolbox

    3/79

    Dedicated to my mother, Yurong Wang,who practiced ingenuity,

    and to my friend, Biwei Su,who raised me up to more than I can be

  • 7/30/2019 Power System Analysis Toolbox

    4/79

    This page intentionally left blank

  • 7/30/2019 Power System Analysis Toolbox

    5/79

    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 introductionit iswritten for the practicing scientist, engineer, and so forth. The reader who wishes to know more

    about 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 forwardusers 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 toa Long at 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 at 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 at Lancaster University andLab Technical Engineer Hong Wen at 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 at 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

  • 7/30/2019 Power System Analysis Toolbox

    6/79

    This page intentionally left blank

  • 7/30/2019 Power System Analysis Toolbox

    7/79

    Contents

    1 INTRODUCTION 1

    1.1 An Overview of PFATB 1

    1.2 PFATB-Interface 2

    2 ABOUT AUTHOR 3

    3 INSTALLATION 4

    4 TOOLBOX DESIGN 5

    4.1 Toolbox Design Process 5

    4.2 MATLAB Programming Style 6

    5 STANDARD DATA STRUCTURES 75.1 Bus Data 7

    5.2 Transmission Line Data and Transformer Data 7

    5.3 Transmission Line Admittance Data 8

    5.4 Transmission Line Flow and Loss Data 9

    6 TOOLBOX FUNCTIONS 13

    6.1 Data Pre-processing 13

    6.2 Execute Algorithms 17

    6.3 Data Reconfiguration 26

    6.4 Output Solution 26

    7 POWER FLOW ALGORITHMS 29

    7.1 Algorithm Convergence Speed 29

    7.2 Gauss-Seidel Algorithm 30

    7.3 Newton-Raphson Algorithm 38

    7.3.1 N-R Algorithm With Polar Coordinate System 38

    7.3.2 N-R Algorithm With Rectangular Coordinate System 45

    7.4 P-Q Decoupling Algorithm 52

    7.5 Algorithm Discussions 59

    8 IEEE 30-BUS TEST SYSTEM 60

    9 FURTHER REVERSIONS 65A APPENDIX IEEE 30-BUS SOLUTIONS 67

  • 7/30/2019 Power System Analysis Toolbox

    8/79

    This page intentionally left blank

  • 7/30/2019 Power System Analysis Toolbox

    9/79

    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

  • 7/30/2019 Power System Analysis Toolbox

    10/79

    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 readability

    in 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

  • 7/30/2019 Power System Analysis Toolbox

    11/79

    Introduction to PFATB 3

    2 ABOUT AUTHOR

    PFATB was 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.

  • 7/30/2019 Power System Analysis Toolbox

    12/79

    4 Introduction to PFATB

    3 INSTALLATION

    I authorize advancedMcode(See http://www.advancedmcode.org) to release PFATB for the user

    to download. It is available from PFATB Home Pagehttp://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 offthe 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 users 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 in IEEE 30-Bus Test System

    Section.In addition, PFATB can be obtained freely and anyone can use it. Because PFATB is free toolbox

    you 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 itll help our communications.

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

    http://www.mathworks.com/matlabcentral/fileexchange/30272mailto:[email protected]://www.advancedmcode.org/power-flow-analysis-toolboxpfatb.html
  • 7/30/2019 Power System Analysis Toolbox

    13/79

    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

    DataPre-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-

  • 7/30/2019 Power System Analysis Toolbox

    14/79

    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 arent 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, its 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 isnt include how to address efficiency concerns, with recommendations such asDont 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 onesthey havefewer errors and are easier to debug and to modifyso it is important to think about style fromthe beginning.

  • 7/30/2019 Power System Analysis Toolbox

    15/79

    Introduction to PFATB 7

    5 STANDARD DATA 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 3

    and 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 Coordinate

    Bus 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

  • 7/30/2019 Power System Analysis Toolbox

    16/79

    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/2 B Tr.Tap Settingnl nr p.u. p.u. p.u. p.u.

    Transformer Data

    Two-winding transformer or three-winding transformer data is included in last column ofline 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 = YTk 1

    k +

    YTk = YT (5.1)

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

    Yj = YT1 k

    k2

    +YTk

    =YT

    k2

    (5.2)

    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

    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.

  • 7/30/2019 Power System Analysis Toolbox

    17/79

    Introduction to PFATB 9

    TABLE 5.4: Line Admittance Data StructureBus Bus Line Admittance Branch Admittance Branch Admittancenl 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 Lossnl 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

  • 7/30/2019 Power System Analysis Toolbox

    18/79

    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 Mvar

    1 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/2 B 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 12

    2-3 0.08 0.30 0.25 12

    TABLE 5.8: Transformer DataBus R X 1/2 B 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, two

    of 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 estimates 0. The initialvoltage magnitude of each PV bus labeled in type 2 estimates 1.05 and its phase angle estimates0, respectively. The initial voltage magnitude of the slack bus labeled in type 3 estimates 1.05and its phase angle estimate 0. In Table 5.10, the initial voltage real part e of each PQ bus labeledin type 1 estimates 1 and its imaginary part f estimates 0. The initial voltage real part e of eachPV bus labeled in type 2 estimates 1.05 and its imaginary part f estimates 0. The initial voltagereal part e of the slack bus labeled in type 3 estimates 1.05 and its imaginary part f estimates 0.Note that bus 1-3 are load buses with no generations, and their real power P and reactive power

    Q should be negative; 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 bus

    4 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.

  • 7/30/2019 Power System Analysis Toolbox

    19/79

    Introduction to PFATB 11

    bus 4 bus 2

    j0.015

    1:1.05

    bus 4 bus 2

    High voltageLow voltage

    YT/k

    1-k

    k2YT

    k-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

    =

    1

    j0.015

    1.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 YT

    k-1

    k YT

    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

    =

    1

    j0.030

    1.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.

  • 7/30/2019 Power System Analysis Toolbox

    20/79

    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 Mvar

    1 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 Coordinate

    Bus Bus Real Imaginary -Load- -Generator- InjectedNo Type e f MW Mvar MW Mvar Qmin Qmax Mvar

    1 1 1 0 -1.6 -0.8 0 0 0 0 0

    2 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/2 B Tr.Tap Settingnl nr p.u. p.u. p.u. p.u.

    1 2 0.04 0.25 0.25 1

    1 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

  • 7/30/2019 Power System Analysis Toolbox

    21/79

    Introduction to PFATB 13

    6 TOOLBOX FUNCTIONS

    In this section, we start to introduce PFATB toolbox functions. It begins with a list of functions

    categorized 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.m

    clc;

    clear all

    %% Bus data

    % Bus Bus Voltage Angle Load Generator Injected

    % No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar

    bus = [1 3 1 0 0 0 0 0 0 0 02 1 1 0 0.8 0.6 0 0 0 0 0

  • 7/30/2019 Power System Analysis Toolbox

    22/79

    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 1

    3 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 0

    2.00 2.00 1.10 0 0 0 0.40 0 0.5 0.5 0

    3.00 3.00 1.00 0 0 0 0 0 0.5 0.5 0line =

    3.00 2.00 0.05 0.20 0 1.00

    1.00 3.00 0.01 0.04 0 1.00

    2.00 0 0 0 3.03 1.00

    nPQ =

    1.00

    nPV =

    1.00

    nodenum =

    1.00 2.00

    2.00 3.00

    3.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 is

    known as the mutual admittance or transfer admittance, which equals the negative of branchadmittance connecting bus i to bus j. If theres 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.

  • 7/30/2019 Power System Analysis Toolbox

    23/79

    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 methodthe resistance is ignored during the calculation ofB, expressed in (6.1)(6.4).

    B

    ij = 1

    xij(6.1)

    B

    ii =n

    ji

    xij (6.2)

    B

    ij

    = xij

    r2ij + x2ij(6.3)

    B

    ii = n

    ji

    B

    ij (6.4)

    [B1,B2,Y] = Bpq(bus,line,nPQ,BX) returns the bus admittance B and B with BX methodtheresistance is ignored during the calculation ofB, expressed in (6.5)(6.8).

    B

    ij = xij

    r2ij + x2ij

    (6.5)

    B

    ii =n

    ji

    xij

    r2ij + x2ij

    (6.6)

    B

    ij = 1

    xij(6.7)

    B

    ii = n

    ji 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

  • 7/30/2019 Power System Analysis Toolbox

    24/79

    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.m

    clc;

    clear all

    %% Bus data

    % Bus Bus Voltage Angle Load Generator Injected

    % No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar

    bus = [1 3 1.05 0 0 0 0 0 0 0 0

    2 2 1 0 2.566 1.102 0 0 0 0 0

    3 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 1

    2 3 0.0125 0.025 0 1];

    % Evaluate Ybus

    Y = 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 Yline

    YtYm = 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.0000i10.0000 +30.0000i 16.0000 +32.0000i 26.0000 62.0000i

  • 7/30/2019 Power System Analysis Toolbox

    25/79

    Introduction to PFATB 17

    B1 =

    50 20

    20 52

    B2 =

    50 2020 52

    B1 =

    58.3333 25.0000

    25.0000 65.0000

    B2 =

    50 20

    20 52

    B1 =

    50 20

    20 52

    B2 =

    58.3333 25.0000

    25.0000 65.0000

    YtYm =

    Columns 1 through 4

    1.0000 2.0000 10.0000 20.0000i 0

    1.0000 3.0000 10.0000 30.0000i 0

    2.0000 3.0000 16.0000 32.0000i 0

    Column 5

    0

    0

    0

    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 doesnt 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 functions 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

    nj=1

    YijU(k+1)j

    Yii

    (i j) (6.9)

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

  • 7/30/2019 Power System Analysis Toolbox

    26/79

    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

    nj=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

    nj=1

    Uj(Gijcosij + Bijsinij) (6.12)

    Qis = Qis Qi + Qvari = Qis + Qvari Ui

    nj=1

    Uj(Gijsinij Bijcosij) (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)

  • 7/30/2019 Power System Analysis Toolbox

    27/79

    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 ei

    nj=1

    (Gijej Bijfj) fi

    nj=1

    (Gijfj + Bijej) (6.14)

    Qi = Qis + Qvari Qi = Qis + Qvari fi

    nj=1

    (Gijej Bijfj) + ei

    nj=1

    (Gijfj + Bijej) (6.15)

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

    PPV = PPV0 PPV = PPV0 ePVn

    j=1

    (GPV jej BPV jfj) fPVn

    j=1

    (GPV jfj + BPV jej) (6.16)

    U2PV = U2PV0 U

    2PV = U

    2PV0 (f

    2PV + e

    2PV) (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 = Ui Uj(Gijsinij Bijcosij) (i j) (6.18)

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

    Nij = Ui Uj(Gijcosij Bijsinij) (i j) (6.20)

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

    Kij = Ui Uj(Gijcosij Bijsinij) (i j) (6.22)

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

    Lij = Ui Uj(Gijsinij Bijcosij) (i j) (6.24)

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

  • 7/30/2019 Power System Analysis Toolbox

    28/79

    20 Introduction to PFATB

    where

    Pi = Ui

    n

    j=1Uj(Gijcosij + Bijsinij)

    Qi = Ui

    nj=1

    Uj(Gijsinij Bijcosij)

    The element Hij =Pij

    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 =PiUj

    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 =QiUj

    Uj 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) Gii ei Bii fi (i = j) (6.27)

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

    Nii = n

    j=1

    (Gijfj + Bijej) Gii ei + Bii fi (i = j) (6.29)

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

    Kii =

    nj=1

    (Gijfj + Bijej) Gii fi + Bii ei (i = j) (6.31)

  • 7/30/2019 Power System Analysis Toolbox

    29/79

    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 =Pifj

    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 = Piejindicates 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 =U2p

    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 =U2p

    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 = LU1U = 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

  • 7/30/2019 Power System Analysis Toolbox

    30/79

    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.

    [PQ] = [H NK L ][ U1U] (6.39)

    where

    [PQ

    ]=

    P1P2

    ...Pn1Q1Q2

    ..

    .Qn1nPV

    [H NK L

    ]=

    H1,1 H1,2 . . . H 1,n1...

    ......

    ...Hn1,1 Hn1,2 . . . H n1,n1

    N1,1 N1,2 . . . N 1,n1...

    ......

    ...Nn1,1 Nn1,2 . . . N n1,n1nPV

    K1,1 K1,2 . . . K 1,n1...

    ......

    ...Kn1nPV,1 Kn1nPV,2 . . . K n1nPV,n1

    L1,1 L1,2 . . . L1,n1...

    ......

    ...Ln1nPV,1 Ln1nPV,2 . . . Ln1nPV,n1nPV

    [

    U1U

    ]=

    12

    ...n1U1U1U1U2

    ...U1Un1

    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

    QU2

    = H N

    K LR S

    [ef] (6.40)

  • 7/30/2019 Power System Analysis Toolbox

    31/79

    Introduction to PFATB 23

    where

    PQU2

    =

    P1P2

    .

    ..Pn1Q1Q2

    ...Qn1nPVU21U22

    ...

    U2nPV

    H NK LR S

    =

    H11 H12 . . . H 1,n1...

    ......

    ...Hn1,1 Hn1,2 . . . H n1,n1

    N11 N12 . . . N 1,n1...

    ......

    ...Nn1,1 Nn1,2 . . . N n1,n1

    K11 K12 . . . K 1,n1...

    ......

    ...Kn1nPV,1 Kn1nPV,2 . . . K n1nPV,n1

    L11 L12 . . . L1,n1...

    ......

    ...Ln1nPV,1 Ln1nPV,2 . . . Ln1nPV,n1

    R11 R12 . . . R1,n1...

    ......

    ...RnPV,1 RnPV,2 . . . RnPV,n1

    S11 S12 . . . S1,n1...

    ......

    ...SnPV,1 SnPV,2 . . . SnPV,n1

    [fe

    ]=

    f1f2

    ...fn1e1e2

    ...en1

    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

  • 7/30/2019 Power System Analysis Toolbox

    32/79

    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 and maximum, 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

  • 7/30/2019 Power System Analysis Toolbox

    33/79

    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 power

    equation (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.

    Ss = Us nj=1

    (YsjUj) (6.43)

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

    QPV =n

    j=1

    UPVUj(GPV jsi n(PV j) BPV jcos(PV j)) QPV l QPV s (6.44)

    where QPV l are the load reactive power and are negative. QPV s are the injected reactive powerfrom shunt capacitors and are positive. Note that UPVPV 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(GPV jcos(SW j) + BPV jsin(SW j)) PSW l (6.45)

    QSW =n

    j=1USWUj(GSW jsin(SW j) BSW jcos(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 USWSW 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.

    QPV = fPV

    nj=1

    BPV jfPV j + ePV

    nj=1

    BPV jePV j QPV l QPV s (6.47)

    where QPV l are the load reactive power and are negative. QPV s are the injected reactive powerfrom shunt capacitors and are positive. Note that ePV +jfPV is the balanced voltage of the PV bus.

  • 7/30/2019 Power System Analysis Toolbox

    34/79

    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 = eSW

    nj=1

    BSW jfSW j fSW

    nj=1

    BSW jeSW j PSW l (6.48)

    QSW = fSW

    nj=1

    BSW jfSW j + eSW

    nj=1

    BSW jeSW j 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 Reconfigurationresetbus 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 Sij~

    S~

    UjUiSij~

    ji

    FIGURE 6.3: Transmission line flow and loss

    Transmission line flow

  • 7/30/2019 Power System Analysis Toolbox

    35/79

    Introduction to PFATB 27

    In Figure 6.3, Sij 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

    Sij = Ui [Ui Yi0 + (Ui Uj)Yij] (6.50)Rearranging (6.50) we can get Sij = U2i (Yij + Yi0) Ui UjYij (6.51)Similarly, Sji 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 asSji = Uj[UjYj0 + (Uj Ui )Yji ] (6.52)Rearranging (6.52) we can get

    Sji = U

    2j (Y

    ji + Y

    j0) UjU

    i Y

    ji (6.53)

    Transmission line lossTransmission line power loss Sij can be expressed as

    Sij = Sij +Sji (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).

  • 7/30/2019 Power System Analysis Toolbox

    36/79

    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).

  • 7/30/2019 Power System Analysis Toolbox

    37/79

    Introduction to PFATB 29

    7 POWER FLOW ALGORITHMS

    This section demonstrates how power flow algorithms can be constructed in steps and using

    routines 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) =

    nnPV1

    i=1U2 (7.1)

    Speed() =

    n1i=1

    2 (7.2)

    Algorithm convergence speed in rectangular coordinate:

    Speed(e) =

    n1i=1

    e2 (7.3)

    Speed(f) =

    n1i=1

    f2 (7.4)

  • 7/30/2019 Power System Analysis Toolbox

    38/79

    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 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 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 residualsQ(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)

    % GaussSeidel 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.0e6 and kmax = 100 in default.

    %

    % See also sortbus,busAM,busVnewPQ,busVnewPV,powerSW,resetbus,lineAM,powerTScm

  • 7/30/2019 Power System Analysis Toolbox

    39/79

    Introduction to PFATB 31

    % Author(s):Chao Lei

    % $Date:2011/02/02 02:40$

    if nargin < 2

    error('Please input 2 variables');end

    if nargin == 2

    EPS = 1.0e6; % Tolerance Accuracy

    kmax = 100; % Maximum iterations

    elseif nargin == 3

    kmax = 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 Figure

    clf;

    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 coordinate

    busV = 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:n1,1); % Preallocate

    busV_PQ = busV(1:nPQ,1);

    de = zeros(n,1); % Preallocate

    df = zeros(n,1);

    P = zeros(n1,1);Q = zeros(n1,1);

    P = bus(1:n1,5)+bus(1:n1,7); % Active power P

    Q = bus(1:n1,6)+bus(1:n1,8)+bus(1:n1,11); % Reactive power Q

    % The Constant voltage magnitude of each PV bus

    bus0 = zeros(n1nPQ,1);

    bus0(:,1) = bus(nPQ+1:n1,3);

    k = 1 ;

    while (k kmax)

    % Step 4: Evaluate new bus voltage at each PQ bus

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

  • 7/30/2019 Power System Analysis Toolbox

    40/79

    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:n1,1); % Step 7: Evaluate delta Q

    % Record Q for comparison at next iteration

    Q(nPQ+1:n1,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 f

    df = imag(busV busV_temp);

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

    derd(k,:) = de';

    % Record bus for comparison at next iteration

    busV_temp = busV;

    if (max(abs(dQ))

  • 7/30/2019 Power System Analysis Toolbox

    41/79

    Introduction to PFATB 33

    % Step 10: Evaluate Power of the swing bus

    S = powerSW(busV,Y,n);

    % Allocate and update variables into bus matrix

    bus(:,3) = real(busV);bus(:,4) = imag(busV);

    bus(n,7) = real(S);

    bus(n,8) = imag(S);

    bus(nPQ+1:n1,8) = Q(nPQ+1:n1,1) bus(nPQ+1:n1,6);

    % Step 11: Reconfigure Bus Numbers

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

    % Step 12: Evaluate line flow and loss

    YtYm = lineAM(line_temp);

    s_res = powerTScm(bus_temp,line_temp,YtYm);

    bus_res = bus_temp;

    % Step 13: Output Solution

    format short

    % Output Bus Solution

    disp(' ')

    disp(' Power Flow Solution by GaussSeidel Algorithm')

    busout(bus_res,dQ,n,k);

    % Output Line Solution

    disp(' ')

    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))

    end

    fprintf(' \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)))

    % Subfunctionfunction lineflow(s_res,n)

  • 7/30/2019 Power System Analysis Toolbox

    42/79

    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 : n

    fprintf(' %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))),

    end

    fprintf(' \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 : n1

    disp(' ')

    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 : k1fprintf(' %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,:))

    end

    end

    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 angle

    bus number 1 2 3

    U(0)(0) 1.050 10 1.040

  • 7/30/2019 Power System Analysis Toolbox

    43/79

    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.m

    clc;

    clear all

    %% Bus data

    % Bus Bus Voltage Angle Load Generator Injected

    % No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar

    bus = [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 0

    3 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 1

    2 3 0.0125 0.025 0 1];

    %% GaussSeidel Algorithm

    [bus_res,s_res,k] = GS(bus,line)

    Try it out and then it results in

    Power Flow Solution by GaussSeidel Algorithm

    Maximum Reactive Power Mismatch = 5.13925e007

    No. of Iterations = 21

    Bus Real Imaginary Load Generation Injected

    No. E F MW Mvar MW Mvar Mvar

    1 1.050 0.000 0.000 0.000 2.184 1.409 0.000

    2 0.971 0.046 4.000 2.500 0.000 0.000 0.000

    3 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

  • 7/30/2019 Power System Analysis Toolbox

    44/79

    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.005

    2 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 Delta

    No. E F E F Mvar Q

    1 1.04000 0.00125 1.04000 0.00125 0.00000 0.00000

    2 1.03999 0.00376 0.00001 0.00501 0.00000 0.00000

    3 1.03998 0.00647 0.00001 0.00271 0.00000 0.00000

    4 1.03997 0.00770 0.00001 0.00123 0.00000 0.00000

    5 1.03997 0.00837 0.00001 0.00066 0.00000 0.00000

    6 1.03996 0.00870 0.00000 0.00034 0.00000 0.00000

    7 1.03996 0.00887 0.00000 0.00017 0.00000 0.00000

    8 1.03996 0.00896 0.00000 0.00009 0.00000 0.00000

    9 1.03996 0.00901 0.00000 0.00005 0.00000 0.00000

    10 1.03996 0.00903 0.00000 0.00002 0.00000 0.00000

    11 1.03996 0.00904 0.00000 0.00001 0.00000 0.00000

    12 1.03996 0.00905 0.00000 0.00001 0.00000 0.00000

    13 1.03996 0.00905 0.00000 0.00000 0.00000 0.00000

    14 1.03996 0.00905 0.00000 0.00000 0.00000 0.0000015 1.03996 0.00905 0.00000 0.00000 0.00000 0.00000

    16 1.03996 0.00905 0.00000 0.00000 0.00000 0.00000

    17 1.03996 0.00905 0.00000 0.00000 0.00000 0.00000

    18 1.03996 0.00905 0.00000 0.00000 0.00000 0.00000

    19 1.03996 0.00905 0.00000 0.00000 0.00000 0.00000

    20 1.03996 0.00905 0.00000 0.00000 0.00000 0.00000

    Display each iteration at bus 3

    Iter Real Imaginary Delta Delta Generation Delta

    No. E F E F Mvar Q

    1 1.04000 0.00125 1.04000 0.00125 1.16000 1.16000

    2 1.03999 0.00376 0.00001 0.00501 1.29435 0.134353 1.03998 0.00647 0.00001 0.00271 1.36683 0.07248

    4 1.03997 0.00770 0.00001 0.00123 1.41578 0.04895

    5 1.03997 0.00837 0.00001 0.00066 1.43793 0.02215

    6 1.03996 0.00870 0.00000 0.00034 1.44955 0.01162

    7 1.03996 0.00887 0.00000 0.00017 1.45552 0.00597

    8 1.03996 0.00896 0.00000 0.00009 1.45856 0.00305

    9 1.03996 0.00901 0.00000 0.00005 1.46013 0.00156

    10 1.03996 0.00903 0.00000 0.00002 1.46093 0.00080

    11 1.03996 0.00904 0.00000 0.00001 1.46134 0.00041

    12 1.03996 0.00905 0.00000 0.00001 1.46155 0.00021

    13 1.03996 0.00905 0.00000 0.00000 1.46166 0.00011

    14 1.03996 0.00905 0.00000 0.00000 1.46171 0.00006

    15 1.03996 0.00905 0.00000 0.00000 1.46174 0.0000316 1.03996 0.00905 0.00000 0.00000 1.46175 0.00001

  • 7/30/2019 Power System Analysis Toolbox

    45/79

    Introduction to PFATB 37

    17 1.03996 0.00905 0.00000 0.00000 1.46176 0.00001

    18 1.03996 0.00905 0.00000 0.00000 1.46177 0.00000

    19 1.03996 0.00905 0.00000 0.00000 1.46177 0.00000

    20 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 GaussSeidel Algorithm

    Iterations

    Speed

    E Increments

    F Increments

    FIGURE 7.2: The convergence speed of Gauss-Seidel algorithm

  • 7/30/2019 Power System Analysis Toolbox

    46/79

    38 Introduction to PFATB

    7.3 Newton-Raphson Algorithm

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

    7.3.1 N-R Algorithm With Polar Coordinate System

    The function NRpm.m returns to solve power flow in N-R algorithm with polar coordinate method.

    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 voltage magnitude 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)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.

  • 7/30/2019 Power System Analysis Toolbox

    47/79

    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)

    % NewtonRaphson 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.0e6 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,changePVpm,dPQSWPVpm,resetbus,lineAM,powerTSpm

    % Author(s):Long,Chao Lei

    % $Date:2010/06/24 15:22$

    if nargin < 2

    error('Please input 2 variables');

    end

    if nargin == 2EPS = 1.0e6; % Tolerance Accuracy

    kmax = 100; % Maximum iterations

    option = 'unchangePVpm'; % Option default

    elseif nargin == 3

    kmax = 100; % Maximum iterations

    option = '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 Figure

    clf;

    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

  • 7/30/2019 Power System Analysis Toolbox

    48/79

    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 Variables

    bus(1:n1,4) = bus(1:n1,4) + dAng;

    % Record the delta Magnitude and delta Angle

    dUrd(k,:) = dU';

    dAngrd(k,:) = dAng';

    switch option

    case 'unchangePVpm'

    case 'changePVpm'

    % Step 8: Examine Reactive Power of each PV Bus

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

    bus = bus_new;

    end

    % Step 9: Termination Conditions

    if (max(abs(dU))

  • 7/30/2019 Power System Analysis Toolbox

    49/79

    Introduction to PFATB 41

    figure(2)

    plot(xk,dUrd_sq,'k',xk,dAngrd_sq,'k','LineWidth',2)

    title('The Convergence Speed of NewtonRaphson Algorithm')

    xlabel('Iterations');

    ylabel('Speed');legend('Magnitude Changes','Angle Changes')

    grid on

    % Step 10: Evaluate Power of the swing bus and each PV bus

    bus = dPQSWPVpm(bus,Y,nPQ);

    % Step 11: Reconfigure Bus Numbers

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

    % Step 12: Evaluate line flow and loss

    YtYm = 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 Solution

    format short

    % Output Bus Solution

    disp(' ')

    disp(' Power Flow Solution by NR Algorithm With Polar Coordinate Method')

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

    % Output Line Solution

    disp(' ')

    disp(' Transmission Line Flow and Loss')

    lineflow(s_res,n);

    % Display output at each iteration

    disp(' ')

    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))

    end

    fprintf(' \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)))

  • 7/30/2019 Power System Analysis Toolbox

    50/79

    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 : n

    fprintf(' %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))),

    end

    fprintf(' \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 : n1

    disp(' ')

    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 : m1

    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,:))

    end

    end

    Example 7.2

    Obtain the power flow solution by Newton-Raphson algorithm. Lets 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 angle

    bus number 1 2 3

    U(0)(0) 1.050 10 1.040

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

  • 7/30/2019 Power System Analysis Toolbox

    51/79

    Introduction to PFATB 43

    % ex7.2.m

    clc;

    clear all

    %% Bus data% Bus Bus Voltage Angle Load Generator Injected

    % No Type Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar

    bus = [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 0

    3 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 1

    2 3 0.0125 0.025 0 1];

    %% Newtonraphson With Polar Coorinate Method

    [bus_res,s_res,k] = NRpm(bus,line)

    Try it out and then it results in

    Power Flow Solution by NR Algorithm With Polar Coordinate Method

    Maximum Active Power Mismatch = 1.16762e009

    Maximum Reactive Power Mismatch = 8.82984e010

    No. of Iterations = 4

    Bus Voltage Angle Load Generation Injected

    No. Mag. Degree MW Mvar MW Mvar Mvar

    1 1.050 0.000 0.000 0.000 2.184 1.409 0.000

    2 0.972 2.696 4.000 2.500 0.000 0.000 0.000

    3 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.005

    2 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 Delta

    No. Mag. Degree Angle Mag. P Q

    1 0.97345 0.04526 0.04526 0.02655 2.86000 0.22000

    2 0.97168 0.04706 0.00180 0.00177 0.09922 0.050913 0.97168 0.04706 0.00000 0.00000 0.00022 0.00014

  • 7/30/2019 Power System Analysis Toolbox

    52/79

    44 Introduction to PFATB

    Display each iteration at bus 3

    Iter Voltage Angle Delta Delta Delta Delta

    No. Mag. Degree Angle Mag. P Q

    1 0.00000 0.00772 0.00772 0.00000 1.43840 0.00000

    2 0.00000 0.00870 0.00099 0.00000 0.02171 0.00000

    3 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 NewtonRaphson Algorithm

    Iterations

    Speed

    Magnitude Increments

    Angle Increments

    FIGURE 7.3: The convergence speed of Newton-Raphson algorithm

  • 7/30/2019 Power System Analysis Toolbox

    53/79

    Introduction to PFATB 45

    7.3.2 N-R Algorithm With Rectangular Coordinate System

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

    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 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 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 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 incrementsof 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 imaginarypart 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 exceeds

    the 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 each

    PV 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 in

    the bus data matrix and the line data matrix.Step 12: Evaluate line flow and loss. Evaluate real and reactive power flows in transmission

    lines and transformers, as well as equipment losses.Step 13: Output solution. Show the final bus voltage real part e and imaginary part f under

    balanced three-phase steady-state conditions.

    Power-flow Program Function

    A complete pseudo-code M-file NRcm.m of N-R algorithm with rectangular coordinate is shownbelow.

  • 7/30/2019 Power System Analysis Toolbox

    54/79

    46 Introduction to PFATB

    function [bus_res,S_res,k] = NRcm(bus,line,EPS,kmax,option)

    % NewtonRaphson 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.0e6 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 < 2

    error('Please input 2 variables');

    end

    if nargin == 2

    EPS = 1.0e6; % Tolerance Accuracy

    kmax = 100; % Maximum iterations

    option = 'unchangePVcm'; % Option default

    elseif nargin == 3

    kmax = 100; % Maximum iterations

    option = '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 Figure

    clf;

    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 bus

    bus0 = zeros(nPV,1);

    bus0 = bus(nPQ+1:n1,3).^2 + bus(nPQ+1:n1,4).^2;

    while (k kmax)

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

  • 7/30/2019 Power System Analysis Toolbox

    55/79

    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:n1,3) = bus(1:n1,3) + de; % Step 7: Update Variablesbus(1:n1,4) = bus(1:n1,4) + df;

    % Record the delta e and delta f

    dfrd(k,:) = df';

    derd(k,:) = de';

    switch option

    case 'unchangePVcm'

    case 'changePVcm'

    % Step 8: Examine Reactive Power of each PV Bus

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

    bus0 = bus0_new;

    end

    % Step 9: Termination Conditions

    if (max(abs(df))

  • 7/30/2019 Power System Analysis Toolbox

    56/79

    48 Introduction to PFATB

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

    grid on

    % Step 10: Evaluate Power of the swing bus and each PV bus

    bus = dPQSWPVcm(bus,Y,nPQ);

    % Step 11: Reconfigure Bus Numbers

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

    % Step 12: Evaluate line flow and loss

    YtYm = lineAM(line_temp);

    S_res = powerTScm(bus_temp,line_temp,YtYm);

    bus_res = bus_temp;

    % Step 13: Output Solution

    format short

    % Output Bus Solution

    disp(' ')

    disp(' Power Flow Solution by NR Algorithm With Rectangular Coordinate Method')

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

    % Output Line Solution

    disp(' ')

    disp(' Transmission Line Flow and Loss')

    lineflow(s_res,n);

    % Display output at each iteration

    disp(' ')

    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))

    end

    fprintf(' \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'

  • 7/30/2019 Power System Analysis Toolbox

    57/79

    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))),

    end

    fprintf(' \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:n1

    disp(' ')

    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:k1

    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,:))

    end

    end

    Example 7.3

    Obtain the power flow solution by N-R algorithm with rectangular coordinate method. Letsuse 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 f

    bus number 1 2 3

    e(0) + j f(0) 1 + j0 1 + j0 1 + j0

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

    % ex7.3.m

    clc;

    clear all

    %% Bus data%