You are on page 1of 16

Addendum to AC Power Flows and their

Derivatives using Complex Matrix Notation: Nodal


Current Balance
Baljinnyam Sereeter Ray D. Zimmerman
April 2, 2018

Matpower Technical Note 3


c 2008, 2010, 2011, 2017, 2018 Power Systems Engineering Research Center (Pserc)
All Rights Reserved
CONTENTS CONTENTS

Contents
1 Notation 3

2 Introduction 4

3 Voltages 5
3.1 Bus Voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 5

4 Bus Injections 6
4.1 Complex Current Injections . . . . . . . . . . . . . . . . . . . . . . . 6
4.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 Complex Power Injections . . . . . . . . . . . . . . . . . . . . . . . . 13

5 Branch Flows 13

6 Generalized AC OPF Costs 13

7 Lagrangian of the AC OPF 13


7.1 Nodal Current Balance . . . . . . . . . . . . . . . . . . . . . . . . . . 14
7.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 14
7.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 15
7.2 Nodal Power Balance . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

References 16

2
1 NOTATION

1 Notation
nb , ng , nl number of buses, generators, branches, respectively
|vi |, θi bus voltage magnitude and angle at bus i
vi complex bus voltage at bus i, that is |vi |ejθi
V, Θ nb × 1 vectors of bus voltage magnitudes and angles
1
V, Λ nb × 1 vector of complex bus voltages vi and their inverses vi

I bus nb × 1 vector of complex bus current injections


If , It nl × 1 vectors of complex branch current injections, from and to ends
S bus nb × 1 vector of complex bus power injections
Sf , St nl × 1 vectors of complex branch power flows, from and to ends
Sg ng × 1 vector of generator complex power injections
P, Q real and reactive power flows/injections, S = P + jQ
M, N real and imaginary parts of current flows/injections, I = M + jN
Ybus nb × nb system bus admittance matrix
Yf , Yt nl × nb system branch admittance matrices, from and to ends
Cg nb × ng generator connection matrix
(i, j)th element is 1 if generator j is located at bus i, 0 otherwise
Cf , Ct nl × nb branch connection matrices, from and to ends,
(i, j)th element is 1 if from end, or to end, respectively, of branch i is
connected to bus j, 0 otherwise
[A] diagonal matrix with vector A on the diagonal
AT (non-conjugate) transpose of matrix A
A∗ complex conjugate of A
Ab matrix exponent for matrix A, or element-wise exponent for vector A
1n , [1n ] n × 1 vector of all ones, n × n identity matrix
0 appropriately-sized vector or matrix of all zeros

3
2 INTRODUCTION

2 Introduction
This document is a supplement to Matpower Technical Note 2 “AC Power Flows,
Generalized OPF Costs and their Derivatives using Complex Matrix Notation” [1],
adding formulas for full nodal current balance, including injections from generators
and loads. Matpower Technical Note 4 [2] presents formulas for variations based
on a cartesian coordinate representation of bus voltages.
The purpose of these documents is to show how the AC power balance and flow
equations used in power flow and optimal power flow computations can be expressed
in terms of complex matrices, and how their first and second derivatives can be
computed efficiently using complex sparse matrix manipulations. The relevant code
in Matpower [3, 4] is based on the formulas found in these three notes.
We will be looking at complex functions of the real valued vector
 
Θ
 V 
X=  Pg  .
 (1)
Qg
 T
For a complex scalar function f : Rn → C of a real vector X = x1 x2 · · · xn ,
we use the following notation for the first derivatives (transpose of the gradient)
∂f h
∂f ∂f ∂f
i
fX = = ∂x1 ∂x2 · · · ∂xn . (2)
∂X
The matrix of second partial derivatives, the Hessian of f , is
 
∂2f 2f

T ∂x 2 · · · ∂x∂1 ∂x n
∂ 2f
  1
∂ ∂f  . . . 
fXX = = = .
. . . .
. . (3)
∂X 2 ∂X ∂X ∂2f ∂2f

∂xn ∂x1
··· ∂x2 n

For a complex vector function F : Rn → Cm of a vector X, where


 T
F (X) = f1 (X) f2 (X) · · · fm (X) , (4)

the first derivatives form the Jacobian matrix, where row i is the transpose of the
gradient of fi .  ∂f1 ∂f1

∂x1
· · · ∂xn
∂F
FX = =  ... .. ..  (5)

. . 
∂X ∂fm ∂fm
∂x1
· · · ∂xn

4
3 VOLTAGES

In these derivations, the full 3-dimensional set of second partial derivatives of F will
not be computed. Instead a matrix of partial derivatives will be formed by computing
the Jacobian of the vector function obtained by multiplying the transpose of the
Jacobian of F by a constant vector λ, using the following notation.
 
∂ T

FXX (α) = FX λ (6)
∂X λ=α

Just to clarify the notation, if Y and Z are subvectors of X, then


 
∂ T

FY Z (α) = FY λ . (7)
∂Z λ=α

One common operation encountered in these derivations is the element-wise mul-


tiplication of a vector A by a vector B to form a new vector C of the same dimension,
which can be expressed in either of the following forms

C = [A] B = [B] A (8)


It is useful to note that the derivative of such a vector can be calculated by the chain
rule as
∂C ∂B ∂A
CX = = [A] + [B] = [A] BX + [B] AX (9)
∂X ∂X ∂X

3 Voltages
3.1 Bus Voltages
See the corresponding section in Matpower Technical Note 2. Consider also the
vector of inverses of bus voltages v1i , denoted by Λ. Note that

1 1 |vi |e−jθi vi ∗
= = = (10)
vi |vi |ejθi |vi |2 |vi |2

Λ = V −1 = [V]−2 V ∗ (11)

3.1.1 First Derivatives

∂Λ
ΛΘ = = − [V ]−2 VΘ = −j [V ]−1 = −j [Λ] (12)
∂Θ
∂Λ
ΛV = = − [V ]−2 VV = − [V ]−1 [V]−1 = − [V]−1 [Λ] (13)
∂V
5
4 BUS INJECTIONS

4 Bus Injections
4.1 Complex Current Injections
Consider the complex current balance equation, Gc (X) = 0, where

Gc (X) = I bus + I dg (14)

and

I bus = Ybus V (15)


dg ∗ ∗
I = [Sd − Cg Sg ] Λ (16)

4.1.1 First Derivatives

bus ∂I bus  bus bus 


IX = = IΘ IV 0 0 (17)
∂X

∂I bus ∂V
IΘbus = = Ybus = jYbus [V ] (18)
∂Θ ∂Θ

∂I bus ∂V
IVbus = = Ybus = Ybus [V ] [V]−1 = Ybus [E] (19)
∂V ∂V

dg ∂I dg h dg dg dg dg i
IX = = IΘ IV IPg IQg (20)
∂X

∂I dg
IΘdg = = j[Sd − Cg Sg ]∗ [Λ∗ ] (21)
∂Θ

∂I dg
IVdg = = −[Sd − Cg Sg ]∗ [V]−1 [Λ∗ ] (22)
∂V

∂I dg
IPdgg = = − [Λ∗ ] Cg (23)
∂Pg

∂I dg
IQdgg = = j [Λ∗ ] Cg (24)
∂Qg

6
4.1 Complex Current Injections 4 BUS INJECTIONS

∂Gc  c
GcX = = GΘ GcV GcPg GcQg

(25)
∂X
∂Gc
GcΘ = = IΘbus + IΘdg = j (Ybus [V ] + [Sd − Cg Sg ]∗ [Λ∗ ]) (26)
∂Θ
∂Gc
GcV = = IVbus + IVdg = Ybus [E] − [Sd − Cg Sg ]∗ [V]−1 [Λ∗ ] (27)
∂V
∂Gc
GcPg = = IPdgg = − [Λ∗ ] Cg (28)
∂Pg

∂Gc
GcQg = = IQdgg = j [Λ∗ ] Cg (29)
∂Qg

4.1.2 Second Derivatives

bus ∂  bus T 
IXX (λ) = I λ (30)
∂X X
 bus bus

IΘΘ (λ) IΘV (λ) 0 0
bus
 IVΘ bus
(λ) IVV (λ) 0 0 
=  (31)
 0 0 0 0 
0 0 0 0
 
B C 0 0
 C 0 0 0 
=
 0
 (32)
0 0 0 
0 0 0 0

bus ∂  bus T 
IΘΘ (λ) = I λ (33)
∂Θ Θ

j [V ] Ybus T λ

= (34)
∂Θ
= j Ybus T λ VΘ
 
(35)
= − Ybus T λ [V ]
 
(36)
=B (37)

7
4.1 Complex Current Injections 4 BUS INJECTIONS

bus ∂  bus T 
IVΘ (λ) = I λ (38)
∂Θ V

[E] Ybus T λ

= (39)
∂Θ T 
= Ybus λ EΘ (40)
= j Ybus T λ [E]
 
(41)
=C (42)

bus ∂  bus T 
IΘV (λ) = I λ (43)
∂V Θ

j [V ] Ybus T λ

= (44)
∂V
= j Ybus T λ VV
 
(45)
= j Ybus T λ [E]
 
(46)
bus T
= IVΘ (λ) =C (47)

bus ∂  bus T 
IVV (λ) = I λ (48)
∂V V

[E] Ybus T λ

= (49)
∂V
= Ybus T λ EV

(50)
=0 (51)

dg ∂  dg T 
IXX (λ) = I λ (52)
∂X X
 dg dg dg dg

IΘΘ (λ) IΘV (λ) IΘP g
(λ) IΘQ g
(λ)
 I dg (λ) I dg (λ) I dg (λ) I dg (λ) 
 VΘ VV VPg VQg
=  dg (53)

 IPg Θ (λ) IPdgg V (λ) 0 0


dg dg
IQg Θ (λ) IQg V (λ) 0 0
 
−G −jH −jKT −KT
 −jH 2DH LT −jLT 
=
 −jK
 (54)
L 0 0 
−K −jL 0 0

8
4.1 Complex Current Injections 4 BUS INJECTIONS

dg ∂  dg T 
IΘΘ (λ) = I λ (55)
∂Θ Θ

= (j[Sd − Cg Sg ]∗ [Λ∗ ] λ) (56)
∂Θ
= j[Sd − Cg Sg ]∗ [λ] Λ∗Θ (57)
= −[Sd − Cg Sg ]∗ [λ] [Λ∗ ] (58)
= −G (59)

dg ∂  dg T 
IVΘ (λ) = I λ (60)
∂Θ V

−[Sd − Cg Sg ]∗ [V]−1 [Λ∗ ] λ

= (61)
∂Θ
= −[Sd − Cg Sg ]∗ [λ] [V]−1 Λ∗Θ (62)
∗ −1 ∗
= −j[Sd − Cg Sg ] [λ] [V] [Λ ] (63)
= −jH (64)

∂  dg T 
IPdgg Θ (λ) = I λ (65)
∂Θ Pg

−Cg T [Λ∗ ] λ

= (66)
∂Θ
= −Cg T [λ] Λ∗Θ (67)
T ∗
= −jCg [λ] [Λ ] (68)
= −jK (69)

∂  dg T 
IQdgg Θ (λ) = I λ (70)
∂Θ Qg

jCg T [Λ∗ ] λ

= (71)
∂Θ
= jCg T [λ] Λ∗Θ (72)
= −Cg T [λ] [Λ∗ ] (73)
= −K (74)

dg ∂  dg T 
IΘV (λ) = I λ (75)
∂V Θ

9
4.1 Complex Current Injections 4 BUS INJECTIONS


= (j[Sd − Cg Sg ]∗ [Λ∗ ] λ) (76)
∂V
= j[Sd − Cg Sg ]∗ [λ] Λ∗V (77)
∗ −1 ∗
= −j[Sd − Cg Sg ] [λ] [V] [Λ ] (78)
dg T
= IVΘ (λ) = −jH (79)

dg ∂  dg T 
IVV (λ) = I λ (80)
∂V V

−[Sd − Cg Sg ]∗ [V]−1 [Λ∗ ] λ

= (81)
∂V
∂V −1
 
∗ −1
= −[Sd − Cg Sg ] [λ] [V] Λ∗V ∗
+ [Λ ] (82)
∂V
= −[Sd − Cg Sg ]∗ [λ] [V]−1 (− [V]−1 [Λ∗ ]) − [Λ∗ ] [V]−2

(83)
= 2[Sd − Cg Sg ]∗ [λ] [V]−2 [Λ∗ ] (84)
= 2DH (85)

∂  dg T 
IPdgg V (λ) = I λ (86)
∂V Pg

−Cg T [Λ∗ ] λ

= (87)
∂V
= −Cg T [λ] Λ∗V (88)
T −1 ∗
= Cg [λ] [V] [Λ ] (89)
=L (90)

∂  dg T 
IQdgg V (λ) = I λ (91)
∂V Qg

jCg T [Λ∗ ] λ

= (92)
∂V
= jCg T [λ] Λ∗V (93)
−1
= −jCg T [λ] [V] [Λ∗ ] (94)
= −jL (95)

10
4.1 Complex Current Injections 4 BUS INJECTIONS

dg ∂  dg T 
IΘP (λ) = I λ (96)
g
∂Pg Θ

= (j[Sd − Cg Sg ]∗ [Λ∗ ] λ) (97)
∂Pg
= −j [λ] [Λ∗ ] Cg (98)
T
= IPdgg Θ (λ) = −jKT (99)

dg ∂  dg T 
IVP (λ) = I λ (100)
g
∂Pg V

−[Sd − Cg Sg ]∗ [V]−1 [Λ∗ ] λ

= (101)
∂Pg
= [λ] [V]−1 [Λ∗ ] Cg (102)
T
= IPdgg V (λ) = LT (103)

dg ∂  dg T 
IΘQ (λ) = I λ (104)
g
∂Qg Θ

= (j[Sd − Cg Sg ]∗ [Λ∗ ] λ) (105)
∂Qg
= − [λ] [Λ∗ ] Cg (106)
T
= IQdgg Θ (λ) = −KT (107)

dg ∂  dg T 
IVQ (λ) = I λ (108)
g
∂Qg V

−[Sd − Cg Sg ]∗ [V]−1 [Λ∗ ] λ

= (109)
∂Qg
= −j [λ] [V]−1 [Λ∗ ] Cg (110)
T
= IQdgg V (λ) = −jLT (111)


GcXX (λ) = GcX T λ

(112)
∂X

11
4.1 Complex Current Injections 4 BUS INJECTIONS

GcΘΘ (λ) GcΘV (λ) GcΘPg (λ) GcΘQg (λ)


 
 GcVΘ (λ) GcVV (λ) GcVP (λ) GcVQ (λ) 
=
 GcP Θ (λ) GcP V (λ)
g g  (113)
g g
0 0 
GcQg Θ (λ) GcQg V (λ) 0 0

bus dg
= IXX (λ) + IXX (λ) (114)
 
B − G C − jH −jKT −KT
 C − jH 2DH LT −jLT 
=
 −jK
 (115)
L 0 0 
−K −jL 0 0
Computational savings can be achieved by storing and reusing certain interme-
diate terms during the computation of these second derivatives, as follows:

A = Ybus T λ
 
(116)
B = −A [V ] (117)
C = jA [E] (118)
D = [V]−1 (119)
E = [λ] [Λ∗ ] (120)
F = [Sd − Cg Sg ]∗ (121)
G = EF (122)
H = DG (123)
K = Cg T E (124)
L = KD (125)
c
GΘΘ (λ) = B − G (126)
GcVΘ (λ) = C − jH (127)
GcPg Θ (λ) = −jK (128)
GcQg Θ (λ) = −K (129)
GcVV (λ) = 2DH (130)
GcPg V (λ) = L (131)
GcQg V (λ) = −jL (132)
GcΘV (λ) = GcVΘ (λ) (133)
GcΘPg (λ) = GcPg Θ T (λ) (134)

12
4.2 Complex Power Injections 7 LAGRANGIAN OF THE AC OPF

GcVPg (λ) = GcPg V T (λ) (135)


GcΘQg (λ) = GcQg Θ T (λ) (136)
T
GcVQg (λ) = GcQg V (λ) (137)

4.2 Complex Power Injections


See the corresponding section in Matpower Technical Note 2.

5 Branch Flows
See the corresponding section in Matpower Technical Note 2.

6 Generalized AC OPF Costs


Let X be defined as in Matpower Technical Note 2
 
Θ
 V 
 
 Pg 
X=  Qg

 (138)
 
 Y 
Z

where Y is the ny ×1 vector of cost variables associated with piecewise linear generator
costs and Z is an nz × 1 vector of additional linearly constrained user variables.
See the corresponding section in Matpower Technical Note 2 for additional
details.

7 Lagrangian of the AC OPF


Consider the following AC OPF problem formulation, where X is defined as in (138),
f is the generalized cost function described above, and X represents the reduced form
of X, consisting of only Θ, V, Pg and Qg , without Y and Z.

min f (X) (139)


X

13
7.1 Nodal Current Balance 7 LAGRANGIAN OF THE AC OPF

subject to
G(X) = 0 (140)
H(X) ≤ 0 (141)
where  
<{Gc (X )}
G(X) =  ={Gc (X )}  (142)
AE X − BE
and  
H f (X )
H(X) =  H t (X )  (143)
AI X − BI
Partitioning the corresponding multipliers λ and µ similarly,
   
λM µf
λ =  λN  , µ =  µt  (144)
λE µI
the Lagrangian for this problem can be written as
L(X, λ, µ) = f (X) + λT G(X) + µT H(X) (145)

7.1 Nodal Current Balance


7.1.1 First Derivatives

LX (X, λ, µ) = fX + λT GX + µT HX (146)
T
Lλ (X, λ, µ) = G (X) (147)
Lµ (X, λ, µ) = H T (X) (148)
where
<{GcΘ } <{GcV } <{GcPg } <{GcQg } 0 0
   
<{GcX } 0 0
GX =  ={GcX } 0 0  =  ={GcΘ } ={GcV } ={GcPg } ={GcQg } 0 0 
AE AE
(149)
and  f   f
HΘ HVf 0 0 0 0

HX 0 0
HX =  HXt 0 0  =  HΘt HVt 0 0 0 0  (150)
AI AI

14
7.2 Nodal Power Balance 7 LAGRANGIAN OF THE AC OPF

7.1.2 Second Derivatives


LXX (X, λ, µ) = fXX + GXX (λ) + HXX (µ) (151)
where
 
<{GcX X (λM )} + ={GcX X (λN )} 0 0
GXX (λ) =  0 0 0  (152)
0 0 0

GcΘΘ (λM ) GcΘV (λM ) GcΘPg (λM ) GcΘQg (λM )


 
 0 0 
GcVΘ (λM ) GcVV (λM ) GcVPg (λM ) GcVQg (λM )
 




 0 0 



 
GcPg Θ (λM ) GcPg V (λM ) 0 0 0 0 
 
=<  c c




 GQg Θ (λM ) GQg V (λM ) 0 0 0 0 

 



 0 0 0 0 0 0 

 
0 0 0 0 0 0
GcΘΘ (λN ) GcΘV (λN ) GcΘPg (λN ) GcΘQg (λN )
 
 0 0 
GcVΘ (λN ) GcVV (λN ) GcVPg (λN ) GcVQg (λN )
 




 0 0  


 
GcPg Θ (λN ) GcPg V (λN ) 0 0 0 0 
 
+=  c c (153)



 GQg Θ (λN ) GQg V (λN ) 0 0 0 0 

 



 0 0 0 0 0 0 

 
0 0 0 0 0 0

and

HXf X (µf ) + HXt X (µt ) 0 0


 

HXX (µ) =  0 0 0  (154)


0 0 0
 f t f t

HΘΘ (µf ) + HΘΘ (µt ) HΘV (µf ) + HΘV (µt ) 0 0 0 0
f t f t

 HVΘ (µf ) + HVΘ (µt ) HVV (µf ) + HVV (µt ) 0 0 0 0 

 0 0 0 0 0 0 
=  (155)

 0 0 0 0 0 0 

 0 0 0 0 0 0 
0 0 0 0 0 0

7.2 Nodal Power Balance


See the corresponding section in Matpower Technical Note 2.

15
REFERENCES REFERENCES

References
[1] R. D. Zimmerman, AC Power Flows, Generalized OPF Costs and their Deriva-
tives using Complex Matrix Notation, Matpower Technical Note 2, Febru-
ary 2010. [Online]. Available: http://www.pserc.cornell.edu/matpower/
TN2-OPF-Derivatives.pdf 2

[2] B. Sereeter and R. D. Zimmerman, AC Power Flows and their Derivatives us-
ing Complex Matrix Notation and Cartesian Coordinate Voltages, Matpower
Technical Note 4, April 2018. [Online]. Available: http://www.pserc.cornell.
edu/matpower/TN4-OPF-Derivatives-Cartesian.pdf 2

[3] R. D. Zimmerman, C. E. Murillo-Sánchez, and R. J. Thomas, “Matpower:


Steady-State Operations, Planning and Analysis Tools for Power Systems Re-
search and Education,” Power Systems, IEEE Transactions on, vol. 26, no. 1,
pp. 12–19, Feb. 2011. DOI: 10.1109/TPWRS.2010.2051168 2

[4] Matpower. [Online]. Available: http://www.pserc.cornell.edu/


matpower/. 2

16

You might also like