d2Imis_dVdSg

d2Imis_dVdSg(Cg, V, lam, vcart)

d2Imis_dVdSg() - Computes 2nd derivatives of current balance w.r.t. V and Sg.

The derivatives can be take with respect to polar or cartesian coordinates
of voltage, depending on the 4th argument.

GSV = D2IMIS_DVDSG(CG, V, LAM)
GSV = D2IMIS_DVDSG(CG, V, LAM, 0)

Returns a matrix containing the partial derivatives w.r.t. voltage angle
and magnitude of the product of a vector LAM with the 1st partial
derivatives of the real and reactive power generation.

GSV = D2IMIS_DVDSG(CG, V, LAM, 1)

Returns a matrix containing the partial derivatives w.r.t. real and
imaginary parts of voltage of the product of a vector LAM with the 1st
partial derivatives of the real and reactive power generation.

Takes the generator connection matrix, complex voltage vector V and
nb x 1 vector of multipliers LAM. Output matrices are sparse.

Examples:
    Cg = sparse(gen(:, GEN_BUS), 1:ng, -, nb, ng);
    Gsv = d2Imis_dVdSg(Cg, V, lam);

    Here the output matrix corresponds to:
        Gsv = [ Gpa Gpv;
                Gqa Gqv ];
        Gpa = d/dVa (dImis_dPg.' * lam)
        Gpv = d/dVm (dImis_dPg.' * lam)
        Gqa = d/dVa (dImis_dQg.' * lam)
        Gqv = d/dVm (dImis_dQg.' * lam)

    [Grr, Gri, Gir, Gii] = d2Imis_dVdSg(Cg, V, lam, 1);

    Here the output matrices correspond to:
        Gsv = [ Gpr Gpi;
                Gqr Gqi ];
        Gpr = d/dVr (dImis_dPg.' * lam)
        Gpi = d/dVi (dImis_dPg.' * lam)
        Gqr = d/dVr (dImis_dQg.' * lam)
        Gqi = d/dVi (dImis_dQg.' * lam)

For more details on the derivations behind the derivative code used in MATPOWER, see:

[TN2]  R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and
       their Derivatives using Complex Matrix Notation", MATPOWER
       Technical Note 2, February 2010. [Online]. Available:
       https://matpower.org/docs/TN2-OPF-Derivatives.pdf
       doi: 10.5281/zenodo.3237866
[TN3]  B. Sereeter and R. D. Zimmerman, "Addendum to AC Power Flows and
       their Derivatives using Complex Matrix Notation: Nodal Current
       Balance," MATPOWER Technical Note 3, April 2018. [Online].
       Available: https://matpower.org/docs/TN3-More-OPF-Derivatives.pdf
       doi: 10.5281/zenodo.3237900
[TN4]  B. Sereeter and R. D. Zimmerman, "AC Power Flows and their
       Derivatives using Complex Matrix Notation and Cartesian
       Coordinate Voltages," MATPOWER Technical Note 4, April 2018.
       [Online]. Available: https://matpower.org/docs/TN4-OPF-Derivatives-Cartesian.pdf
       doi: 10.5281/zenodo.3237909