code: def dSbus_dV(Y, V):
      
      I = Y * V
  
      diagV = spdiag(V)
      diagIbus = spdiag(I)
      diagVnorm = spdiag(div(V, abs(V))) # Element-wise division.
  
      dS_dVm = diagV * conj(Y * diagVnorm) + conj(diagIbus) * diagVnorm
      dS_dVa = 1j * diagV * conj(diagIbus - Y * diagV)
  
      return dS_dVm, dS_dVa
docs: Computes the partial derivative of power injection w.r.t. voltage.
  
          References:
              Ray Zimmerman, "dSbus_dV.m", MATPOWER, version 3.2,
              PSERC (Cornell), http://www.pserc.cornell.edu/matpower/