Ten houses hang off one radial feeder from a substation (the slack bus, held at V₀ = 1.000 pu). Kirchhoff's Current Law fixes the power carried by each branch: the flow into branch i equals the sum of every load beyond it, since current can't accumulate at a node.
Branch flow: P_i = Σ_{j≥i} P_load,j Q_i = Σ_{j≥i} (Q_load,j − Q_cap,j)
Voltage drop: V_i = V_{i-1} − (R_i·P_i + X_i·Q_i) / V_{i-1}
Branch loss: ΔP_i = R_i · (P_i² + Q_i²) / V_{i-1}²
This is the linearized DistFlow model used for real distribution-feeder studies: real power sags voltage mostly through line resistance R, reactive power through reactance X. Every house also draws reactive power at a lagging power factor (inductive loads — motors, compressors), which is exactly what pulls the far end of the feeder below 1.0 pu as load climbs.
Each house's capacitor bank injects positive Q_cap, cancelling reactive demand locally instead of drawing it all the way from the substation. Gradient descent tunes the ten Q_cap values to minimize a cost function balancing voltage deviation against capacitor usage:
J(Q) = Σ_i (V_i − 1)² + λ Σ_i Q_cap,i²
Update: Q_cap,i ← clamp( Q_cap,i − η · ∂J/∂Q_cap,i , 0, Q_max )
The partial derivatives are estimated by finite differences each step (nudge one capacitor, re-solve the feeder, measure the change in J) — the same numerical-gradient idea behind real power-system optimal-power-flow solvers before analytic Jacobians are built. This 2D build additionally exposes the feeder's resistance R, reactance X and load power factor as live sliders, and the learning rate η that drives the descent, none of which are fixed constants here.
- Neighborhood load — scales every house's real power draw, simulating time-of-day demand.
- Capacitor bank capacity — the ceiling Q_max each house's bank can supply; raise it to see how much voltage headroom more compensation buys.
- Feeder resistance / reactance — per-branch line impedance; thinner, newer copper vs. long aging aluminum runs.
- Load power factor — how inductive the neighborhood's appliances are; lower values means more reactive demand per house.
- GD learning rate — the descent step size η; too high and the optimizer overshoots and oscillates, too low and it crawls.
- Run gradient descent — steps every capacitor toward the values that flatten the voltage profile; watch the cost J fall each iteration.
- Drag the feeder diagram to pan along the ten houses, and scroll/pinch to zoom — the voltage, capacitor and cost panels below stay linked to the same data.