📄 fm_flows.m
字号:
function [Fij, Jij, Hij, Fji, Jji, Hji] = fm_flows(type, mu1, mu2)% FM_FLOWS compute current, active power and apparent power flow% in transmission lines and the associated Jacobian and% Hessian matrices%%[FIJ, JIJ, HIJ, FJI, JJI, HJI] = FM_FLOWS(TYPE,MU1,MU2)%% TYPE -> type of flows computations: (1) current flows% (2) active power flows% (3) apparent power flows%% MU1 -> column vector (Line.n,1) of Lagrangian multipliers for (i->j)% MU2 -> column vector (Line.n,1) of Lagrangian multipliers for (j->i)%% FIJ -> column vector (Line.n,1) of flows from bus "i" to bus "j"% JIJ -> Jacobian matrix (Line.n,Bus.n) from bus "i" to bus "j"% HIJ -> Hessian matrix (Bus.n,Bus.n) from bus "i" to bus "j"%% FJI -> column vector (Line.n,1) of flows from bus "j" to bus "i"% JJI -> Jacobian matrix (Line.n,Bus.n) from bus "j" to bus "i"% HJI -> Hessian matrix (Bus.n,Bus.n) from bus "j" to bus "i"%%Author: Federico Milano%Date: 11-Nov-2002%Version: 1.0.0%%E-mail: fmilano@thunderbox.uwaterloo.ca%Web-site: http://thunderbox.uwaterloo.ca/~fmilano%% Copyright (C) 2002-2006 Federico Milanoglobal Line Bus DAE jay% ==========================================================================% line flow solution% ==========================================================================tps = Line.con(:,11).*exp(jay*Line.con(:,12)*pi/180);VV = DAE.V.*exp(jay*DAE.a);r = Line.con(:,8);rx = Line.con(:,9);chrg = Line.con(:,10)/2;z = r + jay*rx;y = 1./z;g = real(y);b = imag(y);nl = [1:Line.n];switch type case 1 % ======================================================================== % AC Current Flows, Jacobian and Hessian % ======================================================================== Fij = ((VV(Line.from) - tps.*VV(Line.to)).*y + ... VV(Line.from).*(jay*chrg))./(tps.*conj(tps)); Fij = abs(Fij).^2; Fji = (VV(Line.to) - VV(Line.from)./tps).*y + VV(Line.to).*(jay*chrg); Fji = abs(Fji).^2; ati = imag(tps); atr = real(tps); cij = cos(DAE.a(Line.from)-DAE.a(Line.to)); sij = sin(DAE.a(Line.from)-DAE.a(Line.to)); g2 = g.^2; b2 = b.^2; at1 = ati.^2+atr.^2; at2 = at1.*at1; Vij = DAE.V(Line.from).*DAE.V(Line.to); Vi = DAE.V(Line.from); Vj = DAE.V(Line.to); a1 = at1.*ati.*b.*chrg; a2 = ati.*g2; a3 = at1.*atr.*g.*chrg; a4 = atr.*g2; a5 = at1.*ati.*g.*chrg; a6 = atr.*b2; a7 = at1.*atr.*b.*chrg; a8 = ati.*b2; c1 = a4+a5+a6+a7; c2 = a1+a2-a3+a8; c3 = a1+a2+a3+a8; c4 = a4-a5+a6+a7; d1 = 2*((at1.*chrg+b).^2+g2)./at2; d2 = 2*at1.*(b2+g2)./at2; d4 = 2*((at1.*chrg+b).^2+g2)./at1; d3 = 2*(g2+b2)./at1; e1 = 2*(c2.*sij+c1.*cij)./at2; e2 = 2*(c2.*cij-c1.*sij)./at2; e3 = 2*(c3.*sij+c4.*cij)./at1; e4 = 2*(c3.*cij-c4.*sij)./at1; Jij = [sparse(nl,Line.from,-Vij.*e2,Line.n,Bus.n) + ... sparse(nl,Line.to, Vij.*e2,Line.n,Bus.n), ... sparse(nl,Line.from, Vi.*d1 - Vj.*e1,Line.n,Bus.n) + ... sparse(nl,Line.to, Vj.*d2 - Vi.*e1,Line.n,Bus.n)]; Jji = [sparse(nl,Line.from,-Vij.*e4,Line.n,Bus.n) + ... sparse(nl,Line.to, Vij.*e4,Line.n,Bus.n), ... sparse(nl,Line.from, Vi.*d3 - Vj.*e3,Line.n,Bus.n) + ... sparse(nl,Line.to, Vj.*at1.*d4 - Vi.*e3,Line.n,Bus.n)]; a1 = mu1.*Vij.*e1; a2 = -mu1.*Vj.*e2; a3 = -mu1.*Vi.*e2; a4 = mu1.*d1; a5 = -mu1.*e1; a6 = mu1.*d2; Hij = [sparse(Line.from, Line.from, a1, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -a1, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-a1, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, a1, Bus.n, Bus.n), ... sparse(Line.from, Line.from, a2, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, a3, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-a2, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, -a3, Bus.n, Bus.n); ... sparse(Line.from, Line.from, a2, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -a2, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, a3, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, -a3, Bus.n, Bus.n), ... sparse(Line.from, Line.from, a4, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, a5, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, a5, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, a6, Bus.n, Bus.n)]; a1 = mu2.*Vij.*e3; a2 = -mu2.*Vj.*e4; a3 = -mu2.*Vi.*e4; a4 = mu2.*d3; a5 = -mu2.*e3; a6 = mu2.*d4.*at1; Hji = [sparse(Line.from, Line.from, a1, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -a1, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-a1, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, a1, Bus.n, Bus.n), ... sparse(Line.from, Line.from, a2, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, a3, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-a2, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, -a3, Bus.n, Bus.n); ... sparse(Line.from, Line.from, a2, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -a2, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, a3, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, -a3, Bus.n, Bus.n), ... sparse(Line.from, Line.from, a4, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, a5, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, a5, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, a6, Bus.n, Bus.n)]; case 2 % ======================================================================== % AC active power flows in each line from bus i to bus j % ======================================================================== Fij = VV(Line.from).*conj(((VV(Line.from) - tps.*VV(Line.to)).*y + ... VV(Line.from).*(jay*chrg))./(tps.*conj(tps))); Fij = real(Fij).^2; Fji = VV(Line.to).*conj((VV(Line.to) - VV(Line.from)./tps).*y ... + VV(Line.to).*(jay*chrg)); Fji = real(Fji).^2; ati = imag(tps); atr = real(tps); cji = cos(DAE.a(Line.to)-DAE.a(Line.from)); sji = sin(DAE.a(Line.to)-DAE.a(Line.from)); g2 = g.^2; b2 = b.^2; at2 = ati.^2+atr.^2; at4 = at2.^2; a1 = atr.*b.*cji; a2 = atr.*g.*sji; a3 = ati.*b.*sji; a4 = ati.*g.*cji; a5 = atr.*b.*sji; a6 = atr.*g.*cji; a7 = ati.*b.*cji; a8 = ati.*g.*sji; Vij = DAE.V(Line.from).*DAE.V(Line.to); Vi2 = DAE.V(Line.from).^2; Vj2 = DAE.V(Line.to).^2; Vi3 = DAE.V(Line.from).*Vi2; Vj3 = DAE.V(Line.to).*Vj2; v1 = Vi2.*Vj2; v2 = Vi3.*DAE.V(Line.to); v3 = Vj3.*DAE.V(Line.from); v4 = Vi2.*DAE.V(Line.to); v5 = Vj2.*DAE.V(Line.from); B1 = -a1 - a2 + a3 - a4; B2 = a5 - a6 + a7 + a8; B3 = -a5 - a6 - a7 + a8; B4 = -a1 + a2 + a3 + a4; C1 = B1.*B1; C2 = B2.*B2; C3 = B1.*B2; C4 = B3.*B3; C5 = B4.*B4; C6 = B3.*B4; C7 = B1.*g; C8 = B2.*g; C9 = B3.*g.*at2; C0 = B4.*g.*at2; Jij = [sparse(nl,Line.from, 2*(v1.*C3+v2.*C7)./at4,Line.n,Bus.n) + ... sparse(nl,Line.to, -2*(v1.*C3+v2.*C7)./at4,Line.n,Bus.n), ... sparse(nl,Line.from, 2*(3*v4.*C8+v5.*C2+2*Vi3.*g2)./at4,Line.n,Bus.n) + ... sparse(nl,Line.to, 2*(v4.*C2+Vi3.*C8)./at4,Line.n,Bus.n)]; Jji = [sparse(nl,Line.from,-2*(v1.*C6+v3.*C0)./at4,Line.n,Bus.n) + ... sparse(nl,Line.to, 2*(v1.*C6+v3.*C0)./at4,Line.n,Bus.n), ... sparse(nl,Line.from, 2*(v5.*C4+Vj3.*C9)./at4,Line.n,Bus.n) + ... sparse(nl,Line.to, 2*(3*v5.*C9+v4.*C4+2*Vj3.*g2.*at4)./at4,Line.n,Bus.n)]; k1 = 2*mu1./at4; k2 = 2*mu2./at4; D1 = (v1.*(C1-C2)-v2.*C8).*k1; E1 = (v1.*(C5-C4)-v3.*C9).*k2; D2 = (3*v4.*C7 + 2*v5.*C3).*k1; E2 = (3*v5.*C0 + 2*v4.*C6).*k2; D3 = (Vi3.*C7 + 2*v4.*C3).*k1; E3 = (Vj3.*C0 + 2*v5.*C6).*k2; D4 = (3*Vi2.*C8+2*Vij.*C2).*k1; E4 = (3*Vj2.*C9+2*Vij.*C4).*k2; D5 = (Vi2.*C2).*k1; E5 = (Vj2.*C4).*k2; D6 = (6*Vij.*C8+6*Vi2.*g2+Vj2.*C2).*k1; E6 = (6*Vij.*C9+6*Vj2.*g2.*at4+Vi2.*C4).*k2; Hij = [sparse(Line.from, Line.from, D1, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -D1, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-D1, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, D1, Bus.n, Bus.n), ... sparse(Line.from, Line.from, D2, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, D3, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-D2, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, -D3, Bus.n, Bus.n); ... sparse(Line.from, Line.from, D2, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -D2, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, D3, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, -D3, Bus.n, Bus.n), ... sparse(Line.from, Line.from, D6, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, D4, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, D4, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, D5, Bus.n, Bus.n)]; Hji = [sparse(Line.from, Line.from, E1, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -E1, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-E1, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, E1, Bus.n, Bus.n), ... sparse(Line.from, Line.from,-E3, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, -E2, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, E3, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, E2, Bus.n, Bus.n); ... sparse(Line.from, Line.from,-E3, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, E3, Bus.n, Bus.n) + ... sparse(Line.to, Line.from,-E2, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, E2, Bus.n, Bus.n), ... sparse(Line.from, Line.from, E5, Bus.n, Bus.n) + ... sparse(Line.from, Line.to, E4, Bus.n, Bus.n) + ... sparse(Line.to, Line.from, E4, Bus.n, Bus.n) + ... sparse(Line.to, Line.to, E6, Bus.n, Bus.n)]; case 3 % ======================================================================== % AC apparent power flows % ======================================================================== %Fij2 = VV(Line.from).*conj(((VV(Line.from) - tps.*VV(Line.to)).*y + ... % VV(Line.from).*(jay*chrg))./(tps.*conj(tps))); %Fij2 = abs(Fij2).^2; %Fji2 = VV(Line.to).*conj((VV(Line.to) - VV(Line.from)./tps).*y + ... % VV(Line.to).*(jay*chrg)); %Fji2 = abs(Fji2).^2; i = Line.from; j = Line.to; cij = cos(DAE.a(i)-DAE.a(j)); sij = sin(DAE.a(i)-DAE.a(j)); conjy = conj(y); conjt = conj(tps); tps2 = abs(tps).^2; ya = conjy.*conjt./tps2; yb = conjy./conjt; yj = conjy-jay*chrg; yi = yj./tps2; ga = real(ya); ba = imag(ya); gb = real(yb); bb = imag(yb);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -