You are on page 1of 32

AC Power Flows and their Derivatives using

Complex Matrix Notation and Cartesian


Coordinate Voltages
Baljinnyam Sereeter Ray D. Zimmerman
April 2, 2018∗

Matpower Technical Note 4


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


Revision 1 – October 25, 2018. See Section 8 for revision history details.
CONTENTS CONTENTS

Contents
1 Notation 4

2 Introduction 5

3 Voltages 6
3.1 Bus Voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Branch Voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Reference Bus Voltage Angles . . . . . . . . . . . . . . . . . . . . . . 9
3.3.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 Bus Voltage Magnitude Limits . . . . . . . . . . . . . . . . . . . . . . 10
3.4.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.4.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 10
3.5 Branch Angle Difference Limits . . . . . . . . . . . . . . . . . . . . . 11
3.5.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.5.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 11

4 Bus Injections 12
4.1 Complex Current Injections . . . . . . . . . . . . . . . . . . . . . . . 12
4.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Complex Power Injections . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 18

5 Branch Flows 20
5.1 Complex Currents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2 Complex Power Flows . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 21
5.3 Squared Current Magnitudes . . . . . . . . . . . . . . . . . . . . . . . 23
5.4 Squared Apparent Power Magnitudes . . . . . . . . . . . . . . . . . . 23

2
CONTENTS CONTENTS

5.5 Squared Real Power Magnitudes . . . . . . . . . . . . . . . . . . . . . 23

6 Generalized AC OPF Costs 23

7 Lagrangian of the AC OPF 24


7.1 Nodal Current Balance . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 25
7.2 Nodal Power Balance . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.2.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 27

8 Revision History 29

Appendix A Scalar Polar Coordinate Derivatives 30


A.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
A.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

References 32

3
1 NOTATION

1 Notation
nb , ng , nl , nr number of buses, generators, branches, reference buses, respectively
ui , wi real and imaginary parts of bus voltage at bus i
|vi |, θi bus voltage magnitude and angle at bus i
vi complex bus voltage at bus i, that is |vi |ejθi or ui + jwi
U, W nb × 1 vectors of real and imaginary parts of bus voltage
V, Θ nb × 1 vectors of bus voltage magnitudes and angles
V nb × 1 vector of complex bus voltages vi , U + jW
I bus nb × 1 vector of complex bus current injections
If , It nl × 1 vectors of complex branch current injections, from and to ends
bus
S 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
Cref nr × nb reference bus indicator matrix
(i, j)th element is 1 if bus j is ith reference bus, 0 otherwise
[A] diagonal matrix with vector A on the diagonal
T
A (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

4
2 INTRODUCTION

2 Introduction
This document is a companion to Matpower Technical Note 2 [1] and Matpower
Technical Note 3 [2]. The purpose of these documents is to show how the AC power
balance and flow equations used in power flow and optimal power flow computa-
tions 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.
Matpower Technical Note 2 presents a standard formulation based on complex
power flows and nodal power balances using a polar representation of bus voltages,
Matpower Technical Note 3 adds the formulas needed for nodal current balances,
and this note presents versions of both based on a cartesian coordinate representation
of bus voltages.
We will be looking at complex functions of the real valued vector
 
U
 W 
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 = = ∂x ∂x2
· · · ∂xn . (2)
∂X 1

The matrix of second partial derivatives, the Hessian of f , is


 
∂2f ∂2f
2 · · · ∂x1 ∂xn
∂ 2f
T
 ∂x. 1
 
∂ ∂f .. .. 
fXX = = =  .
. . . . (3)
∂X 2 ∂X ∂X 
2
∂ f 2
∂ f

∂xn ∂x1
··· ∂x2
n

n m
For a complex vector function F : R → C 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

5
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
V is the nb × 1 vector of complex bus voltages. The element for bus i is vi = ui + jwi .
U and W are the vectors of real and imaginary parts of the bus voltages. Consider
also the vector of inverses of bus voltages v1i , denoted by Λ. Note that
1 1 ui − jwi vi ∗
= = 2 = (10)
vi ui + jwi ui + wi2 |vi |2

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

Θ = tan−1 [U ]−1 W

(12)

 21
V = U2 + W 2 (13)

6
3.1 Bus Voltages 3 VOLTAGES

3.1.1 First Derivatives

∂V
VU = = [1nb ] (14)
∂U
∂V
VW = = j [1nb ] (15)
∂W
∂Λ
ΛU = = − [Λ]2 (16)
∂U
∂Λ
ΛW = = −j [Λ]2 (17)
∂W
The following could also be useful for implementing certain constraints on volt-
age magnitude or angles. For the derivations, see the scalar versions found in Ap-
pendix A.

∂Θ
ΘU = = − [V]−2 [W ] (18)
∂U
∂Θ
ΘW = = [V]−2 [U ] (19)
∂W
∂V
VU = = [V]−1 [U ] (20)
∂U
∂V
VW = = [V]−1 [W ] (21)
∂W

3.1.2 Second Derivatives


For the derivations, see the scalar versions found in Appendix A.


ΘU T λ

ΘU U (λ) = (22)
∂U
= 2 [λ] [V]−4 [U ] [W ] (23)


ΘU T λ

ΘU W (λ) = (24)
∂W
7
3.2 Branch Voltages 3 VOLTAGES

= [λ] [V]−4 [W ]2 − [U ]2

(25)


ΘW T λ

ΘW U (λ) = (26)
∂U
= [λ] [V]−4 [W ]2 − [U ]2

(27)


ΘW T λ

ΘW W (λ) = (28)
∂W
= −2 [λ] [V]−4 [U ] [W ] (29)


VU T λ

VU U (λ) = (30)
∂U
= [λ] [V]−3 [W ]2 (31)


VU T λ

VU W (λ) = (32)
∂W
= − [λ] [V]−3 [U ] [W ] (33)


VW T λ

VW U (λ) = (34)
∂U
= − [λ] [V]−3 [U ] [W ] (35)


VW T λ

VW W (λ) = (36)
∂W
= [λ] [V]−3 [U ]2 (37)

3.2 Branch Voltages


The nl × 1 vectors of complex voltages at the from and to ends of all branches are,
respectively

V f = Cf V (38)
Vt = Ct V (39)

8
3.3 Reference Bus Voltage Angles 3 VOLTAGES

3.2.1 First Derivatives

∂Vf ∂V
= Cf = Cf (40)
∂U ∂U
∂Vf ∂V
= Cf = jCf (41)
∂W ∂W

3.3 Reference Bus Voltage Angles


The nr × 1 vector of complex voltages at reference buses is

Vref = Cref V (42)

The equality constraint on voltage angles at reference buses is

Gref (X) = Cref Θ − Θspecified


ref (43)

3.3.1 First Derivatives

∂Gref
Gref
U = = Cref ΘU = −Cref [V]−2 [W ] (44)
∂U

∂Gref
Gref
W = = Cref ΘW = Cref [V]−2 [U ] (45)
∂W

3.3.2 Second Derivatives

−4
Gref
U U (λ) = Cref ΘU U (λ) = 2Cref [λ] [V] [U ] [W ] (46)
−4
Gref [W ]2 − [U ]2

U W (λ) = Cref ΘU W (λ) = Cref [λ] [V] (47)
−4
Gref [W ]2 − [U ]2

W U (λ) = Cref ΘW U (λ) = Cref [λ] [V] (48)
−4
Gref
W W (λ) = Cref ΘW W (λ) = −2Cref [λ] [V] [U ] [W ] (49)

9
3.4 Bus Voltage Magnitude Limits 3 VOLTAGES

3.4 Bus Voltage Magnitude Limits


Upper and lower bounds on bus voltage magnitudes are the nb × 1 vectors
max
HV (X) = V − V max (50)
V min
H (X) = V min − V (51)

3.4.1 First Derivatives

max
HUV = VU = [V]−1 [U ] (52)
max
V
HW = VW = [V]−1 [W ] (53)
min max
HUV = −HUV (54)

V min V max
HW = −HW (55)

3.4.2 Second Derivatives

max
HUV U (λ) = VU U (λ) = [λ] [V]−3 [W ]2 (56)
max
HUV W (λ) = VU W (λ) = − [λ] [V]−3 [U ] [W ] (57)

V max −3
HW U (λ) = VW U (λ) = − [λ] [V] [U ] [W ] (58)
max −3
V
HW W (λ) = VW W (λ) = [λ] [V] [U ]2 (59)
min max
HUV U (λ) = −HUV U (λ) (60)
min max
HUV W (λ) = −HUV W (λ) (61)

V min V max
HW U (λ) = −HW U (λ) (62)

V min V max
HW W (λ) = −HW W (λ) (63)

10
3.5 Branch Angle Difference Limits 3 VOLTAGES

3.5 Branch Angle Difference Limits


Upper and lower bounds on branch voltage angle differences are the nl × 1 vectors
max
HΘ (X) = (Cf − Ct )Θ − Θmax
ft (64)
Θmin
H (X) = Θmin
f t − (Cf − Ct )Θ (65)

3.5.1 First Derivatives

max
HUΘ = (Cf − Ct )ΘU = −(Cf − Ct ) [V]−2 [W ] (66)
max
Θ
HW = ΘW = (Cf − Ct ) [V]−2 [U ] (67)
min max
HUΘ = −HUΘ (68)

Θ min Θ max
HW = −HW (69)

3.5.2 Second Derivatives

max
HUΘU (λ) = (Cf − Ct )ΘU U (λ) = 2(Cf − Ct ) [λ] [V]−4 [U ] [W ] (70)
max
HUΘW (λ) = (Cf − Ct )ΘU W (λ) = (Cf − Ct ) [λ] [V]−4 [W ]2 − [U ]2

(71)
max −4
Θ
[W ]2 − [U ]2

HW U (λ) = (Cf − Ct )ΘW U (λ) = (Cf − Ct ) [λ] [V] (72)

Θ max −4
HW W (λ) = (Cf − Ct )ΘW W (λ) = −2(Cf − Ct ) [λ] [V] [U ] [W ] (73)
min max
HUΘU (λ) = −HUΘU (λ) (74)
min max
HUΘW (λ) = −HUΘW (λ) (75)

Θ min Θ max
HW U (λ) = −HW U (λ) (76)

Θ min Θ max
HW W (λ) = −HW W (λ) (77)

11
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 (78)

and

I bus = Ybus V (79)


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

4.1.1 First Derivatives

bus ∂I bus  bus bus 


IX = = IU IW 0 0 (81)
∂X

∂I bus ∂V
IUbus = = Ybus = Ybus (82)
∂U ∂U

bus ∂I bus ∂V
IW = = Ybus = jYbus (83)
∂W ∂W

dg ∂I dg h dg dg dg dg i
IX = = IU IW IPg IQg (84)
∂X

∂I dg
IUdg = = −[Sd − Cg Sg ]∗ [Λ∗ ]2 (85)
∂U

∂I dg
dg
IW = = j[Sd − Cg Sg ]∗ [Λ∗ ]2 (86)
∂W

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

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

12
4.1 Complex Current Injections 4 BUS INJECTIONS

∂Gc  c
GcX = = GU GcW GcPg GcQg

(89)
∂X
∂Gc
GcU = = IUbus + IUdg = Ybus − [Sd − Cg Sg ]∗ [Λ∗ ]2 (90)
∂U
∂Gc
GcW = bus dg
= j Ybus + [Sd − Cg Sg ]∗ [Λ∗ ]2

= IW + IW (91)
∂W
∂Gc
GcPg = = IPdgg = − [Λ∗ ] Cg (92)
∂Pg

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

4.1.2 Second Derivatives


bus ∂  bus T 
IXX (λ) = I λ =0 (94)
∂X X

dg ∂  dg T 
IXX (λ) = I λ (95)
∂X X
 dg
IU U (λ) IUdgW (λ) IUdgPg (λ) IUdgQg (λ)

 I dg (λ) I dg (λ) I dg (λ) I dg (λ) 
= W U WW W Pg W Qg
(96)
 
 IPdgg U (λ) IPdgg W (λ) 0 0


dg dg
IQg U (λ) IQg W (λ) 0 0
 
C −jC DT −jDT
 −jC −C −jDT −DT 
=
 D −jD
 (97)
0 0 
−jD −D 0 0

∂  dg T 
IUdgU (λ) = I λ (98)
∂U U

−[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (99)
∂U

13
4.1 Complex Current Injections 4 BUS INJECTIONS

= −2[Sd − Cg Sg ]∗ [λ] [Λ∗ ] Λ∗U (100)


∗ ∗ 3
= 2[Sd − Cg Sg ] [λ] [Λ ] (101)
=C (102)

dg ∂  dg T 
IW U (λ) = I λ (103)
∂U W

j[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (104)
∂U
= 2j[Sd − Cg Sg ]∗ [λ] [Λ∗ ] Λ∗U (105)
∗ ∗ 3
= −2j[Sd − Cg Sg ] [λ] [Λ ] (106)
= −jC (107)

∂  dg T 
IPdgg U (λ) = I λ (108)
∂U Pg

−Cg T [Λ∗ ] λ

= (109)
∂U
= −Cg T [λ] Λ∗U (110)
= Cg T [λ] [Λ∗ ]2 (111)
=D (112)

∂  dg T 
IQdgg U (λ) = I λ (113)
∂U Qg

jCg T [Λ∗ ] λ

= (114)
∂U
= jCg T [λ] Λ∗U (115)
T ∗ 2
= −jCg [λ] [Λ ] (116)
= −jD (117)

∂  dg T 
IUdgW (λ) = I λ (118)
∂W U

−[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (119)
∂W
= −2[Sd − Cg Sg ]∗ [λ] [Λ∗ ] Λ∗W (120)

14
4.1 Complex Current Injections 4 BUS INJECTIONS

= −2j[Sd − Cg Sg ]∗ [λ] [Λ∗ ]3 (121)


dg T
= IW U (λ) = −jC (122)

dg ∂  dg T 
IW W (λ) = I λ (123)
∂W W

j[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (124)
∂W
= 2j[Sd − Cg Sg ]∗ [λ] [Λ∗ ] Λ∗W (125)
= −2[Sd − Cg Sg ]∗ [λ] [Λ∗ ]3 (126)
= −C (127)

∂  dg T 
IPdgg W (λ) = I λ (128)
∂W Pg

−Cg T [Λ∗ ] λ

= (129)
∂W
= −Cg T [λ] Λ∗W (130)
T ∗ 2
= −jCg [λ] [Λ ] (131)
= −jD (132)

∂  dg T 
IQdgg W (λ) = I λ (133)
∂W Qg

jCg T [Λ∗ ] λ

= (134)
∂W
= jCg T [λ] Λ∗W (135)
∗ 2
= −Cg T [λ] [Λ ] (136)
= −D (137)

∂  dg T 
IUdgPg (λ) = I λ (138)
∂Pg U

−[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (139)
∂Pg
= [Λ∗ ]2 [λ] Cg (140)

15
4.1 Complex Current Injections 4 BUS INJECTIONS

T
= IPdgg U (λ) = DT (141)

dg ∂  dg T 
IW Pg (λ) = I λ (142)
∂Pg W

j[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (143)
∂Pg
= −j [Λ∗ ]2 [λ] Cg (144)
T
= IPdgg W (λ) = −jDT (145)

∂  dg T 
IUdgQg (λ) = I λ (146)
∂Qg U

−[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (147)
∂Qg
= −j [Λ∗ ]2 [λ] Cg (148)
T
= IQdgg U (λ) = −jDT (149)

dg ∂  dg T 
IW Qg (λ) = I λ (150)
∂Qg W

j[Sd − Cg Sg ]∗ [Λ∗ ]2 λ

= (151)
∂Qg
= − [Λ∗ ]2 [λ] Cg (152)
T
= IQdgg W (λ) = −DT (153)


GcXX (λ) = GcX T λ

(154)
∂X
 c
GU U (λ) GcU W (λ) GcU Pg (λ) GcU Qg (λ)

 GcW U (λ) GcW W (λ) GcW P (λ) GcW Q (λ) 
=
 GcP U (λ) GcP W (λ)
g g  (155)
g g
0 0 
GcQg U (λ) GcQg W (λ) 0 0

dg
= IXX (λ) (156)

16
4.2 Complex Power Injections 4 BUS INJECTIONS

 
C −jC DT −jDT
 −jC −C −jDT −DT 
=
 D −jD
 (157)
0 0 
−jD −D 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 = [Λ∗ ] (158)
B = [λ] A2 (159)
C = 2[Sd − Cg Sg ]∗ AB (160)
D = Cg T B (161)
GcU U (λ) = C (162)
GcW U (λ) = −jC (163)
GcPg U (λ) = D (164)
GcQg U (λ) = −jD (165)
GcW W (λ) = −C (166)
GcPg W (λ) = −jD (167)
GcQg W (λ) = −D (168)
GcU W (λ) = GcW U (λ) (169)
GcU Pg (λ) = GcPg U T (λ) (170)
GcW Pg (λ) = GcPg W T (λ) (171)
GcU Qg (λ) = GcQg U T (λ) (172)
GcW Qg (λ) = GcQg W T (λ) (173)

4.2 Complex Power Injections


Consider the complex power balance equation, Gs (X) = 0, where

Gs (X) = S bus + Sd − Cg Sg (174)

and

S bus = [V ] I bus (175)

17
4.2 Complex Power Injections 4 BUS INJECTIONS

4.2.1 First Derivatives

∂Gs  s
GsX = = GU GsW GsPg GsQg

(176)
∂X

∂S bus h bus ∗ i ∂V ∂I bus
GsU = = I + [V ] (177)
∂U h i ∂U ∂U
bus ∗ ∗
= I + [V ] Ybus (178)


∂S bus h bus ∗ i ∂V ∂I bus
GsW = = I + [V ] (179)
∂W h ∂Wi ∂W 
bus ∗
=j I − [V ] Ybus ∗ (180)

GsPg = −Cg (181)

GsQg = −jCg (182)

4.2.2 Second Derivatives


GsXX (λ) = GsX T λ

(183)
∂X
 s 
GU U (λ) GsU W (λ) 0 0
 GsW U (λ) GsW W (λ) 0 0 
=  (184)
 0 0 0 0 
0 0 0 0


GsU U (λ) = GsU T λ

(185)
∂U
∂ h bus ∗ i  
= I + Ybus ∗ T [V ] λ (186)
∂U
∂  
= [λ] Ybus ∗ V ∗ + Ybus ∗ T [λ] V (187)
∂U
= [λ] Ybus ∗ + Ybus ∗ T [λ] (188)
=F (189)


GsW U (λ) = GsW T λ

(190)
∂U
18
4.2 Complex Power Injections 4 BUS INJECTIONS

∂  h bus ∗ i  
= j I − Ybus ∗ T [V ] λ (191)
∂U
∂   
= j [λ] Ybus ∗ V ∗ − Ybus ∗ T [λ] V (192)
∂U
 
∗ ∗T
= j [λ] Ybus − Ybus [λ] (193)
=G (194)


GsU W (λ) = GsU T λ

(195)
∂W
∂ h bus ∗ i  
= I + Ybus ∗ T [V ] λ (196)
∂W
∂  
= [λ] Ybus ∗ V ∗ + Ybus ∗ T [λ] V (197)
∂W
 
∗T ∗
= j Ybus [λ] − [λ] Ybus (198)
= GsW U T (λ) = G T (199)


GsW W (λ) = GsW T λ

(200)
∂W
∂  h bus ∗ i  
= j I − Ybus ∗ T [V ] λ (201)
∂W
∂   
= j [λ] Ybus ∗ V ∗ − Ybus ∗ T [λ] V (202)
∂W
= [λ] Ybus ∗ + Ybus ∗ T [λ] (203)
=F (204)

Computational savings can be achieved by storing and reusing certain interme-


diate terms during the computation of these second derivatives, as follows:

E = [λ] Ybus ∗ (205)


F = E + ET (206)
T

G =j E −E (207)
GsU U (λ)=F (208)
GsW U (λ) =G (209)
GsU W (λ) = GT (210)
GsW W (λ) =F (211)

19
5 BRANCH FLOWS

5 Branch Flows
Consider the line flow constraints of the form H(X) < 0. This section examines 3
variations based on the square of the magnitude of the current, apparent power and
real power, respectively. The relationships are derived first for the complex flows at
the from ends of the branches. Derivations for the to end are identical (i.e. just
replace all f sub/super-scripts with t).

5.1 Complex Currents

I f = Yf V (212)
I t = Yt V (213)

5.1.1 First Derivatives

∂I f h i
f
IX = = IUf IW
f
IPf g IQf g (214)
∂X

∂I f
IUf = = Yf (215)
∂U
f ∂I f
IW = = jYf (216)
∂W
∂I f
IPf g = =0 (217)
∂Pg
∂I f
IQf g = =0 (218)
∂Qg

5.1.2 Second Derivatives


f ∂  fT 
IXX (µ) = I µ =0 (219)
∂X X

5.2 Complex Power Flows



S f = [Vf ] I f (220)
t t∗
S = [Vt ] I (221)

20
5.2 Complex Power Flows 5 BRANCH FLOWS

5.2.1 First Derivatives

f ∂S f h
f f f f
i
SX = = SU SW SPg SQg (222)
∂X

h ∗ i ∂V
f ∂I f
= If + [Vf ] (223)
∂X ∂X

h ∗ i ∂V
f ∂I f
SUf = I f + [Vf ] (224)
h ∗ i ∂U ∂U
f ∗
= I Cf + [Vf ] Yf (225)


f
h
f∗
i ∂V ∂I f
f
SW = I + [Vf ] (226)
h ∂W i ∂W 
f∗
=j I Cf − [Vf ] Yf ∗ (227)

SPf g = 0 (228)

SQf g = 0 (229)

5.2.2 Second Derivatives

f ∂  fT 
SXX (µ) = SX µ (230)
∂X
 f
SU U (µ) SUf W (µ)

0 0
 S f (µ) S f (µ) 0 0 
= WU WW  (231)
 0 0 0 0 
0 0 0 0

∂  fT 
SUf U (µ) = SU µ (232)
∂U
∂ 
T
h ∗i
f ∗T
 
= Cf I + Yf [Vf ] µ (233)
∂U

∂I f ∂Vf
= Cf T [µ] + Yf ∗ T [µ] (234)
∂U ∂U
T ∗ ∗T
= Cf [µ] Yf + Yf [µ] Cf (235)

21
5.2 Complex Power Flows 5 BRANCH FLOWS

= Bf (236)

f ∂ 
f T

SW U (µ) = SW µ (237)
∂U
∂  
T
h ∗i
f ∗T
 
= j Cf I − Yf [Vf ] µ (238)
∂U

∂I f
 
T ∗T ∂Vf
= j Cf [µ] − Yf [µ] (239)
∂U ∂U
 
T ∗ ∗T
= j Cf [µ] Yf − Yf [µ] Cf (240)
= Df (241)

∂  fT 
SUf W (µ) = SU µ (242)
∂W
∂  T h f ∗ i  
= Cf I + Yf ∗ T [Vf ] µ (243)
∂W

∂I f ∂Vf
T
= Cf [µ] + Yf ∗ T [µ] (244)
 ∂W ∂W 
T ∗ ∗T
= −j Cf [µ] Yf − Yf [µ] Cf (245)
f T
= SW U (µ) = −Df (246)

f ∂  f T 
SW W (µ) = SW µ (247)
∂W
∂   T h f ∗i  
= j Cf I − Yf ∗ T [Vf ] µ (248)
∂W

∂I f
 
T ∗T ∂Vf
= j Cf [µ] − Yf [µ] (249)
∂W ∂W
 
= j Cf T [µ] (−j)Yf ∗ − Yf ∗ T [µ] (j)Cf (250)
= Cf T [µ] Yf ∗ + Yf ∗ T [µ] Cf (251)
= Bf (252)

Computational savings can be achieved by storing and reusing certain interme-


diate terms during the computation of these second derivatives, as follows:

Af = Cf T [µ] Yf ∗ (253)

22
5.3 Squared Current Magnitudes 6 GENERALIZED AC OPF COSTS

Bf = Af + Af T (254)
T

Df = j Af − Af (255)
SUf U (µ) = Bf (256)
f
SW U (µ) = Df (257)
T
SUf W (µ) = SW
f
U (µ) = −Df (258)
f
SW W (µ) = Bf (259)

5.3 Squared Current Magnitudes


See the corresponding section in Matpower Technical Note 2.

5.4 Squared Apparent Power Magnitudes


See the corresponding section in Matpower Technical Note 2.

5.5 Squared Real Power Magnitudes


See the corresponding section in Matpower Technical Note 2.

6 Generalized AC OPF Costs


Let X be defined as  
U

 W 

 Pg 
X=  (260)

 Qg 

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

23
7 LAGRANGIAN OF THE AC OPF

7 Lagrangian of the AC OPF


Consider the following AC OPF problem formulation, where X is defined as in (260),
f is the cost function, and X represents the reduced form of X, consisting of only
U , W , Pg and Qg , without Y and Z.

min f (X) (261)


X
subject to
G(X) = 0 (262)
H(X) ≤ 0 (263)
where  
<{Gb (X )}
 ={Gb (X )} 
G(X) = 
 Gref (X ) 
 (264)
AE X − BE
and
H f (X )
 
 H t (X ) 
max
H V (X )
 
 
 min 
H(X) =  H V (X )  (265)
max
 

 H Θ (X ) 

min
 H Θ (X ) 
AI X − BI
and Gb is the nodal balance function, equal to either Gc for current balance or to Gs
for power balance.
Partitioning the corresponding multipliers λ and µ similarly,
 
µf
   µt 
λP  
 µV max 
 λQ   
λ=  , µ =  µV min  (266)
 λref   
 µΘmax 
λE 
 µΘmin 

µI
the Lagrangian for this problem can be written as
L(X, λ, µ) = f (X) + λT G(X) + µT H(X) (267)

24
7.1 Nodal Current Balance 7 LAGRANGIAN OF THE AC OPF

7.1 Nodal Current Balance


Let the nodal balance function Gb be the nodal complex current balance Gc .

7.1.1 First Derivatives

LX (X, λ, µ) = fX + λT GX + µT HX (268)
T
Lλ (X, λ, µ) = G (X) (269)
Lµ (X, λ, µ) = H T (X) (270)

where
<{GcU } <{GcW } <{GcPg } <{GcQg } 0 0
   
<{GcX } 0 0
 ={GcX } c c c c
0 0   =  ={GU } ={GW } ={GPg } ={GQg } 0 0 
 
GX = 
 Gref ref ref
X 0 0   GU GW 0 0 0 0 
AE AE
(271)
and
HXf HUf f
   
0 0 HW 0 0 0 0
 HXt 0 0    H
 t
U HWt
0 0 0 0 
V max V max V max
 
 HX 0 0   HU HW 0 0 0 0 
min
 H V min H V min 0 0 0 0 
   
HX =  HXV 0 0  =
  U max W (272)
Θmax Θmax
 
Θ

 HX 0 0   HU
  HW 0 0 0 0 

Θmin Θmin Θmin
 HX 0 0   HU HW 0 0 0 0 
AI AI

7.1.2 Second Derivatives


LXX (X, λ, µ) = fXX + GXX (λ) + HXX (µ) (273)
where  
GX X (λ) 0 0
GXX (λ) =  0 0 0  (274)
0 0 0

25
7.1 Nodal Current Balance 7 LAGRANGIAN OF THE AC OPF

GX X (λ) = <{GcX X (λP )} + ={GcX X (λQ )} + Gref


X X (λref ) (275)
 c
GU U (λP ) GcU W (λP ) GcU Pg (λP ) GcU Qg (λP ) 


 GcW U (λP ) GcW W (λP ) GcW Pg (λP ) GcW Qg (λP ) 

 

=<   GcP U (λP ) GcP W (λP )


 g g
0 0 

GcQg U (λP ) GcQg W (λP ) 0 0
 
 c
GU U (λQ ) GcU W (λQ ) GcU Pg (λQ ) GcU Qg (λQ ) 


 Gc (λ ) Gc (λ )

GcW Pg (λQ ) GcW Qg (λQ ) 


WU Q WW Q
+=   GcP U (λQ ) GcP W (λQ )


 g g
0 0 

GcQg U (λQ ) GcQg W (λQ ) 0 0
 
 ref 
GU U (λref ) GrefU W (λref ) 0 0
 Gref
WU (λ ref ) G ref
W W (λref ) 0 0 
+  (276)
 0 0 0 0 
0 0 0 0

and  
HX X (µ) 0 0
HXX (µ) =  0 0 0  (277)
0 0 0
 
HU U (µ) HU W (µ) 0 0
 HW U (µ) HW W (µ) 0 0 
HX X (µ) =   (278)
 0 0 0 0 
0 0 0 0

HU U (µ) = HUf U (µf ) + HUt U (µt )


max min
+ HUV U (µV max ) + HUV U (µV min )
max min
+ HUΘU (µΘmax ) + HUΘU (µΘmin ) (279)

HU W (µ) = HUf W (µf ) + HUt W (µt )


max min
+ HUV W (µV max ) + HUV W (µV min )
max min
+ HUΘW (µΘmax ) + HUΘW (µΘmin ) (280)

f t
HW U (µ) = HW U (µf ) + HW U (µt )
V max V min
+ HW U (µV max ) + HW U (µV min )

26
7.2 Nodal Power Balance 7 LAGRANGIAN OF THE AC OPF

Θ max Θ min
+ HW U (µΘmax ) + HW U (µΘmin ) (281)

f t
HW W (µ) = HW W (µf ) + HW W (µt )
V max V min
+ HW W (µV max ) + HW W (µV min )
Θ max Θ min
+ HW W (µΘmax ) + HW W (µΘmin ) (282)

7.2 Nodal Power Balance


Let the nodal balance function Gb be the nodal complex power balance Gs .

7.2.1 First Derivatives

LX (X, λ, µ) = fX + λT GX + µT HX (283)
T
Lλ (X, λ, µ) = G (X) (284)
T
Lµ (X, λ, µ) = H (X) (285)

where
   
<{GsX } 0 0 <{GsU } <{GsW } −Cg 0 0 0
 ={GsX } s s
 =  ={G
0 0  U } ={GW } 0 −Cg 0 0 

GX = 
 Gref ref ref
 (286)
X 0 0   GU GW 0 0 0 0 
AE AE

and HX is the same as for nodal current balance in (272).

7.2.2 Second Derivatives


LXX (X, λ, µ) = fXX + GXX (λ) + HXX (µ) (287)
where  
GX X (λ) 0 0
GXX (λ) =  0 0 0  (288)
0 0 0

27
7.2 Nodal Power Balance 7 LAGRANGIAN OF THE AC OPF

GX X (λ) = <{GsX X (λP )} + ={GsX X (λQ )} + Gref


X X (λref ) (289)
 s 

 GU U (λP ) GsU W (λP ) 0 0  
 s s
G W U (λ P ) GW W (λ P ) 0 0 
=<  


 0 0 0 0  
0 0 0 0
 
 s s


 G U U (λ Q ) G U W (λ Q ) 0 0 

 s s
G (λ ) G (λ ) 0 0

Q Q
WU WW

+=   

 0 0 0 0  
0 0 0 0
 
 ref 
GU U (λref ) Gref U W (λref ) 0 0
 Gref ref
W U (λref ) GW W (λref ) 0 0 

+ (290)
 0 0 0 0 
0 0 0 0

and HXX (µ) is the same as for nodal current balance in (277)–(282).

28
8 REVISION HISTORY

8 Revision History
• Revision 1 (October 25, 2018)

– Added missing equality constraint for reference voltage angles. See Sec-
tions 3.3 and 7.
– Added missing inequality constraints for bus voltage magnitude limits.
See Sections 3.4 and 7.
– Added missing inequality constraints for branch voltage angle difference
limits. See Sections 3.5 and 7.

• Initial version (April 2, 2018) – Published as “Matpower Technical Note 4”.

29
A SCALAR POLAR COORDINATE DERIVATIVES

Appendix A Scalar Polar Coordinate Derivatives


When using cartesian coordinates for the voltages, the voltage magnitudes and angles
are now functions of the cartesian coordinates. Constraints on these functions require
their derivatives as well.
Consider a scalar complex voltage v that can be expressed in polar coordinates
|v| and θ or cartesian coordinates u and w as:

v = |v|ejθ (291)
= u + jw (292)

We also have
w
θ = tan−1 (293)
u
|v| = u + w2
2 2
(294)

A.1 First Derivatives


Given that
∂ tan−1 (y) 1 ∂y
= (295)
∂x 1 + y 2 ∂x
we have
∂θ 1 ∂(u−1 w) 1 w
= −2 2
= −2 2
(−u−2 w) = − 2 (296)
∂u 1+u w ∂u 1+u w |v|

∂θ 1 ∂(u−1 w) 1 −1 u
= = u = (297)
∂w 1 + u−2 w2 ∂w 1 + u−2 w2 |v|2

∂|v| ∂|v| ∂|v|2 1 1 u


= 2
= (|v|2 )− 2 (2u) = (298)
∂u ∂|v| ∂u 2 |v|

∂|v| ∂|v| ∂|v|2 1 2 − 21 w


= = (|v| ) (2w) = (299)
∂w ∂|v|2 ∂w 2 |v|

30
A.2 Second Derivatives A SCALAR POLAR COORDINATE DERIVATIVES

A.2 Second Derivatives

∂ 2θ ∂(−|v|−2 w) −3 u 2uw
= = −w(−2|v| ) = (300)
∂u2 ∂u |v| |v|4

∂ 2θ ∂(|v|−2 u) |v|2 − 2u2 w 2 − u2


 
1 −2 u
= = 2 +u = = (301)
∂w∂u ∂u |v| |v|3 |v| |v|4 |v|4

∂ 2θ ∂(−|v|−2 w) −|v|2 + 2w2


 
1 −2 w
= =− 2 −w = (302)
∂u∂w ∂w |v| |v|3 |v| |v|4
2 2 2
w −u ∂ θ
= 4
= (303)
|v| ∂w∂u

∂ 2θ ∂(|v|−2 u) −3 w 2uw ∂ 2θ
= = u(−2|v| ) = − = − (304)
∂w2 ∂w |v| |v|4 ∂u2

∂ 2 |v| ∂(|v|−1 u) −1 −2 u |v|2 − u2 w2


= = |v| + u(−|v| ) = = (305)
∂u2 ∂u |v| |v|3 |v|3

∂ 2 |v| ∂(|v|−1 w) u uw
= = w(−|v|−2 ) =− 3 (306)
∂w∂u ∂u |v| |v|

∂ 2 |v| ∂(|v|−1 u) w uw ∂ 2 |v|


= = u(−|v|−2 ) =− 3 = (307)
∂u∂w ∂w |v| |v| ∂w∂u

∂ 2 |v| ∂(|v|−1 w) −1 −2 w |v|2 − w2 u2


= = |v| + w(−|v| ) = = (308)
∂w2 ∂w |v| |v|3 |v|3

31
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, Addendum to AC Power Flows and their


Derivatives using Complex Matrix Notation: Nodal Current Balance, Mat-
power Technical Note 3, April 2018. [Online]. Available: http://www.pserc.
cornell.edu/matpower/TN3-More-OPF-Derivatives.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

32

You might also like