S1034 of 56
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S10 · Lesson 34 · Dispatch lab

Lambda iteration with generator limits, dispatch with transmission losses and penalty factors, a congested two-bus market with its prices and congestion rent, and penalty factors from a full B matrix

Lessons 27 to 29 dispatched generators by equal incremental cost, charged remote plants for their losses, and priced electricity bus by bus. Market operators run these calculations every five minutes over thousands of units. In this lab you'll write the core of them: a lambda iteration that respects unit limits, the coordination equation with losses, a congested two-bus market, and penalty factors from a loss-coefficient matrix.

  • The curve is total generation from three units against the system's incremental cost λ, each unit running at (λ−bi)/(2ci) between its limits (lesson 27's units, with the first capped at 300 MW).
  • Where a unit hits its limit the curve's slope drops: λ rises faster for the same added load.
  • Lambda iteration searches this monotone curve for the λ that meets the demand.

Predict

Three units share 900 MW at λ = 11.35 dollars per MWh. If the first unit is limited to 300 MW instead of the 334.8 it would produce, what happens to λ?

Name it

What the lab computes

  • Lambda iteration: for a trial λ, each unit runs at Pi=(λ−bi)/(2ci) clamped to [Pmin⁡,i,Pmax⁡,i]; bisect on λ until the outputs sum to the demand.
  • Losses: with a remote unit whose losses are BP22, the coordination equation (b2+2c2P2)=λ(1−2BP2) gives P2=(λ−b2)/(2c2+2Bλ), and the balance is P1+P2=D+BP22.
  • Two-bus market: a cheap unit at A and a dear one at B serve load at B through a line of limited capacity. If the line binds, B's price is set by the dear unit, A's by the cheap one, and the congestion rent is the flow times the price difference.
  • Penalty factors from PL=PTBP: ∂PL/∂Pi=2∑jBijPj and Li=1/(1−∂PL/∂Pi).

Check

Write dispatch(units, D): units are (b, c, Pmin, Pmax) with incremental cost b + 2cP dollars per MWh; return (λ, list of outputs) meeting demand D, by bisecting λ between 0 and 1000.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write dispatch_losses(b1, c1, b2, c2, B, D): unit 1 local, unit 2 remote with losses BP22; return (λ, P1, P2, losses).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write two_bus_market(cA, cB, D, limit): a constant-cost unit at A (cA dollars per MWh) and one at B (cB > cA) serve D MW at B through a line limited to limit MW; return (flow, price at A, price at B, congestion rent per hour).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write penalty_factors(Bm, P): for a loss matrix Bm (list of lists, per MW) and outputs P, return the list of penalty factors 1/(1−2∑jBijPj).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a congested line create two different prices at its ends, and who collects the difference?