You are on page 1of 28

AC Power Flows, Generalized OPF Costs and their

Derivatives using Complex Matrix Notation


Ray D. Zimmerman
February 24, 2010∗

Matpower Technical Note 2


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


Revision 5 – April 2, 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 . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Branch Voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 7

4 Bus Injections 7
4.1 Complex Current Injections . . . . . . . . . . . . . . . . . . . . . . . 7
4.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2 Complex Power Injections . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 9

5 Branch Flows 11
5.1 Complex Currents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 12
5.2 Complex Power Flows . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 13
5.3 Squared Current Magnitudes . . . . . . . . . . . . . . . . . . . . . . . 16
5.3.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4 Squared Apparent Power Magnitudes . . . . . . . . . . . . . . . . . . 17
5.4.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 18
5.5 Squared Real Power Magnitudes . . . . . . . . . . . . . . . . . . . . . 18
5.5.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.5.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 19

2
CONTENTS CONTENTS

6 Generalized AC OPF Costs 19


6.1 Polynomial Generator Costs . . . . . . . . . . . . . . . . . . . . . . . 20
6.1.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.1.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 21
6.2 Piecewise Linear Generator Costs . . . . . . . . . . . . . . . . . . . . 21
6.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.2.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 21
6.3 General Cost Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.3.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.3.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 23
6.4 Full Cost Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.4.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.4.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 24

7 Lagrangian of the AC OPF 24


7.1 Nodal Current Balance . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.2 Nodal Power Balance . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.2.1 First Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.2.2 Second Derivatives . . . . . . . . . . . . . . . . . . . . . . . . 26

8 Revision History 27

References 28

3
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
V nb × 1 vector of complex bus voltages 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

4
2 INTRODUCTION

2 Introduction
The purpose of this document is to show how the AC power balance and flow equa-
tions 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 com-
puted efficiently using complex sparse matrix manipulations. Similarly, the deriva-
tives of the generalized AC OPF cost function used by Matpower [1, 2] and the
corresponding OPF Lagrangian function are developed. The relevant code in Mat-
power is based on the formulas found in this note, in which nodal balances are
expressed in terms of complex power and voltages are represented in polar coor-
dinates, and in the companion Matpower Technical Note 2 [3] and Matpower
Technical Note 3 [4], which present formulas for variations based on nodal current
balances and cartesian coordinate voltages, respectively.
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
2 · · · ∂x1 ∂xn
 ∂x. 1
T
∂ 2f

∂ ∂f . .. 
fXX = 2
= = .. .. . . (3)
∂X ∂X ∂X 2
∂ f 2
∂ f

∂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

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 = |vi |ejθi .
V and Θ are the vectors of bus voltage magnitudes and angles. Let

E = [V]−1 V (10)

3.1.1 First Derivatives

∂V
VΘ = = j [V ] (11)
∂Θ
∂V
VV = = [V ] [V]−1 = [E] (12)
∂V

6
3.2 Branch Voltages 4 BUS INJECTIONS

∂E
EΘ = = j [E] (13)
∂Θ
∂E
EV = =0 (14)
∂V

3.1.2 Second Derivatives


It may be useful in later derivations to note that

∂V T
 

VVV (λ) = λ = [λ] EV = 0 (15)
∂V ∂V

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 (16)
V t = Ct V (17)

3.2.1 First Derivatives

∂Vf ∂V
= Cf = jCf [V ] (18)
∂Θ ∂Θ
∂Vf ∂V
= Cf = Cf [V ] [V]−1 = Cf [E] (19)
∂V ∂V

4 Bus Injections
4.1 Complex Current Injections
I bus = Ybus V (20)

7
4.2 Complex Power Injections 4 BUS INJECTIONS

4.1.1 First Derivatives

bus ∂I bus h ∂I bus ∂I bus


i
IX = = ∂Θ ∂V
0 0 (21)
∂X

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

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

4.2 Complex Power Injections


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

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

and

S bus = [V ] I bus (25)

4.2.1 First Derivatives

∂Gs  s
GsX = = GΘ GsV GsPg GsQg

(26)
∂X

∂S bus h bus ∗ i ∂V ∂I bus
GsΘ = = I + [V ] (27)
∂Θ h i ∂Θ ∂Θ
bus ∗
= I j [V ] + [V ] (jYbus [V ])∗ (28)
h ∗
i
= j [V ] ( I bus − Ybus ∗ [V ∗ ]) (29)


∂S bus h bus ∗ i ∂V ∂I bus
GsV = = I + [V ] (30)
∂V h i ∂V ∂V
bus ∗
= I [E] + [V ] Ybus ∗ [E ∗ ] (31)
h ∗
i
= [V ] ( I bus + Ybus ∗ [V ∗ ]) [V]−1 (32)

GsPg = −Cg (33)

8
4.2 Complex Power Injections 4 BUS INJECTIONS

GsQg = −jCg (34)

4.2.2 Second Derivatives


GsXX (λ) = GsX T λ

(35)
∂X
 s 
GΘΘ (λ) GsΘV (λ) 0 0
 GsVΘ (λ) GsVV (λ) 0 0 
=  (36)
 0 0 0 0 
0 0 0 0


GsΘΘ (λ) = GsΘ T λ

(37)
∂Θ
∂  h bus ∗ i ∗ ∗T
 
= j I − [V ] Ybus [V ] λ (38)
∂Θ
∂ h bus ∗ i 
=j I [V ] λ − [V ∗ ] Ybus ∗ T [V ] λ (39)
∂Θ

h i
∗ ∗ bus ∗

=j
 [V ] [λ] (−jY bus [V ]) + I [λ] (j [V ])
| {z } | {z }
∗ ∂V
∂I bus
∂Θ ∂Θ

h i
− [V ∗ ] Ybus ∗ T [λ] (j [V ]) − Ybus ∗ T [V ] λ (−j [V ∗ ]) (40)

| {z } | {z }
∂V ∂V ∗
∂Θ ∂Θ
 h i
= [V ∗ ] Ybus ∗ T [V ] [λ] − Ybus ∗ T [V ] λ
 h ∗
i
+ [λ] [V ] Ybus ∗ [V ∗ ] − I bus (41)
=E +F (42)


GsVΘ (λ) = GsV T λ

(43)
∂Θ
∂  h bus ∗ i ∗ ∗T

= [E] I λ + [E ] Ybus [V ] λ (44)
∂Θ h i

= [E] [λ] (−jYbus ∗ [V ∗ ]) + I bus [λ] j [E]
| {z } |{z}
∗ ∂E
∂I bus
∂Θ ∂Θ

9
4.2 Complex Power Injections 4 BUS INJECTIONS

h i
+ [E ∗ ] Ybus ∗ T [λ] j [V ] + Ybus ∗ T [V ] λ (−j [E ∗ ]) (45)
|{z} | {z }
∂V ∂E ∗
∂Θ ∂Θ
  h i
= j [E ∗ ] Ybus ∗ T [V ] [λ] − Ybus ∗ T [V ] λ
 h ∗
i 
− [λ] [E] Ybus ∗ [V ∗ ] − I bus (46)
  h i
−1 ∗ ∗T ∗T
= j [V] [V ] Ybus [V ] [λ] − Ybus [V ] λ
 h ∗
i 
− [λ] [V ] Ybus ∗ [V ∗ ] − I bus (47)
= jG(E − F) (48)


GsΘV (λ) = GsΘ T λ

(49)
∂V
 h i
∗ ∗T
= j [λ] [V ] Ybus − Ybus [V ] λ [V ∗ ]
 h ∗
i 
− [V ∗ ] Ybus ∗ T − I bus [V ] [λ] [V]−1 (50)
= GsVΘ T (λ) (51)


GsVV (λ) = GsV T λ

(52)
∂V
∂  h bus ∗ i ∗ ∗T

= [E] I λ + [E ] Ybus [V ] λ (53)
∂V h i

= [E] [λ] Ybus ∗ [E ∗ ] + I bus [λ] |{z}
0
| {z }
∗ ∂E
∂I bus ∂V
∂V
h i
+ [E ∗ ] Ybus ∗ T [λ] [E] + Ybus ∗ T [V ] λ |{z}
0 (54)
|{z} ∗
∂V ∂E
∂V ∂V
 
−1
= [V] ∗ ∗ ∗
[λ] [V ] Ybus [V ] + [V ] Ybus ∗T
[V ] [λ] [V]−1 (55)
= G(C + C T )G (56)
Computational savings can be achieved by storing and reusing certain interme-
diate terms during the computation of these second derivatives, as follows:

A = [λ] [V ] (57)
B = Ybus [V ] (58)

10
5 BRANCH FLOWS

C = AB ∗ (59)
∗T
D = Ybus [V ] (60)
E = [V ∗ ] (D [λ] − [Dλ]) (61)
h i
bus ∗
F =C−A I = j [λ] GsΘ (62)
G = [V]−1 (63)
GsΘΘ (λ) = E + F (64)
GsVΘ (λ) = jG(E − F) (65)
GsΘV (λ) = GsVΘ T (λ) (66)
GsVV (λ) = G(C + C )G T
(67)

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 (68)
I t = Yt V (69)

5.1.1 First Derivatives


∂I f h i
f
IX = = IΘf IVf IPf g IQf g (70)
∂X
 
∂V
IΘf = Yf = jYf [V ] (71)
∂Θ
 
∂V
IVf = Yf = Yf [V ] [V]−1 = Yf [E] (72)
∂V
IPf g = 0 (73)
IQf g = 0 (74)

11
5.1 Complex Currents 5 BRANCH FLOWS

5.1.2 Second Derivatives

f ∂  fT 
IXX (µ) = I µ (75)
∂X X
 f f 
IΘΘ (µ) IΘV (µ) 0 0
 I f (µ) I f (µ) 0 0 
= VΘ VV  (76)
 0 0 0 0 
0 0 0 0

f ∂  fT 
IΘΘ (µ) = I µ (77)
∂Θ Θ

j [V ] Yf T µ

= (78)
∂Θ
= − Yf T µ [V ]

(79)

f ∂  fT 
IVΘ (µ) = I µ (80)
∂Θ V

[E] Yf T µ

= (81)
∂Θ
= j Yf T µ [E]
 
(82)
f
= −jIΘΘ (µ) [V]−1 (83)

f ∂  fT 
IΘV (µ) = I µ (84)
∂V Θ

j [V ] Yf T µ

= (85)
∂V
= j Yf T µ [E]
 
(86)
f
= IVΘ (µ) (87)

f ∂  fT 
IVV (µ) = I µ (88)
∂V V

[E] Yf T µ

= (89)
∂V
=0 (90)

12
5.2 Complex Power Flows 5 BRANCH FLOWS

5.2 Complex Power Flows



S f = [Vf ] I f (91)
t∗
S t = [Vt ] I (92)

5.2.1 First Derivatives

f ∂S f h
f f f f
i
SX = = SΘ SV SPg SQg (93)
∂X

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

h ∗ i ∂V
f ∂I f
SΘf = I f + [Vf ] (95)
h ∗ i ∂Θ ∂Θ
= I f
jCf [V ] + [Cf V ] (jYf [V ])∗ (96)
h ∗i
= j( I f Cf [V ] − [Cf V ] Yf ∗ [V ∗ ]) (97)


h ∗ i ∂V
f ∂I f
SVf = I f + [Vf ] (98)
h ∗ i ∂V ∂V
= I f
Cf [E] + [Cf V ] Yf ∗ [E ∗ ] (99)

SPf g = 0 (100)

SQf g = 0 (101)

5.2.2 Second Derivatives

f ∂  fT 
SXX (µ) = SX µ (102)
∂X
 f f 
SΘΘ (µ) SΘV (µ) 0 0
 S f (µ) S f (µ) 0 0 
= VΘ VV  (103)
 0 0 0 0 
0 0 0 0

13
5.2 Complex Power Flows 5 BRANCH FLOWS

f ∂  fT 
SΘΘ (µ) = S µ (104)
∂Θ Θ
∂   h ∗i  
= j [V ] Cf T I f − [V ∗ ] Yf ∗ T [Cf V ] µ (105)
∂Θ
∂  h ∗i 
=j [V ] Cf T I f µ − [V ∗ ] Yf ∗ T [Cf V ] µ (106)
∂Θ

h h ∗i i
∗ ∗
 T T
=j
 [V ] C f [µ] (−jY f [V ]) + C f I f µ j [V ]
| {z } |{z}
∗ ∂V
∂I f
∂Θ ∂Θ

h i
− [V ∗ ] Yf ∗ T [µ] Cf j [V ] − Yf ∗ T [Cf V ] µ (−j [V ∗ ]) (107)

|{z} | {z }
∂V ∂V ∗
∂Θ ∂Θ

= [V ∗ ] Yf ∗ T [µ] Cf [V ] + [V ] Cf T [µ] Yf ∗ [V ∗ ]
h i
− Yf ∗ T [µ] Cf V [V ∗ ] − Cf T [µ] Yf ∗ V ∗ [V ]
 
(108)
= Ff − Df − Ef (109)

f ∂  fT 
SVΘ (µ) = S µ (110)
∂Θ V
∂ 
T
h ∗i
f ∗ ∗T

= [E] Cf I µ + [E ] Yf [Cf V ] µ (111)
∂Θ h h ∗i i
= [E] Cf T [µ] (−jYf ∗ [V ∗ ]) + Cf T I f µ j [E]
| {z } |{z}
∗ ∂E
∂I f
∂Θ ∂Θ
h i
+ [E ∗ ] Yf ∗ T [µ] Cf j [V ] + Yf ∗ T [Cf V ] µ (−j [E ∗ ]) (112)
|{z} | {z }
∂V ∂E ∗
∂Θ ∂Θ

= j [E ∗ ] Yf ∗ T [µ] Cf [V ] − [E] Cf T [µ] Yf ∗ [V ∗ ]
h i  
− Yf ∗ T [µ] Cf V [E ∗ ] + Cf T [µ] Yf ∗ V ∗ [E]

(113)

−1
= j [V] [V ∗ ] Yf ∗ T [µ] Cf [V ] − [V ] Cf T [µ] Yf ∗ [V ∗ ]
h i  
− Yf ∗ T [µ] Cf V [V ∗ ] + Cf T [µ] Yf ∗ V ∗ [V ]

(114)
= jG(Bf − Bf T − Df + Ef ) (115)

14
5.2 Complex Power Flows 5 BRANCH FLOWS

f ∂  fT 
SΘV (µ) = SΘ µ (116)
∂V

= j [V ] Cf T [µ] Yf ∗ [V ∗ ] − [V ∗ ] Yf ∗ T [µ] Cf [V ]
h i  
− Yf ∗ T [µ] Cf V [V ∗ ] + Cf T [µ] Yf ∗ V ∗ [V ] [V]−1

(117)
f T
= SVΘ (µ) (118)

f ∂  fT 
SVV (µ) = SV µ (119)
∂V
∂  h ∗i 
= [E] Cf T I f µ + [E ∗ ] Yf ∗ T [Cf V ] µ (120)
∂V h h ∗i i
T ∗ ∗ T
= [E] Cf [µ] Yf [E ] + Cf I f µ |{z} 0
| {z } ∂E

∂I f ∂V
∂V
h i
∗ ∗T ∗T
+ [E ] Yf [µ] Cf [E] + Yf [Cf V ] µ |{z}
0 (121)
|{z} ∗
∂V ∂E
∂V ∂V
 
= [V]−1 [V ∗ ] Yf ∗ T [µ] Cf [V ] + [V ] Cf T [µ] Yf ∗ [V ∗ ] [V]−1 (122)
= GFf G (123)

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


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

Af = Yf ∗ T [µ] Cf (124)
Bf = [V ∗ ] Af [V ] (125)
Df = [Af V ] [V ∗ ] (126)
Ef = Af T V ∗ [V ]
 
(127)
Ff = Bf + Bf T (128)
G = [V]−1 (129)
f
SΘΘ (µ) = Ff − D f − E f (130)
f T
SVΘ (µ) = jG(Bf − Bf − Df + Ef ) (131)
f f T
SΘV (µ) = SVΘ (µ) (132)
f
SVV (µ) = GFf G (133)

15
5.3 Squared Current Magnitudes 5 BRANCH FLOWS

5.3 Squared Current Magnitudes


2
Let Imax denote the vector of the squares of the current magnitude limits. Then the
flow constraint function H(X) can be defined in terms of the square of the current
magnitudes as follows:
h ∗i
H f (X) = I f I f − Imax
2
(134)
 f f  f f 2
= M M + N N − Imax (135)

where I f = M f + jN f .

5.3.1 First Derivatives

f
h ∗i
f
  f∗
HX = I f IX + I f IX (136)
h ∗i h ∗ i ∗
f f
= I f IX + I f IX (137)
nh ∗ i o
f
= 2 · < I f IX (138)
= M f − jN f (MXf + jNXf ) + M f + jN f (MXf − jNXf )
   
(139)
  f  f f 
f
= 2 M MX + N NX (140)
   n o   n f o
f
= 2 < I f < IX + = I f = IX (141)

5.3.2 Second Derivatives

f ∂  fT 
HXX (µ) = HX µ (142)
∂X
 f f 
HΘΘ (µ) HΘV (µ) 0 0
 H f (µ) H f (µ) 0 0 
= VΘ VV  (143)
 0 0 0 0 
0 0 0 0

16
5.4 Squared Apparent Power Magnitudes 5 BRANCH FLOWS

f ∂ 
fT

HXX (µ) = HX µ (144)
∂X
∂  T h ∗i
f f ∗T
 f 
= IX I f µ + IX I µ (145)
∂X
f∗ f ∗ f ∗T
h ∗i
f fT f
( I f µ) + IX ( I f µ) + IX
 
= IXX [µ] IX + IXX [µ] IX (146)
f∗
n h ∗i o
f fT
= 2 · < IXX ( I f µ) + IX [µ] IX (147)

f∗
n h ∗i o
f f f fT
HΘΘ (µ) = 2 · < IΘΘ ( I µ) + IΘ [µ] IΘ (148)

n h ∗i T
o
f f
HVΘ (µ) = 2 · < IVΘ ( I f µ) + IVf [µ] IΘf (149)

n h ∗i T
o
f f
HΘV (µ) = 2 · < IΘV ( I f µ) + IΘf [µ] IVf (150)
f∗
n h ∗i o
f f f fT
HVV (µ) = 2 · < IVV ( I µ) + IV [µ] IV (151)

5.4 Squared Apparent Power Magnitudes


2
Let Smax denote the vector of the squares of the apparent power flow limits. Then the
flow constraint function H(X) can be defined in terms of the square of the apparent
power flows as follows:
h ∗i
H f (X) = S f S f − Smax 2
(152)
 f f  f f 2
= P P + Q Q − Smax (153)

where S f = P f + jQf .

5.4.1 First Derivatives

f
h ∗i
f
  f∗
HX = S f SX + S f SX (154)
h ∗i h ∗ i ∗
f f
= S f SX + S f SX (155)
nh ∗ i o
f
= 2 · < S f SX (156)
= P f − jQf (PXf + jQfX ) + P f + jQf (PXf − jQfX )
   
(157)

17
5.5 Squared Real Power Magnitudes 5 BRANCH FLOWS

 
P f PXf + Qf QfX
  
=2 (158)
   n o  f  n f o
f f
=2 < S < SX + = S = SX (159)

5.4.2 Second Derivatives

f ∂  fT 
HXX (µ) = HX µ (160)
∂X
 f f 
HΘΘ (µ) HΘV (µ) 0 0
 H f (µ) H f (µ) 0 0 
= VΘ VV  (161)
 0 0 0 0 
0 0 0 0

f ∂ 
fT

HXX (µ) = HX µ (162)
∂X
∂ 
f T
h ∗i
f ∗T
 f 
= SX S f µ + SX S µ (163)
∂X
f ∗ f ∗ f ∗T
h ∗i
f f T f
( S f µ) + SX ( S f µ) + SX
 
= SXX [µ] SX + SXX [µ] SX (164)
f ∗
n h ∗i o
f f f T
= 2 · < SXX ( S µ) + SX [µ] SX (165)


n h ∗i T
o
f f
HΘΘ (µ) = 2 · < SΘΘ ( S f µ) + SΘf [µ] SΘf (166)

n h ∗i T
o
f f
HVΘ (µ) = 2 · < SVΘ ( S f µ) + SVf [µ] SΘf (167)

n h ∗i T
o
f f
HΘV (µ) = 2 · < SΘV ( S f µ) + SΘf [µ] SVf (168)

n h ∗i T
o
f f
HVV (µ) = 2 · < SVV ( S f µ) + SVf [µ] SVf (169)

5.5 Squared Real Power Magnitudes


2
Let Pmax denote the vector of the squares of the real power flow limits. Then the flow
constraint function H(X) can be defined in terms of the square of the real power
flows as follows:

H f (X) = < S f < S f − Pmax 2


   
(170)
 f f 2
= P P − Pmax (171)

18
6 GENERALIZED AC OPF COSTS

5.5.1 First Derivatives

f
= 2 P f PXf
 
HX (172)
   n o
f
= 2 < S f < SX (173)

5.5.2 Second Derivatives

f ∂  fT 
HXX (µ) = HX µ (174)
∂X
 f f 
HΘΘ (µ) HΘV (µ) 0 0
 H f (µ) H f (µ) 0 0 
= VΘ VV  (175)
 0 0 0 0 
0 0 0 0

f ∂  fT 
HXX (µ) = HX µ (176)
∂X
∂  f T  f 
= 2PX P µ (177)
∂X
 
f fT f
 f
= 2 PXX ( P µ) + PX [µ] PX (178)
 n    o n To n o
f f f
= 2 < SXX ( < S f µ) + < SX [µ] < SX (179)

 n    o n To n o
f f
HΘΘ (µ) = 2 < SΘΘ ( < S f µ) + < SΘf [µ] < SΘf (180)
 n   f  o n To n o
f f
HVΘ (µ) = 2 < SVΘ ( < S µ) + < SV [µ] < SΘf
f
(181)
 n    o n To n o
f f
HΘV (µ) = 2 < SΘV ( < S f µ) + < SΘf [µ] < SVf (182)
 n    o n To n o
f f
HVV (µ) = 2 < SVV ( < S f µ) + < SVf [µ] < SVf (183)

6 Generalized AC OPF Costs


The generalized cost function for the AC OPF consists of three parts,

f (X) = f a (X) + f b (X) + f c (X) (184)

19
6.1 Polynomial Generator Costs 6 GENERALIZED AC OPF COSTS

expressed as functions of the full set of optimization variables.


 
Θ
 V 
 
 Pg 
X=  Qg 
 (185)
 
 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.

6.1 Polynomial Generator Costs


Let fPi (pig ) and fQi (qgi ) be polynomial cost functions for real and reactive power for
generator i and F P and F Q be the ng × 1 vectors of these costs.
 
fP1 (p1g )
F P (Pg ) = 
 .. 
(186)
. 
ng ng
fP (pg )
 1 1 
fQ (qg )
Q
F (Qg ) = 
 .. 
(187)
. 
ng ng
fQ (qg )

f a (X) = 1Tng F P (Pg ) + F Q (Qg )



(188)

6.1.1 First Derivatives


0 00
We will use F P and F P to represent the vectors of first and second derivatives of
each of these real power cost functions with respect to the corresponding generator
output. Likewise for the reactive power costs.

∂f a
fXa = (189)
∂Xa
= fΘ fVa fPag fQa g fYa fZa

(190)
h i
0 T 0 T
P
= 0 0 (F ) (F ) 0 0Q (191)

20
6.2 Piecewise Linear Generator Costs 6 GENERALIZED AC OPF COSTS

6.1.2 Second Derivatives

a ∂fXa T
fXX = (192)
∂X 
0 0 0 0 0 0
 0 0 0 0 0 0 
 0 0 fPa P
 
0 0 0 
= 0 0
g g
a
 (193)
 0 f Qg Qg 0 0 

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

where
h i
P 00
fPag Pg = F (194)
h i
00
fQa g Qg = FQ (195)

6.2 Piecewise Linear Generator Costs


f b (X) = 1Tny Y (196)

6.2.1 First Derivatives

∂f b
fXb = (197)
∂Xb
= fΘ fVb fPb g fQb g fYb fZb

(198)
= 0 0 0 0 1Tny 0
 
(199)

6.2.2 Second Derivatives


b
fXX =0 (200)

6.3 General Cost Term


Let the general cost be defined in terms of the nw × nw matrix H w and nw × 1
vector C w of coefficients and the parameters specified in the nw × nx matrix N and
the nw × 1 vectors D, R, b K, and M. The parameters N and R b provide a linear

21
6.3 General Cost Term 6 GENERALIZED AC OPF COSTS

transformation and shift to the full set of optimization variables X, resulting in a


new set of variables R.
R = NX − R b (201)
Each element of K specifies the size of a “dead zone” in which the cost is zero for
the corresponding element of R. The elements ki are used to define nw × 1 vectors
Ū , K̄ and R̄, where

0, −ki ≤ ri ≤ ki
ūi = (202)
1, otherwise

 ki , ri < −ki
k̄i = 0, −ki ≤ ri ≤ ki (203)
−ki , ri > ki

 
The “dead zone” costs are zeroed by multiplying by Ū . The remaining elements
are shifted toward zero by the size of the “dead zone” by adding K̄, before applying
a cost.
R̄ = R + K̄ (204)
Each element of D specifies whether to apply a linear or quadratic function to
the corresponding element of R̄. This can be done via two more nw × 1 vectors, DL
and DQ , defined as follows

L 1, di = 1
di = (205)
0, otherwise

Q 1, di = 2
di = (206)
0, otherwise
The result is scaled by the corresponding element of M to form a new nw × 1
vector
   L   Q   
W = [M] Ū D + D R̄ R̄ (207)
 
= DL + DQ R̄ R̄ (208)
where
DL = [M] Ū DL
  
(209)
DQ = [M] Ū DQ
  
(210)
The full general cost term is then expressed as a quadratic function of W as
follows
1
f c (X) = W T H w W + C wT W (211)
2
22
6.4 Full Cost Function 6 GENERALIZED AC OPF COSTS

6.3.1 First Derivatives


For simplicity of derivation and computation, we defined A and B as follows

∂W  
A = WR̄ = = DL + 2 DQ R̄ (212)
∂ R̄

c ∂f c
B = fW = = W T H w + C wT (213)
∂W

∂ R̄
R̄X = =N (214)
∂X
∂W
WX = = WR̄ · R̄X (215)
∂X
= AN (216)

∂f c
fXc = c
= fW · WX (217)
∂X
= BAN (218)

6.3.2 Second Derivatives


c
fXc T

fXX = (219)
∂X

N T AB T

= (220)
∂X  
T ∂ w w
 T  ∂ R̄
=N A (H W + C ) + 2 DQ B (221)
∂X ∂X
T w
 T 
= N AH WX + 2 DQ B R̄X (222)
= N T AH w A + 2 DQ B T N
 
(223)

6.4 Full Cost Function

f (X) = f a (X) + f b (X) + f c (X) (224)


1
= 1Tng F P (Pg ) + F Q (Qg ) + 1Tny Y + W T H w W + C wT W

(225)
2

23
7 LAGRANGIAN OF THE AC OPF

6.4.1 First Derivatives

∂f
fX = = f a + fXb + fXc (226)
∂X hX i
0 T 0 T
= 0 0 (F ) (F ) 1ny 0 + BAN
P Q T (227)

6.4.2 Second Derivatives

∂ 2f a b c
fXX = 2
= fXX + fXX + fXX (228)
∂X  
0 0 0 00 0
 0 0 h 0 i 00 0 
 
00
 0 0 FP 0 0 0 
 
= h i 
Q 00
 0 0 0 F 0 0 
 
 
 0 0 0 0 0 0 
00 0 0 0 0
T w
 T 
+ N AH A + 2 DQ B N (229)

7 Lagrangian of the AC OPF


Consider the following AC OPF problem formulation, where X is defined as in (185),
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) (230)


X

subject to

G(X) = 0 (231)
H(X) ≤ 0 (232)

where  
<{Gs (X )}
G(X) =  ={Gs (X )}  (233)
AE X − BE

24
7.1 Nodal Current Balance 7 LAGRANGIAN OF THE AC OPF

and  
H f (X )
H(X) =  H t (X )  (234)
AI X − BI
Partitioning the corresponding multipliers λ and µ similarly,
   
λP µf
λ =  λQ  , µ =  µt  (235)
λE µI

the Lagrangian for this problem can be written as

L(X, λ, µ) = f (X) + λT G(X) + µT H(X) (236)

7.1 Nodal Current Balance


See the corresponding section in Matpower Technical Note 3.

7.2 Nodal Power Balance


7.2.1 First Derivatives

LX (X, λ, µ) = fX + λT GX + µT HX (237)
Lλ (X, λ, µ) = GT (X) (238)
Lµ (X, λ, µ) = H T (X) (239)

where
   
<{GsX } 0 0 <{GsΘ } <{GsV } −Cg 0 0 0
GX =  ={GsX } 0 0  =  ={GsΘ } ={GsV } 0 −Cg 0 0  (240)
AE AE

and
HXf
  f
HΘ HVf 0 0 0 0
 
0 0
HX =  HXt 0 0  =  HΘt HVt 0 0 0 0  (241)
AI AI

25
7.2 Nodal Power Balance 7 LAGRANGIAN OF THE AC OPF

7.2.2 Second Derivatives


LXX (X, λ, µ) = fXX + GXX (λ) + HXX (µ) (242)
where
 
<{GsX X (λP )} + ={GsX X (λQ )} 0 0
GXX (λ) =  0 0 0  (243)
0 0 0
 s 

 GΘΘ (λP ) GsΘV (λP ) 0 0 0 0 

s
 GVΘ (λP ) GsVV (λP ) 0 0 0 0

  
 
0 0 0 0 0 0
  
=<  



 0 0 0 0 0 0 

0 0 0 0 0 0

  

 

0 0 0 0 0 0
 
 s 
G (λQ ) GsΘV (λQ ) 0 0 0 0
 ΘΘ

 

GsVΘ (λQ ) GsVV (λQ ) 0 0 0 0
 


 
 
 0 0 0 0 0 0 
+=   (244)



 0 0 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  (245)


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 
=  (246)

 0 0 0 0 0 0 

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

26
8 REVISION HISTORY

8 Revision History
• Revision 5 (April 2, 2018) – Added References section and mention of Mat-
power Technical Note 3 and Matpower Technical Note 4. Updated some
LATEX syntax for consistency across Matpower Tech Notes 2, 3, and 4. Also,
the following notation changes were made to allow U and W to be used for
cartesian coordinates in Matpower Technical Note 4: u → ū, U → Ū ,
W → W.

• Revision 4 (January 22, 2018) – Clarified second derivative notation in (6)


and (7) to make explicit that, even if input argument is a function of X, λ is a
constant in the context of the derivative. Added this revision history section.
Thanks to Baljinnyam Sereeter.
∗  ∗
• Revision 3 (September 25, 2017) – Corrected I bus to I bus in (50). Thanks
to Salman Zaferanlouei.

• Revision 2 (March 14, 2011) – Corrected dimensions (transpose mistake)


in the first derivative of the Lagrangian expression in (237). Thanks to Ali
Mehrizi-Sani.

• Revision 1 (February 24, 2010) – Swapped g and h (and G and H) in notation


to match convention used in previous publications. Published as “Matpower
Technical Note 2”.

• Initial draft (February 29, 2008)

27
REFERENCES REFERENCES

References
[1] 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

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


matpower/. 2

[3] 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

[4] 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

28

You might also like